1/17
Learn
A rate limiter for an LLM API, the way the design round asks
OpenAI candidates report rate limiting as a system design question (1 report), a guide lists a distributed rate limiter for the design round and an implementation for coding (2 sources), and an ML engineer candidate had to find the bug in a Django app's rate limiter (1 report). This lesson's practice problem builds the limiter, in three levels:
TokenBucket(capacity, rate), withallow(now, cost)andretry_after(now, cost): a burst, then a steady rate, and when to come back.LLMLimiter(rpm, itpm, otpm), withstart(...)andfinish(...): requests, input tokens and output tokens, all or nothing, with the answer's tokens reserved and the unused ones given back.KeyedLimiter(capacity, rate, global_capacity, global_rate): a bucket for each customer and one for everyone, with no memory kept for customers whose buckets are full.
Call Returns 8 questions in a second, against a burst of 5 True five times, then False retry_afterat 10.5 s, for that customer2.5 s, so the header says 3 startreserving max_tokens of 4,096, under 400,000 a minuteroom for 97 answers a minute keys(now)an hour after the last question0 buckets kept
The lesson follows the outdoor shop's assistant at 120,000 questions a day: the provider's limits, the token bucket, limits on tokens, one limit across many servers, and how many requests run at once. Seven steps end with a small task in the editor.