A worked example: rate limits for the shop's assistant
The prompt, from a guide to OpenAI interviews: design a distributed rate limiter (1 source). For the shop, that means limiting every customer of the assistant and keeping the whole shop inside its provider's limits.
1. Clarify. Who gets limited: signed-in customers by account, visitors by IP address. What counts: questions, tokens and runs in flight. How exact it must be: a few percent over for a minute is fine, and a script running for an hour isn't. What a limited customer sees, and how many servers and active customers there are.
A visitor who isn't signed in has no account. What should their bucket be keyed on?
The plan sets each customer's Redis key to expire at the moment its bucket would be full again. Why is deleting it safe?
Why set the shop's own bucket at 90% of the provider's limits, not 100%?