Prevent Double Redemption of Rewards Miles With Optimistic Locking

Last updated: November 29, 2026

Quick Overview

Two requests try to redeem miles from the same rewards account at nearly the same time. Implement redemption with a version column so the balance never goes negative, a redemption is never applied twice, and concurrent writers retry safely.

Capital One
Software Engineering Fundamentals
Software Engineer
Capital One
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Two requests try to redeem miles from the same rewards account at nearly the same time. Implement redemption with a version column so the balance never goes negative, a redemption is never applied twice, and concurrent writers retry safely.

Rewards redemptions for products like Venture miles are a real place where race conditions cost money: a double-tapped redeem button or two devices can drain the balance twice. The interviewer checks understanding of transaction isolation, lost updates, and optimistic versus pessimistic locking.

What the Interviewer Expects
  • Explain the lost update and why a read-then-write is unsafe
  • Use a conditional update on a version column (compare and set)
  • Put the debit and the redemption record in one transaction
  • Use a unique redemption id for idempotency
  • Retry on conflict with a bounded number of attempts
  • Compare with SELECT FOR UPDATE and an atomic conditional decrement
Key Topics to Cover
optimistic concurrency control
transactions
isolation levels
lost updates
idempotency
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
  • When would you prefer pessimistic locking here?
  • Could you avoid the version column entirely with a single UPDATE?
  • What isolation level does your database default to, and does it prevent this race?
  • How would you test the race deterministically?
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
  • redeem(account_id, redemption_id, miles) debits miles if the balance is sufficient.
  • Concurrent redemptions must never overdraw the balance or lose an update.
  • The same redemption_id must neve...
High-Level Design

Read the balance and version. If sufficient, run UPDATE ... SET miles = miles - ?, version = version + 1 WHERE account_id = ? AND version = ?. If another writer committed in between, the version no ...


Submit Your Answer
Markdown supported