Design a distributed rate limiter for a public API gateway with 20 nodes.
Short answer
Use a token bucket per API key stored in Redis with an atomic Lua script so all gateway nodes share counts, add a local in-memory pre-limit for abuse, return 429 with Retry-After, choose fail-open with conservative local limits if Redis is unavailable, and expose rate-limit headers to clients.
Detailed answer
See the Lua implementation in Rate Limiting. Key decisions: algorithm (token bucket for bursts), key (API key + route), storage (Redis Cluster sharded by key), atomicity (Lua), latency (one round trip, pipelining), failure mode (fail-open with local limits), observability (rejections by key), and tiers (per plan).
What the interviewer expects
Atomicity across nodes, algorithm choice, failure handling.
Common mistakes to avoid
Per-node local counters only (limits multiply by node count); read-then-write without atomicity.