Fix a Flaky Receipt Due-Date Test Around Midnight

Last updated: November 29, 2026

Quick Overview

A unit test for 'receipt overdue' reminders passes locally but fails on CI a few evenings a week. Find the bug in the due-date logic, fix it, and write tests that can never be flaky again.

Ramp
Software Engineering Fundamentals
Software Engineer
Ramp
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


A unit test for 'receipt overdue' reminders passes locally but fails on CI a few evenings a week. Find the bug in the due-date logic, fix it, and write tests that can never be flaky again.

Ramp nudges cardholders to upload receipts within a grace period, and the reminder logic touches card network timestamps in UTC and companies in many timezones. The interviewer wants a methodical debugging story: form a hypothesis from when it fails, reproduce it with a fixed input, fix the root cause, and remove the hidden wall-clock dependency.

What the Interviewer Expects
  • Notices the failure pattern (evenings in US time) points to a UTC date boundary
  • Identifies both bugs: using the UTC date instead of the company's local date, and reading the wall clock inside the function
  • Injects `now` so tests are deterministic
  • Writes boundary tests on both sides of local midnight and across a DST change
  • Rejects naive datetimes explicitly
Key Topics to Cover
Timezones
Flaky tests
Dependency injection
Boundary testing
DST
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you find every other place in the codebase that calls `date.today()` or `datetime.now()`?
  • Should the grace period count business days, and how would that change the tests?
  • What would a property-based test for this function look like?
  • How do you handle a company that changes its timezone setting?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

A receipt is due 7 calendar days after the transaction's posting date, where 'date' means the company's local calendar. A reminder fires when today, in the company's timezone, is past the due date. Th...

High-Level Design

The failure only appears when local time and UTC disagree on the date, which for a US company is the evening, matching when CI runs nightly. That gives two root causes. First, a 9:30pm Pacific purchas...


Submit Your Answer
Markdown supported