Kong
medium 27 minKong Gateway is an API gateway built on NGINX and Lua.
See it run
One request through the plugins, their order, which setting wins, and what a limit really counts.
Operations
One request
Router, plugins by priority, proxy. Then the same without a key.
Step 1 of 6
Match a route
The router finds the route with the highest priority that fits. It belongs to the service Orders.
Step 1: Match a route
def handle(req): route = router.match(req) # highest priority if not route: return 404 for plugin in by_priority(route): answer = plugin.access(req) if answer: return answer # 401, 403, 429 ... resp = proxy(route.service, req) return response_phases(resp) # transform, log- Work per request
- Each plugin once
- Where state lives
- Config in memory
A plugin that answers early saves all the work behind it.
In the real world
The same kong doing real jobs. Pick one and step through it.
Hybrid mode: traffic and configuration fail separately.
Step 1 of 4
Normal
The control plane reads the database and pushes configuration to the data planes.
Step 1: Normal
Common mistakes
The bugs interviewers watch for, with the fix beside each.
The Admin API on the internet
criticalWho reaches it can change every route and read every key. By default it listens on 127.0.0.1 only. Keep it so.
Wrongadmin_listen = 0.0.0.0:8001Rightadmin_listen = 127.0.0.1:8001# reach it over SSH or a private networkA way around the gateway
criticalIf services answer calls that did not pass Kong, keys and limits protect nothing.
Wrong# orders listens on a public addressRight# network rule: only Kong reaches orders# or mutual TLS between Kong and ordersReading a local limit as a total
majorWith the policy local every node counts alone. Three nodes let through up to three times the limit.
Wrongconfig: { minute: 100 } # policy: localRightconfig: minute: 100 policy: redis redis: { host: redis.internal }API keys in the address
majorkey-auth also reads the query string by default, and addresses end up in logs and histories.
WrongGET /orders?apikey=...Rightconfig: key_names: [apikey] key_in_query: false hide_credentials: truePulling :latest and expecting 3.16
minorThe open source image ends at the 3.9 line. Newer minor versions are Enterprise packages that need a licence.
Wrongimage: kong:latestRightimage: kong:3.9 # open source, patches only# or kong/kong-gateway with a licence
Interview tips
How to explain it
- A proxy with plug-in places.
- Service, route, consumer, plugin.
- The services stay simple.
Where state lives
- Config: database, file or control plane.
- Counters: node, database or Redis.
- Requests never need the database.
Reach for it when
- Partners call your APIs.
- Every API needs keys and limits.
- Several teams share one door.
Before production
- Admin API private.
- Decide open or closed on Redis loss.
- Check edition and end of support.