The 30 second answer
The gateway, for example Spring Cloud Gateway or AWS API Gateway, validates the token, routes by path or host, and rate-limits per client or tenant. For tenant isolation I put the tenant ID in the token and give each tenant its own limit, so one noisy tenant can't starve others. Each service still checks tenant access itself, because the gateway should not be the only defense.
The gateway (Spring Cloud Gateway or AWS API Gateway) validates the token, routes by path or host, and applies rate limits per client or tenant. AWS API Gateway supports throttling and per-client usage plans with API keys. Tenant isolation: put the tenant ID in the token, rate-limit per tenant so one noisy tenant can't starve others, and still check tenant access in each service, because the gateway is not the only line of defense. Follow-up: Where do fine-grained permissions belong? (In the services; the gateway does coarse checks.) Editor's note: "check again in each service" is a defense-in-depth opinion.
Alternate interview scenarios
"Design a distributed rate limiter that works consistently across many application instances."
In-memory limiters count requests on each instance separately. With N instances the real limit becomes N times the configured value, and it changes during autoscaling. For a shared limit I keep the counter in Redis and update it atomically. That can be a fixed or sliding window with INCR and an expiry, or a token bucket run as a single Lua script so check-and-decrement cannot race. Spring Cloud Gateway's Redis rate limiter implements a token bucket this way. The tradeoffs are one Redis round trip per request, and deciding what happens when Redis is down, either fail open or fail closed. For extremely hot paths I combine a coarse local limiter with periodic global sync, accepting approximate limits.
Sources (4)
- Spring Cloud Gateway referencedocs.spring.io
- AWS API Gateway: Throttle requestsdocs.aws.amazon.com
- Redis INCR: rate limiter patternredis.io
- Spring Cloud Gateway: RequestRateLimiter (Redis token bucket)docs.spring.io