Gateways1 min read
Kong Gateway Integration
Enable the Aforo metering sidecar on your existing Kong cluster. Zero application code changes required.
Updated 2026-06-15Suggest edits
Docs Gateways Kong
Task Overview#
JIRA-READY TASK
Enable the Aforo Metering Sidecar on your existing Kong cluster. Verify handshake with SRE team before promoting to production.
Estimated time: 15 minutes. Target: Platform Engineer + SRE Verification.
Prerequisites#
REQUIRED
Kong Gateway
OSS 3.x+ or Enterprise 3.x+
REQUIRED
Admin API access
HTTP access to Kong Admin API (default: localhost:8001)
REQUIRED
Aforo API Key
sk_live_* key from Admin Panel → Settings → API Keys
OPTIONAL
Redis (optional)
For local edge cache. Falls back to in-memory LRU if unavailable.
Step 1: Download the Plugin#
Clone the Aforo Kong metering plugin into your Kong plugins directory:
Step 2: Configure#
Add the plugin to your kong.yml declarative config or apply via Admin API:
Option A: Declarative (kong.yml) — Production Ready
PRO TIP
The core configuration is 5 lines. Everything below is production hardening.
discovery_enabled: true activates automated catalog indexing — Aforo discovers and versions your APIs without manual entry.Option B: Admin API
INFO
The Admin API method applies the plugin globally (all routes). To scope to a specific service or route, add
service.id or route.id to the request.Step 3: Deploy#
After configuration, reload Kong to activate the plugin:
Performance: Zero Latency Impact#
The Aforo Kong plugin is designed for zero impact on your API response times:
<5ms
Entitlement Check
Local Redis lookup. No cross-network call.
0ms added
Usage Metering
Fires in Lua log_by phase — after response is sent.
Every 5s
Batch Flush
100 events per batch. lz4 compressed. Async HTTP.
30s TTL
Cache Refresh
Background sync. Stale cache serves until refresh.
<5ms
Kong Edge Decision
Local Redis lookup in access phase. Zero cross-network call.
MARGIN GUARD/ Kong
The plugin operates in Kong's
log phase for metering and access phase for entitlement + margin checks. L1-L3 enforcement runs before the request reaches your upstream — unprofitable traffic is blocked at the gateway.Fallback Behavior#
If the Aforo ingestion endpoint is temporarily unreachable, the plugin guarantees zero data loss:
RESILIENCE CHAIN
1. Normal → Events batched and flushed every 5s to ingest.aforo.ai
2. Ingest unreachable → Events buffered in local memory (up to
buffer_max_size: 10000)3. Retry → 3 retries with exponential backoff (1s, 2s, 4s)
4. Buffer full → Events spill to disk (
/tmp/aforo-buffer/) — survives Kong restarts5. Ingest recovered → Disk buffer drained first (FIFO), then memory buffer resumes
INFO
The
fallback_on_error: "allow" setting controls what happens to API requests when entitlement checks fail. "allow" means your API continues serving traffic (fail-open). "block" means requests are rejected if Aforo can't verify entitlements (fail-closed). Most production deployments use "allow" to prioritize availability.Verification#
Verify the handshake by checking Kong logs for a successful connection:
PaperPlaneTilt a Test Event
PRO TIP
If events are not appearing, check the Kong error log for
[aforo-metering] ERROR entries. Common issues: invalid API key (401), network timeout to ingest.aforo.ai, or missing X-Tenant-Id header on the request.