Design a token grant system with automatic one-hour release.
Unlock detailed company stats for this questionUpgrade
A bucket holds a limited number of tokens. Users request tokens and are either granted or rejected based on current availability. If granted, the user holds those n tokens for exactly 1 hour, after which they are automatically returned to the bucket. Support requestTokens(userId, n), releaseTokens(userId), and a background expiry mechanism.
Discussion points: a min-heap / priority queue ordered by expiry time for auto-release; handling concurrent requests (locking vs. atomic operations); edge cases such as partial grants, a user requesting tokens they already hold, and expiry during an active request; time complexity of grant and release.
Expect follow-ups like
- How do you handle concurrent requests?
- What edge cases exist such as partial grants or expiry during a request?
Community answers
No answers contributed by the community yet.
Related questions
Design an automated reimbursement system.Related courses

Course

