Diagnose and Fix a Flaky Offer Expiration Test
Last updated: November 29, 2026
Quick Overview
A test for the service that expires unaccepted delivery offers fails about one run in twenty in CI. It reads wall-clock time and sleeps 1.1 seconds waiting for a background thread. Explain how you would diagnose the flakiness and rewrite the code and tests to be deterministic.
DoorDash
November 29, 20260
0
0 solved
A test for the service that expires unaccepted delivery offers fails about one run in twenty in CI. It reads wall-clock time and sleeps 1.1 seconds waiting for a background thread. Explain how you would diagnose the flakiness and rewrite the code and tests to be deterministic.
DoorDash dispatch logic is full of timeouts (offer expiry, order auto-cancel, Dasher check-ins), and tests around time are a common source of CI flakiness. The interviewer checks a disciplined debugging process and the design fix: inject the clock and expose the work the background thread does so tests can drive it directly.
What the Interviewer Expects
- Reproduce by running the test many times, under load, and in parallel
- Identify the sources of nondeterminism: wall clock, sleeps and thread scheduling
- Inject a fake clock instead of patching time globally
- Expose a sweep method the background loop calls, and call it directly in tests
- Test the exact TTL boundary and the accept-versus-expire race
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 still test the background loop itself?
- Should a flaky test be quarantined, deleted or fixed first, and who decides?
- How would you detect flaky tests across the whole CI fleet?
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
offer(order, dasher),accept(order)and expiry afterttlseconds.- Expired offers trigger
on_expire(order)exactly once. - Tests must be deterministic and run in milliseconds....
High-Level Design
First reproduce: loop the test 500 times, then run it with stress on the box; failures cluster when CI is loaded, which points at timing. The original test assumed the background thread runs within ...