Enforce Per-Vault Burst and Daily API Rate Limits
Last updated: November 29, 2026
Quick Overview
Implement a limiter for a multi-tenant document API that admits a call for a given vault only if fewer than B calls were admitted in the trailing W seconds and fewer than D calls today, and returns the remaining allowance either way.
Veeva Systems
November 29, 20260
0
0 solved
Implement a limiter for a multi-tenant document API that admits a call for a given vault only if fewer than B calls were admitted in the trailing W seconds and fewer than D calls today, and returns the remaining allowance either way.
The Vault REST API publishes burst and daily limits per vault and returns the remaining counts in response headers, so integrations from CROs and partners must back off gracefully. The interviewer checks sliding window versus fixed window trade-offs, tenant isolation, and how the design moves from one process to a distributed service.
What the Interviewer Expects
- Separates the two limits: sliding window for burst, calendar-day counter for daily
- Isolates state per tenant so one noisy integration cannot starve another
- Only records admitted calls, so rejected retries do not extend a lockout
- Returns remaining allowance to support headers clients can back off on
- Explains memory cost of a timestamp log and alternatives (sliding window counter, token bucket)
- Describes moving state to Redis with atomic scripts for a fleet of API servers
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you implement this across 50 API servers without a single hot key?
- The timestamp deque holds up to B entries per vault; how would you cut memory with an approximate sliding window counter?
- Should a rejected call count against the daily limit? Argue both sides.
- How should the client SDK react to a 429 with remaining headers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
allow(vault_id, ts) returns (admitted, remaining). Burst: at most B admitted calls in any trailing W seconds (a true sliding window, not fixed buckets, so a client cannot fire 2B calls across a bu...
High-Level Design
Per vault keep a deque of admitted timestamps for the burst window and a (day, count) pair for the daily limit. On each call, evict timestamps older than ts - W, roll the day counter if the day ch...