Keep a Gift Card Balance Correct Under Concurrent Redemptions
Last updated: November 29, 2026
Quick Overview
Two checkouts can try to spend the same Walmart gift card at the same moment, and network retries can submit the same redemption twice. Design the database schema and transaction logic so the balance never goes negative and each order is charged exactly once.
Walmart Labs
November 29, 20260
0
0 solved
Two checkouts can try to spend the same Walmart gift card at the same moment, and network retries can submit the same redemption twice. Design the database schema and transaction logic so the balance never goes negative and each order is charged exactly once.
Gift cards are stored value, so double spends or lost debits are direct financial loss and audit findings. Walmart Labs onsite interviewers use this to test practical transaction knowledge: isolation anomalies, atomic conditional updates, uniqueness constraints for idempotency, and an auditable ledger.
What the Interviewer Expects
- Name the lost update anomaly in read, check, write logic
- Use an atomic conditional UPDATE or row lock instead of read then write
- Enforce idempotency with a unique constraint on order id
- Keep a ledger so the balance is auditable
- Explain what each isolation level does and does not prevent here
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 split a payment across a gift card and a credit card atomically?
- How would you handle a refund to a card that was partially spent?
- Would you store the balance at all, or derive it from the ledger?
- How does this change on a database sharded by card id?
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
redeem(card_id, order_id, amount) debits the card if the balance covers it. Guarantees: the balance never goes negative, a given order debits at most once even if retried, and every change is record...
High-Level Design
The naive flow (SELECT balance, check in app code, UPDATE balance) suffers a lost update under READ COMMITTED: two transactions read 5000, both debit 300, and one write overwrites the other. Fixes: ei...