Lesson 12 of 15
32. Design a Rate Limiter as a Service

Score yourself

3 min read+10 XP

Score yourself

Give yourself 0, 1 or 2 points per row.

Area0 points1 point2 points
RequirementsStarted drawingListed featuresFeatures, latency budget, fail-open/closed and multi-region agreed and written down
EstimatesNoneNumbers, not used laterNumbers that drove decisions (ops/s → shards, memory is small, latency budget)
API and dataSkippedCheck API or rule model, not bothBoth, with remaining/retry-after and Redis key design
High-level designMissing piecesBoxes, no walkthroughCheck path and rule-change path walked, failure handling included
Deep diveHand-wavedOne algorithm describedAlgorithm per rule, atomic script, multi-rule race or regions handled
Trade-offsNone namedNamed when askedRaised unprompted (library vs sidecar, exact vs fast, open vs closed)
CommunicationLong silencesMostly clearThought out loud, checked in, managed time

12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.

The bar: fresher vs SDE-2

FresherSDE-2
AlgorithmExplains token bucket or fixed window clearlyPicks per rule, knows boundary bursts, costs and retry-after
Shared statePuts a counter in RedisOne atomic script, TTLs, sharding, hash tags, Redis clock
ConcurrencyKnows INCR is atomicHandles multi-rule checks without leaking tokens
Failure"Redis has replicas"Timeouts, breaker, fail-open vs closed per rule, local backstop
RegionsNot mentionedLocal enforcement with rebalanced shares; home region for tight limits

Common mistakes

  • A network hop to a separate limiter service on every request without discussing latency.
  • GET, check, SET instead of one atomic step.
  • No plan for the limiter being down, so a Redis blip becomes a site-wide outage.
  • One global counter across regions on the hot path.
  • Checking several rules one by one and silently spending tokens on denied requests.
  • No safeguards on rule changes: one typo throttles every customer.

Quick check

Five questions on this chapter. Pick an answer, then check it.

quiz