Every API you have ever called has a speed limit. Exceed it and you receive a 429 Too Many Requests error instead of a reply. The limit is not just about fairness: without it, a single misbehaving client can crowd out everyone else or melt a server.
The challenge is that "too fast" is surprisingly tricky to define. A client that sends ten requests in one second is certainly fast. But what about ten requests in one minute — is that ten little bursts of one, or one big burst of ten? And what if they are allowed to save up quiet time for an occasional burst?
The Generic Cell Rate Algorithm (GCRA) answers all three questions with a single number per client. First standardized in ATM networking by the ITU-T in 1992 and later popularized in web-API contexts, GCRA tracks a theoretical arrival time (TAT): the moment the next request would be due if arrivals were perfectly spaced. Each new request is accepted if it arrives early enough, and the TAT is pushed forward. The gap between a request's arrival and the TAT encodes both the average rate and the burst allowance in one compact computation.
This article unpacks how that single number does all the work, and why it is equivalent to both the token bucket and the leaky bucket — two algorithms that look completely different on the surface.
Comments
Loading comments...