Snowflake: Tiered rate limiter whose limits can change while it runs
Problem. Build a rate-limiting service. Each client belongs to a tier, such as free, pro or enterprise, and each tier has its own limit. Tier limits can be changed while the service is running, without a restart. A request carries a client id. Allow it if the client is within its tier's limit, otherwise reject it. A requirement added verbally: if a client has no tier, or its config is broken, apply a global default policy. Defaulting to deny or to allow were both accepted.
The round was one hour in Python, and AI help was allowed.
Follow-ups, in order.
- Why this algorithm? What are the pros and cons of the alternatives?
- Write tests that prove it works.
- Real time passes too fast or too slow for a test to observe the bucket refilling. How do you test refill behaviour? (Answer: inject or mock a clock.)
- How would you turn this single in-memory instance into a cluster of rate limiters?
What mattered. Clarifying requirements, testing, and a correct refill formula: tokens added equal elapsed time times rate, capped at capacity. Also correct behaviour when a limit is raised: existing tokens should not jump. The candidate never reached the distributed question.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.