Quick revision
The short answer
Spring Cloud Gateway runs every route on the same few Netty event loops, so one filter that makes a synchronous introspection call blocks loops that carry every team's traffic, and latency rises across the whole gateway, not only for that team's routes. We fix the filter by validating JWTs locally where possible, or by calling introspection through a non-blocking client such as WebClient with a cache, and we prevent the whole class of problem by running BlockHound in gateway CI, reviewing gateway filters as shared infrastructure, load testing them before release and monitoring event-loop latency.
What to remember
In this answer, we saw that a gateway built on WebFlux shares a few event loops across all routes, so one synchronous introspection call in a filter blocks loops carrying every team's traffic, and at 50,000 requests per second a 20 ms blocking call leaves the loops busy most of the time. We fixed the filter with local JWT validation or a cached, non-blocking introspection call, and prevented the class of problem with BlockHound in gateway CI, a review process for filters on shared infrastructure, load tests with slow dependencies, and monitoring of event-loop latency with a canary route.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Spring Cloud Gateway runs every route on the same few Netty event loops, so one filter that makes a synchronous introspection call blocks loops that carry every team's traffic, and latency rises across the whole gateway, not only for that team's routes. We fix the filter by validating JWTs locally where possible, or by calling introspection through a non-blocking client such as WebClient with a cache, and we prevent the whole class of problem by running BlockHound in gateway CI, reviewing gateway filters as shared infrastructure, load testing them before release and monitoring event-loop latency.
Why this question is asked
An API gateway is a single point that every request passes through. That makes it efficient, and it also means that a mistake in one small piece of code affects every service behind it. Interviewers ask this scenario because it combines a technical root cause, blocking on an event loop, with a fleet-level question: how do we stop any team from making that mistake on shared infrastructure? In this answer, we will recap how the gateway handles requests, calculate what one blocking call does at 50,000 requests per second, fix the filter, and then design the guardrails: automated detection, review, load testing and monitoring.
1A Quick Recap of How the Gateway Handles Requests
Spring Cloud Gateway is built on Spring WebFlux and Reactor Netty. Each request is matched to a route and passed through a chain of filters, global filters that apply to all routes and gateway filters attached to specific routes, before being proxied to the backend with Netty's non-blocking HTTP client. All of that runs on a small group of event-loop threads, typically one per CPU core, shared by every route and every team.
Token introspection is how a gateway checks an opaque OAuth 2.0 access token: it calls the authorization server's introspection endpoint, which says whether the token is active and what it allows. If the filter makes that call with a blocking client, such as RestTemplate, the event-loop thread waits for the reply.
2What One Blocking Call Does at 50,000 Requests per Second
Let us put numbers on it. Suppose the gateway runs on 10 instances with 8 cores each, so 80 event loops in total, and 50,000 requests per second means about 625 requests per second per loop. A non-blocking loop handles that easily, because each request costs it well under a millisecond of CPU.
Now one team's filter makes a synchronous introspection call that takes 20 ms. A loop that blocks for 20 ms per request can complete at most 50 such requests per second. If that team's routes carry 5 percent of the traffic, each loop sees about 31 of those requests per second, which is 620 ms of blocking every second. The loop is now blocked most of the time, and every other route's requests on that loop wait behind it. When the introspection endpoint slows to 100 ms, the loops cannot keep up at all, queues grow, and latency and timeouts spread to every team's traffic.
7 messages in order. Play them, or step through them one at a time.
Shared event loops turn one team's latency into everyone's latency.
3Fixing the Filter
The best fix avoids the network call altogether. If the authorization server issues JWTs, signed tokens that carry their own claims, the gateway can validate them locally by checking the signature against the server's public keys and the expiry and audience claims. Spring Security's reactive resource server does this with a ReactiveJwtDecoder that fetches and caches the key set, so validating a token costs microseconds of CPU and no I/O per request.
If tokens must be opaque, the introspection call must be non-blocking and cached. Spring Security's reactive opaque-token support calls the endpoint with WebClient, and we wrap it with a short-lived cache keyed by the token, bounded by both a TTL such as 30 to 60 seconds and the token's own expiry, so a busy client's token is introspected once a minute rather than on every request.
Notice that the fixed version is not just faster. It also removes a runtime dependency: if the authorization server has a brief outage, local validation keeps working with cached keys, while per-request introspection would fail every request.
4Preventing This Class of Problem
A fix for one filter does not stop the next team from writing another blocking call. The gateway is shared infrastructure, so it needs guardrails like any other platform component. The first is automated detection: BlockHound installed in the gateway's integration tests, so any blocking call on an event loop throws an error and fails the build. Every filter, including those contributed by other teams, must run in that test suite.
The second is a review process. Gateway filters are owned by the platform team, and changes from other teams go through a review that asks specific questions: does the filter do any I/O, is it non-blocking, what happens when its dependency is slow, is there a timeout and a cache, and does it need to be in the gateway at all or could it live in the backend service? Many filters belong in the service that owns the route.
- Team proposes a filterwith its route scope and dependencies
- Does it do I/O per request?YesMust be non-blocking, cached, with timeoutNoCPU-only, review cost
- BlockHound integration tests in CIfails on any blocking call
- Load test at 1.5x peak with slow dependencycompare gateway p99 with baseline
- Gateway latency unchanged?YesRelease behind a flag, watch metricsNoBack to the team
5 steps in order. Play them, or step through them one at a time.
5Load Testing and Monitoring the Event Loops
Before release, each filter change is load tested against a production-like profile, say 1.5 times peak, both with its dependency healthy and with the dependency slowed to ten times its normal latency, because a slow dependency is what turns a small blocking call into an outage. The pass criterion is that the gateway's own added latency, measured per route, does not change for routes the filter does not touch.
In production we monitor the event loops directly: Reactor Netty can publish metrics through Micrometer, such as pending tasks per event loop, and we track gateway-added latency per route and per filter. A simple synthetic probe, a cheap route that returns immediately, is a sensitive canary: if its latency rises, some loop is being blocked. Alerts on those signals catch a blocking filter within minutes of a release, and a feature flag on new filters lets us switch it off without a deployment.
6Follow-up questions
Couldn't the filter just use subscribeOn(boundedElastic) for the blocking call?
That moves the wait off the event loop and would stop the fleet-wide damage, but at 50,000 requests per second it needs hundreds of blocked threads and adds latency per request. It is acceptable as an emergency patch; local JWT validation or a cached non-blocking introspection call is the proper design for a gateway.
How long should introspection results be cached?
Long enough to remove most calls, short enough that revocation still takes effect reasonably fast, for example 30 to 60 seconds, and never beyond the token's own expiry. The security team should agree the TTL, because it is the maximum time a revoked token may still be accepted.
Why not let each team run its own gateway?
Separate gateways isolate failures but multiply operational cost, duplicate security logic and complicate routing. A middle path is one shared gateway with strong guardrails, plus separate gateway instances or route groups for teams with very different risk or traffic profiles.
7Conclusion
In this answer, we saw that a gateway built on WebFlux shares a few event loops across all routes, so one synchronous introspection call in a filter blocks loops carrying every team's traffic, and at 50,000 requests per second a 20 ms blocking call leaves the loops busy most of the time. We fixed the filter with local JWT validation or a cached, non-blocking introspection call, and prevented the class of problem with BlockHound in gateway CI, a review process for filters on shared infrastructure, load tests with slow dependencies, and monitoring of event-loop latency with a canary route.
Open with
The fleet-level risk is that the gateway's event loops are shared by every route. Spring Cloud Gateway runs on WebFlux and Reactor Netty, so all filters for all teams run on roughly one loop per core.
Then, if they want more
A synchronous introspection call blocks a loop, and every other request on that loop waits, so latency rises for every team's traffic, not just the team that wrote the filter. Putting numbers on it: with 80 loops across the fleet, each handles about 625 requests per second.
If 5 percent of traffic hits that filter and introspection takes 20 milliseconds, each loop is blocked over 600 milliseconds every second, and if the introspection endpoint slows down, the gateway collapses.
For the filter itself, I'd prefer local JWT validation with Spring Security's ReactiveJwtDecoder, which caches the signing keys, so there's no I/O per request and no runtime dependency on the auth server.
If tokens must be opaque, introspection goes through WebClient, non-blocking, with a short cache keyed by token, bounded by a TTL agreed with security and by the token's expiry.
To prevent the whole class of problem, I'd treat the gateway as shared infrastructure: BlockHound in the gateway's integration tests so any blocking call fails CI, a review process for filters owned by the platform team that asks about I/O, timeouts, caching and whether the logic belongs in the backend instead, load tests at 1.5 times peak with the dependency slowed down, and production monitoring of event-loop pending tasks and per-route gateway latency, with a cheap canary route and feature flags so a bad filter can be switched off fast.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring WebFlux, Project Reactor reference guide
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A gateway built on Spring Cloud Gateway (WebFlux) handles 50,000 requests per second. A...": https://scrivio-interview-library.netlify.app/spring-boot/webflux/7074ea9018/