Design an Idempotent API for Issuing Virtual Cards
Last updated: November 29, 2026
Quick Overview
Design the endpoint a finance admin's client calls to issue a virtual card so that retries after timeouts never create duplicate cards, and implement the idempotency layer that sits in front of the handler.
Ramp
November 29, 20260
0
0 solved
Design the endpoint a finance admin's client calls to issue a virtual card so that retries after timeouts never create duplicate cards, and implement the idempotency layer that sits in front of the handler.
Ramp exposes card issuance through its dashboard and public API, and a client that times out will retry; two cards with the same limit is a real money and audit problem. The interviewer checks API shape (resource naming, status codes, error bodies) and whether the idempotency design covers concurrent retries and mismatched payloads.
What the Interviewer Expects
- Proposes a clear `POST /v1/cards` contract with an `Idempotency-Key` header scoped per tenant
- Stores a request fingerprint and replays the original response for exact retries
- Returns a distinct error when a key is reused with a different body
- Handles a retry that arrives while the first request is still running
- Chooses what to do when the handler fails before committing
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 make the record and the card creation commit atomically in Postgres?
- Should a 500 response be replayed or should the key be released?
- How long should keys live, and what does that cost in storage?
- How would you version this API when card controls change shape?
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
POST /v1/cards with body {user_id, limit_cents, interval, merchant_lock?} returns 201 with the card. Clients send Idempotency-Key; the same key with the same body must return the same card, th...
High-Level Design
Errors return a stable machine code plus a human message, for example {"error": {"code": "limit_exceeds_policy", "message": ...}}. Validation failures are 400, policy failures 422, and auth fail...