Deep Dive: The Leaky Token Bucket
An engineering analysis of why this AI-generated Pull Request passed isolated unit tests, how multi-tenant traffic exposes the architectural flaw, and how interviewers score your response.
The Root Cause Anti-Pattern
In Python, default parameter expressions such as default_bucket={"tokens": 5.0, ...} are evaluated only once when the function is defined, not per instance instantiation. Because the dictionary is mutable, every client that falls back to this default operates on the exact same dictionary in memory, creating a silent cross-tenant quota leak.
The Interviewer's Scoring Rubric
Candidates are assessed on whether they jump to trial-and-error editing or follow a hypothesis-driven approach. A "Strong Hire" candidate restates the data flow between modules, explains why single-client unit tests passed, crafts an adversarial probe showing cross-tenant leakage, and implements a surgical 1-line patch without breaking existing contracts.
Candidate Strategy for the Code Comprehension Round
- 1Map Module ContractsTrace how the gateway invokes the underlying service. Note what data is passed by reference vs. by value.
- 2Break It With An Adversarial ProbeSimulate concurrent or sequential traffic across multiple identities to force shared state mutation.
- 3Deliver a Surgical PatchMake the minimal required diff to ensure proper per-client state isolation without refactoring unnecessary files.