In this lesson · topic 1 of 7
Topic 1
Why callers need a limit
4 min read
A shared service has a fixed size
A service can answer only so many requests a second. Every caller shares that. Most callers behave. Then one script loops on an error, a customer runs a bulk import, or a crawler finds your search endpoint. That caller is not malicious, only fast, and the rest of the callers wait behind it.
A rate limiter fixes this at the door. It gives each caller an allowance, say 20 requests in 20 ticks, and rejects whatever comes in over it. The service stays up and the heavy caller gets a clear signal to slow down.
Two different jobs
It helps to keep two ideas apart, because they are easy to confuse.
Rate limiting looks at the caller. It says: you may make this many requests. It protects the service from one caller and shares capacity out fairly. It does not know how busy the server is.
Load shedding looks at the server. It says: I am full, so some of you will be turned away. It protects the server from the sum of everyone. The next lesson covers it.
A limiter is a promise made in advance. Shedding is a reaction in the moment. You usually want both.
The decision is tiny, and it has to be cheap
A limiter runs on every request, before any real work, so it has to be fast and small. It also has to remember the past, because “20 requests in a window” is a statement about time. Each algorithm in this lesson is a different answer to one question: what is the least we can remember about a caller’s recent requests and still make a good decision?
Here is the first thing to predict. The limit is 20 requests per window of 20 ticks, counted with a fixed window. A caller sends 20 requests on the last tick of one window and 20 more on the first tick of the next.
Predict first
Twice the limit in two ticks
On that traffic the lab’s fixed window admitted 40measured requests inside one 20-tick span, against a limit of 20. The sliding window log admitted 20measured.
The next topic goes through the five algorithms and the state each one keeps.