Make Concurrent Card Authorizations Respect a Shared Spend Limit
Last updated: November 29, 2026
Quick Overview
Card authorizations for the same Ramp card can arrive on many threads at once. Implement a limiter that atomically checks and reserves spend against the card's limit, handles network retries of the same authorization, and supports reversals.
Ramp
November 29, 20260
0
0 solved
Card authorizations for the same Ramp card can arrive on many threads at once. Implement a limiter that atomically checks and reserves spend against the card's limit, handles network retries of the same authorization, and supports reversals.
Ramp's card program decides approve or decline inside a tight authorization window, and the same card can be swiped at two merchants or retried by the network within milliseconds. The interviewer is checking whether you spot the check-then-act race, pick a lock granularity that does not serialize the whole fleet, and treat retries as idempotent.
What the Interviewer Expects
- Identifies the read-check-write race that lets two authorizations overspend a limit
- Uses per-card locking instead of one global lock and explains why
- Makes a retried authorization with the same id a no-op rather than a second hold
- Handles reversals safely when they race with new authorizations
- Discusses how the same guarantee is achieved across processes (row lock or conditional update)
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 enforce this when authorizations are served by many hosts behind a load balancer?
- How do partial captures and tips that exceed the authorized amount change the bookkeeping?
- What happens to held spend if the reversal message is never received?
- How would you test for 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 ProblemsSample Answer
Requirements
Track a limit per card in cents. authorize(auth_id, card_id, amount) approves only if held plus settled spend stays within the limit, and the check and the reservation must be one atomic step. A net...
High-Level Design
The bug in the naive version is if used + amount <= limit: used += amount executed by two threads that both read the old used. I guard each card with its own lock so cards never contend with each ...