How to design a distributed rate limiter for a shared API gateway
Rate limiter design is a frequent system design interview question, typically framed as one limiter shared across many API gateway instances. The example uses per-key, per-endpoint limits of 100 requests per minute on a free plan and 5,000 on paid plans, with 50 gateways handling roughly 500,000 requests per second. The limiter is best placed as middleware inside each gateway, using locally cached rules refreshed periodically and one atomic Redis operation per rule. Algorithm choices are compared, with token bucket recommended as a common default for APIs and sliding log rejected for its memory cost at this scale. Race conditions across gateways are addressed by performing check-and-update atomically with a Redis Lua script, and the article advises deciding in advance whether to fail open or fail closed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in