A new benchmark of the API gateway vs load balancer question puts numbers on what each gateway feature costs. The same small JSON API was placed behind nginx, Kong Gateway OSS and Tyk Gateway OSS. With TLS, API key checks, per-key rate limits and header rewrites all enabled at 2,000 requests per second, nginx used 117 ms of CPU per 1,000 requests and answered at a median of 0.39 ms.
The two gateways burned about four times more: 495 ms for Kong and 482 ms for Tyk. Kong was nearly out of headroom on its one core, while Tyk fell behind on its schedule, and once queueing delay is included its median latency hit 0.5 seconds.
How the test was run
The authors used a single 4 vCPU DigitalOcean droplet and gave each part its own vCPU. nginx 1.30.7 and Kong 3.9.5 (DB-less) each ran one worker. Tyk 5.16.0 was limited to one core, with its Redis store on another. Logging was disabled, and traffic used TLS 1.3 over HTTP/1.1.
They enabled the features one by one and measured each proxy’s CPU through its cgroup. A full pass takes around 90 minutes on an idle machine, with the supplementary tests needing a similar amount of time.
The cost of the hop itself
Putting any of the three proxies in front of the service added roughly 0.2 to 0.3 ms to the median response time. The bare backend replied in 0.25 ms. With a proxy in place and every feature off, replies took 0.43 to 0.56 ms at 1,000 requests per second.
For nginx, the feature costs vanished into the noise. Swings from minus 43 to plus 54 ms of CPU per 1,000 requests appeared with TLS, key validation, a per-key limit_req and three header edits, and repeated runs of one setting differed by as much as 83 ms.
Where Kong and Tyk spend CPU
Rate limiting was Kong’s biggest expense, adding between 259 ms (2,000 requests per second) and 473 ms (1,000 per second) per 1,000 requests, and pushing p99 latency from 8 ms to 47 ms. The cause is how version 3.9 handles the local policy: every request spawns its own ngx.timer.at(0, …) timer for counting. A patched build that counted inline brought the limiter’s cost down to 18 to 59 ms. That single feature explained two thirds of Kong’s overhead.
Tyk’s weak spot was key authentication, costing 88 to 129 ms per 1,000 requests, while its limiter was close to free. A single core couldn’t sustain 2,000 requests per second with keys enabled. Including queue time, the median was 7.5 ms with keys alone and 516 ms with everything on, and adding a second core cut that to 1.2 ms.
Other findings
- Configured for 10 requests per second, the proxies admitted anywhere from 1 or 2 up to 20 of 50 simultaneous requests. One admitted exactly 10.
- Memory under load: nginx held 6 MiB, Kong 170 to 176 MiB, and Tyk 74 to 114 MiB plus roughly 5 MiB for Redis.
- A keepalive trap affected nginx 1.28.3. Adding one proxy_set_header inside a location silently disabled upstream keepalive, so each request opened a new backend connection and cost 76 to 86 ms more CPU per 1,000 requests. Responses still looked correct. Since 1.29.7 keepalive is on by default, and 1.30.7 kept connections with the same config.
What a gateway really adds
The API gateway vs load balancer choice looks technical, but the data makes it a question about who uses the API.
Much of what vendors sell as gateway functionality overlaps with ordinary load balancing, such as terminating TLS, routing on host or path, retrying and editing headers, and nginx covers those. Its test configuration looked up a fixed key in a map, throttled per key with limit_req, removed the key before forwarding and changed headers on the way in and out. It passed the same functional checks as the two gateways.
The missing piece is key management for outside users: who gets keys, who rotates them and who is billed for which quota. A company whose keys rarely change and whose API is internal can stay with nginx or its current load balancer. One that issues keys to customers, cuts them off after failed payments and sells tiers with different limits would end up writing that machinery itself.
Managed gateways and what to do next
Price matters for managed services too. At 1,000 requests per second around the clock, AWS API Gateway’s request charges alone would be $6,822 a month for a REST API, which supports API keys and usage plans, or $2,363 for an HTTP API, which doesn’t. The same traffic used less than one core in this test.
The authors’ conclusion is that gateways aren’t a bad idea. The API gateway vs load balancer choice is mostly about consumers, not requests. Teams weighing Kong should test the rate limiter under their own load, and anyone running nginx should check that a proxy_set_header hasn’t quietly disabled keepalive on an older version.
Source: devops-daily.com