MediumπŸ‘€ 3-5 yearsπŸ‘€ 8-15 years 1 min read

How would you design a distributed rate limiter?

Asked inAmazonGoogleMicrosoft
#rate limiter#token bucket#sliding window#redis#distributed
Report issue

⚑ Short Answer

Use a token-bucket or sliding-window-log/counter algorithm, keyed per client, with counters in a shared low-latency store (Redis) so the limit is enforced globally across all app instances. Update atomically (Lua/INCR+EXPIRE), and decide fail-open vs fail-closed if the store is down.

β˜•Coffee Chat Question

Concept Made Simple

β€œHow would you design a distributed rate limiter?”

🧠Mind Map Answer

Remember It Faster

Algorithm→token bucket / sliding window
State→Redis (shared, atomic)
Key→per client/API key
On store down→fail-open vs fail-closed

πŸ”₯What If?

Think Beyond the Expected

Why not just keep the counter in each app instance's memory?

Per-instance counters let a client multiply the limit by the instance count and reset on deploys/scaling β€” the global limit isn't enforced. A shared atomic store (Redis) gives one consistent count across instances; the gateway is a common enforcement point.

πŸ˜‚Real World

Distributed rate limiting lives at the gateway with Redis-backed counters and atomic Lua scripts; the design questions are algorithm choice (burst vs smoothness) and fail-open/closed behavior.

🎯Interviewer's Expectation

Keywords they're listening for:

βœ“ token bucket vs sliding windowβœ“ shared atomic store (Redis)βœ“ per-key global enforcementβœ“ atomicity (Lua/INCR)βœ“ fail-open/closed

⚠️Common Mistakes

  • βœ—Per-instance counters (limit multiplied)
  • βœ—Non-atomic read-modify-write races
  • βœ—No plan for the limiter store failing

βœ…Best Practices

  • βœ“Shared atomic counters (Redis Lua)
  • βœ“Enforce at the gateway
  • βœ“Choose algorithm for burst vs smoothness; decide fail mode

πŸ”Follow-up Questions

  • 1Token bucket vs sliding-window-log vs counter?
  • 2Fail-open or fail-closed when Redis is down?
  • 3How do you handle bursts vs sustained rate?

🧩Related Technologies

Redistoken bucketAPI gatewayLua scripts

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β€” AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Scaling (System Design)
Interview question: "How would you design a distributed rate limiter?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission β€” at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions