Stop Double Payouts of Employee Reimbursements With Transactions
Last updated: November 29, 2026
Quick Overview
Two payout workers sometimes pick up the same approved reimbursement and pay the employee twice. Use database transactions, a compare-and-set status change and a unique constraint so a reimbursement can be paid at most once.
Ramp
November 29, 20260
0
0 solved
Two payout workers sometimes pick up the same approved reimbursement and pay the employee twice. Use database transactions, a compare-and-set status change and a unique constraint so a reimbursement can be paid at most once.
Ramp reimburses out-of-pocket expenses by ACH, and a duplicate payout is real money that is hard to claw back from an employee. The interviewer probes transaction isolation, lost updates, how to claim work atomically, and how the database schema itself can act as the last line of defense.
What the Interviewer Expects
- Explains the race: two workers read `approved`, both send money, both write `paid`
- Uses a conditional UPDATE (or SELECT FOR UPDATE SKIP LOCKED) to claim the row atomically
- Writes the payout record in the same transaction as the status change
- Adds a unique constraint on the payout's reimbursement id as a backstop
- Separates the external bank call from the database transaction and handles the gap
- Discusses isolation levels and why read committed alone does not prevent this
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
- Why should the ACH call not happen inside the database transaction?
- A worker crashes after claiming but before calling the bank. How is that row recovered?
- How would SERIALIZABLE isolation change the design, and what does it cost?
- How would you detect duplicate payouts that slipped through historically?
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
A reimbursement moves approved -> paying -> paid (or failed). Any number of workers may scan for approved rows. Each reimbursement produces at most one payout row and one bank instruction, even wi...
High-Level Design
The original worker did SELECT ... WHERE status='approved', called the bank, then UPDATE status='paid'. Under read committed, two workers can both see the row as approved. The fix has three layers...