LESSON 07 · Operations

Explain throttling and tune the rule

A useful limiter tells clients when to retry and tells operators whom it affects.

SYSTEM VIEW

The decision path

Diagram view
Swipe or scroll to explore the full diagram
Protect capacity without blocking good usersLimiter decisions produce client signals and metrics; operators tune a rule using both rejected traffic and downstream health.Protect capacity without blocking good usersexplainrecordreviewLimiterallow or throttleClient response429 · Retry-AfterMetricsrejects · latency · errorsPolicy tuningfalse blocks + loadA falling CPU graph alone does not prove a good policy.
Limiter decisions produce client signals and metrics; operators tune a rule using both rejected traffic and downstream health.
Trace the quota decision before a request reaches the API.
THE IDEA

How it works

Return 429 for rejected synchronous requests and a Retry-After value, a wait in seconds or a date, when a meaningful wait can be computed. Quota and remaining-allowance headers can help clients pace themselves; GitHub’s API, for example, returns x-ratelimit-limit, x-ratelimit-remaining, and x-ratelimit-reset. Keep their semantics consistent with the algorithm. Clients should back off, avoid retry storms, and cache or batch work where appropriate. Queueing is suitable only when the API contract permits delayed processing.

A retry storm is easy to cause. Suppose 5,000 clients are rejected in the same second and each is told to wait 30 seconds. All 5,000 return together 30 seconds later, and most are rejected again. If clients add jitter, a random extra delay, of up to 10 seconds, the return spreads to about 500 per second.

Track allowed and rejected requests by rule, endpoint, and safe aggregate client segment; measure decision latency, counter-store errors, and downstream load. A high reject rate may mean the rule is too strict, an attack is active, or the key groups unrelated users. Review both false blocks and capacity protection. Load-test boundary bursts and concurrent requests, then tune based on the actual traffic shape. Consider rolling out a new rule in shadow mode, logging what it would have rejected without rejecting anything. That delays protection, so it does not suit a rule written during an active attack.

DECISION POINT

After a new rule ships, database load falls but checkout failures surge. Is the limiter successful?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • A 429 response should lead to predictable client behavior.
  • Monitor both the protection gained and legitimate traffic blocked.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What should a throttled synchronous client usually receive?

Choose an answer. You’ll see the explanation once you get it right.

Design rate limits and plan quotas for a public API

Apply the rate limiter chapter to two limits with different jobs: a per-second limit that protects capacity and a monthly quota that customers pay for.

The brief

A company sells a public API from three regions. Each API key has a per-second limit that protects the service and a monthly quota set by its paid plan. Design how requests are checked, how usage is counted across regions, and how customers learn where they stand. Keep the API’s own business logic, invoicing, and key issuance outside this exercise.

  • Traffic averages 1,000 requests per second across all keys, with a peak of 5 times the average. Use a 30-day month of 2,592,000 seconds and decimal units.
  • Plans: Free allows 10 requests per second and 1 million a month; Pro allows 100 per second and 50 million a month; Enterprise allows 1,000 per second and 1 billion a month. 50,000 keys are active in a month.
  • The API runs in 3 regions with traffic roughly even across them. A cross-region round trip takes 80 ms, and the limiter’s decision must add under 5 ms at p99.
  • The per-second limit protects capacity and may overshoot briefly. The monthly quota may overshoot by at most 0.1%, and usage that customers are billed for must not be lost.
  • Limiter state takes 120 bytes per key in each region. A raw usage record is 100 bytes; an hourly rollup per key and region is 50 bytes.

Reading a design isn’t the same as producing one under a clock. Try it timed: the requirement change stays hidden until partway through.

Loading your draft…

State your scope. Estimate monthly requests, peak decisions per region, limiter state, and usage storage. Work out how long a key at its full per-second limit takes to use its monthly quota, and compare the cross-region round trip with the decision budget.

0 / 4,000 characters

Name the components and what each stores. Trace one allowed request, one request rejected by the per-second limit, and one rejected by the monthly quota, including what each response tells the client.

0 / 4,000 characters

Work out the worst-case monthly overshoot for a key active in all three regions, given how often your regions sync. Then explain what happens if a regional counter store fails, and if one region is cut off from the others.

0 / 4,000 characters

Respond to the prepaid change below. Explain how a region decides it may serve a request, what happens near zero balance, and what a crashed region does to the customer’s remaining balance.

The requirement changesSales launches prepaid packs: a customer buys 10 million requests up front, and the contract forbids serving even one request beyond what was paid for. Customers can buy more at any time. How do you stop at exactly the limit without putting an 80 ms call on every request?

0 / 4,000 characters

Write an initial response in all four sections to unlock the checklist and two worked approaches.

Next chapter: URL Shortener

0 of 3 checkpoints answered correctly to complete this lesson.