Token Bucket Admission for Rider App API Requests
Last updated: November 29, 2026
Quick Overview
Simulate a token bucket rate limiter for one rider's API key: the bucket holds at most capacity tokens, starts full, gains one token every interval milliseconds, and each request consumes one token. Given sorted request timestamps, return whether each request is admitted.
Uber
November 29, 20260
0
0 solved
Simulate a token bucket rate limiter for one rider's API key: the bucket holds at most capacity tokens, starts full, gains one token every interval milliseconds, and each request consumes one token. Given sorted request timestamps, return whether each request is admitted.
Uber's edge gateway rate limits rider and driver clients, and this coding version is a common technical screen topic. The interviewer checks lazy refill math, integer-only time handling, and that partial progress toward the next token is not lost or double counted.
What the Interviewer Expects
- Refills lazily on each request instead of running a timer
- Caps tokens at capacity
- Preserves partial progress toward the next token
- Resets the refill clock when the bucket is full
- Explains how this extends to a distributed limiter
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you share this limiter across many gateway hosts with Redis?
- How would you support requests with different costs?
- How does a sliding window log compare in memory and accuracy?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: capacity >= 1, interval >= 1 (ms per token), and a non-decreasing list of timestamps. Output: list of booleans. Rejected requests do not consume tokens. All math is integer, so no floating ...
High-Level Design
Store tokens and last, the time from which refill progress is measured. On a request at t, compute add = (t - last) // interval. If that would fill the bucket, set tokens to capacity and move ...