Workspace/Rate Limiter
Explore

Rate limiter FOUNDATIONS

A shared decision that protects every request path.

Each mode starts with a clear purpose.
01 · START WITH THE PURPOSE

Rate limiting protects finite work.

A limiter decides whether one request may proceed now. It can protect a backend, enforce a plan, reduce abuse, or keep one caller from crowding out others.

The key defines who shares a budget: a signed-in user, API key, tenant, endpoint, or—carefully—an IP address. IPs are easy to obtain but can group many people behind one network.

Limit

How much work a key may consume.

Window or refill

How capacity becomes available over time.

Burst capacity

Extra stored tokens allowed briefly; it is separate from the sustained refill rate.

429 + Retry-After

A rejected request stops here. It is not silently queued for later.

02 · INTERVIEW CHALLENGE

Design a distributed API rate limiter.

Support per-key quotas across gateway replicas while keeping the protected API available.

45 MINUTES
PROBLEM STATEMENT

Protect a multi-tenant API at 100K requests/s. Enforce per-API-key limits across gateway replicas, permit documented bursts, return useful client headers, and define behavior when shared state is slow or unavailable.

Design the contract, algorithm, state, atomic operation, scaling, failure policy, and observability.
CLARIFY FIRST
  1. 01Identity and quota scope
  2. 02Sustained rate and burst allowance
  3. 03Accuracy and latency targets
  4. 04Multi-region requirements
  5. 05Failure and abuse policy
  6. 06Operational signals
03 · INTERACTIVE ARCHITECTURE

Follow the decision between the boxes.

Select a workflow, then move through each component to see the data, purpose, and failure risk.

Allowed pathReject or degraded path
STEP 1 / 5
04 · ALGORITHM TRADEOFFS

Choose the behavior you need.

PRIMARY MODEL

Token bucket

Tokens refill continuously at the sustained rate. Capacity permits a bounded burst. Primary model in this lab.

COMPARISON

Fixed window

A counter resets at fixed boundaries. Simple and cheap, but adjacent windows can admit a sharp double burst.

COMPARISON

Sliding window counter

Blends adjacent counters for a smoother estimate. Less memory than a log, with approximation near boundaries.

COMPARISON

Sliding window log

Stores request timestamps for an exact rolling window. Accurate, but memory and cleanup cost grow with traffic.

COMPARISON

Leaky bucket

Drains work at a steady rate and is often used to shape queued traffic. Unlike this lab’s reject-first limiter, it introduces a queue.

05 · READY TO TEST IT?

Eight deterministic scenarios turn the rules into evidence.