Design a Payment System: System Design Interview Walkthrough
- Andrew C. Lewis
- 12 Nov, 2026
- 15 Mins read
“Design a payment system” is the system design question where the usual playbook fails. Most questions reward scale: shard the database, add a cache, fan out the writes. A payment system has almost no scale problem. It has a correctness problem. If a notification arrives twice, the user is annoyed. If a card is charged twice, the company refunds money, pays a dispute fee, and may lose the customer. A candidate who opens with “we need to handle millions of transactions per second” has already shown they misread the question.
This walkthrough follows the 45-minute shape from the system design interview framework: requirements, the one number that matters, the high-level design with one request walked through, two deep dives, trade-offs, and what the interviewer probes at each level. The two deep dives are the two things every real payment system is built around: idempotency (making a retried request safe) and the ledger (the record of where every cent went).
Requirements and scope (0 to 5 minutes)
Payments are a broad topic, so scoping matters more here than in most questions. A card payment goes through a payment provider (a company such as Stripe or Adyen that talks to the card networks for you), so you are not designing the card network. You are designing the system that sits between your checkout page and that provider.
Functional requirements to confirm with the interviewer:
- Charge a card through a payment provider. The provider returns approved or declined.
- Record the payment so the order system, the customer and the finance team can see it.
- Refund a payment, in full or in part.
- Never double charge. A retried request must not create a second charge.
- Money must add up at the end of the day. What the provider says it moved must match what the system says it moved.
Non-functional requirements (how well the system runs, rather than what it does):
- Correctness over speed. A checkout that takes two seconds is fine. A checkout that charges twice is not.
- Durability. Once the system says “paid”, that fact must survive a crash.
- Auditability. Every change to a payment must be traceable to who did it and when.
What to say: “I will assume we use one external payment provider, that the card details never touch our servers because the checkout page tokenizes them (replaces the card number with a reference the provider understands), and that losing speed is acceptable but losing or duplicating money is not. I will leave out fraud scoring, subscriptions and multi-currency, and I will say so if any of them affect a choice.”
Write the scope on the board. It is what you point to when you cut something later.
The number that matters (5 to 8 minutes)
This is the moment to show you understand the question. Most candidates do a throughput estimate here because the framework says to. Do the estimate, but draw the right conclusion from it.
- Say the business handles 1 million payments a day. That is a large business.
- A day has 86,400 seconds. 1 million divided by 86,400 is about 12 payments a second.
- Peak is 2 to 3 times the average by the usual rule of thumb, so about 30 to 40 a second.
A single PostgreSQL instance on four virtual CPUs handles roughly 4,700 to 6,200 mixed read-write transactions a second in a 2025 benchmark (ClickHouse benchmark, 2025). A payment system at 40 writes a second is nowhere near a database limit.
What to say: “Even at a million payments a day this is about 12 a second, so throughput is not the hard part. The hard part is correctness: every one of those payments has to happen exactly once from the customer’s point of view, and the books have to balance. I am going to design for that, with one primary database, and I will not shard anything unless you ask me to.”
High-level design (8 to 20 minutes)
Draw the simplest design that meets the scope. For a payment system that is still more boxes than most, because each box fixes one way of losing money.
The parts, in the order you draw them:
- Payment API. The checkout page or the merchant’s backend calls it: create a payment, get a payment, refund a payment. Every create and refund request carries an idempotency key (a unique id the client makes for this one attempt, so a retry can be recognised).
- Idempotency key store. Where the API records which keys it has seen and what it answered. Deep dive one is about this box.
- Payment service with a state machine. A state machine is a fixed list of states a payment can be in and the allowed moves between them. It is the only component that may change a payment’s state.
- Payments table in the primary database. One row per payment: id, amount, currency, state, provider reference, timestamps.
- Provider adapter. The one place that knows how to talk to the payment provider. It translates “charge 50.00” into the provider’s API call and translates the provider’s reply back. Swapping providers later means rewriting this box only.
- Webhook receiver and event queue. The provider reports later events (a dispute, a settled refund, a delayed decline) by calling a URL of yours. These webhooks (a notification the provider posts to your server when something happens) go onto a queue so a slow or crashed payment service does not lose them.
- Ledger. The double-entry record of every movement of money. Deep dive two is about this box.
- Reconciliation job. A nightly job that compares the ledger with the provider’s settlement report (the provider’s own list of what it moved and when).
Now walk one charge through it, out loud, pointing at each box.
What to say: “The checkout posts a payment of 50.00 with a card token and an idempotency key. The API checks the key store: never seen, so it records the key as in progress. The payment service writes a row in state ‘created’, calls the provider through the adapter, and gets ‘approved’. It moves the row to ‘captured’ and writes two ledger rows for the 50.00. The API saves the full response under the idempotency key and returns the payment id. If the client’s network dropped before the response arrived, it sends the same request with the same key, and the API returns the saved response. One charge.”
Then stop and ask: “That is the happy path. Do you want me to go deep on what happens when it is not happy, which is idempotency and the ledger, or somewhere else?” You have a complete picture on the board by minute 20, which is the midpoint rule from an interviewer who says they have run about a thousand rounds (Blind AMA, June 2024).
The state machine
Before the deep dives, spend one minute on the states. Interviewers at payment companies ask about them directly, and the diagram is quick to draw.
In plain words:
- Created. The row exists. Nothing has been asked of the provider yet.
- Authorized. The provider has put a hold on the money. The bank has agreed, but nothing has moved yet. A hotel does this at check-in.
- Captured. The hold has been turned into a real charge. This is when the customer sees the line on their statement.
- Voided. The hold was released without capturing. Nothing moved.
- Failed. The provider declined, or the capture failed.
- Refunded and partially refunded. Money went back to the card, all of it or some of it.
Two rules make the state machine useful. First, every transition is written as a row in a payment events table, with the old state, the new state, who caused it and when. That table is your audit trail. Second, the service rejects any move that is not an arrow in the diagram. A refund request on a payment in state “created” is a bug somewhere, and refusing it is better than guessing.
What to say: “The state machine stops impossible things, like refunding a payment that was never captured, and gives the support team a history they can read.”
Deep dive one: idempotency (20 to 29 minutes)
The interviewer’s question is usually some form of: “The provider approved the charge, then your service crashed before writing ‘captured’. The client retries. What happens?”
Start with the fact that makes this hard. A client that sends a request and gets no response cannot know whether the server did the work. The network might have dropped the request on the way in, or dropped the response on the way out. From the client’s side those look the same. This is why exactly-once delivery over a network is not possible to guarantee: the client has to retry to be safe, and a retry might repeat work that already happened. The way out is at-least-once delivery (retry until you get an answer) plus idempotency (make the repeat harmless).
The idempotency key is how you make the repeat harmless. Stripe’s API accepts an Idempotency-Key header on every POST request and describes the key as a unique id “to identify just that operation” (Stripe, 2017). The server’s job is to remember what it did under that key.
The rules, in the order the interviewer will probe them:
- The client generates the key, one per attempt at one operation, and sends the same key on every retry of that attempt. Stripe suggests a random UUID (a 128-bit random id) and caps keys at 255 characters (Stripe API docs).
- The server stores the response under the key. Stripe saves the status code and body of the first request made with a key, once that request starts executing, and returns the saved response on a retry, “including 500 errors” (Stripe API docs). Returning the saved error is deliberate: the client gets a consistent view, and can start a fresh attempt with a fresh key.
- A key with different parameters is an error. The server compares the incoming request with the original and refuses if they differ, so a bug that reuses a key for a different amount is caught rather than silently answered with the old payment. The IETF draft that standardises the header says the server should answer such a reuse with HTTP 422 (IETF draft).
- Reads and writes of the key go to the primary database, never a replica (a read-only copy that lags behind). Airbnb’s payments team built its idempotency layer this way, because a check against a replica that has not yet seen the key would let a duplicate through (Airbnb, 2019). The same post splits each request into a pre-call phase, the provider call, and a post-call phase, with the key state written in a database transaction before and after the provider call so a crash in the middle is visible on the retry.
- Keys can be pruned after a day. Stripe removes keys once they are at least 24 hours old (Stripe API docs). Clients retry within seconds or minutes, so a day is generous, and the store stays small.
Now answer the crash question directly.
What to say: “The key store has three states: in progress, done with a saved response, and absent. When the service crashes after the provider approved but before we wrote ‘captured’, the key is still ‘in progress’ and the payment row is still ‘created’ with the provider’s reference saved on it. The retry sees ‘in progress’, so it does not call the provider again. It asks the provider for the status of that reference, learns it is captured, finishes the state change, writes the ledger rows, saves the response, and returns. If the crash happened before we even got a provider reference, there is nothing to recover and the retry runs the charge once.”
Add the retry policy, because it is where candidates lose points for naming a pattern without its details:
- Retryable errors are the ones where trying again can help: a timeout, a connection reset, a 500 from the provider, a 429 rate-limit response. Retry with backoff (a wait that grows after each failure) and jitter (a random part added to the wait so a thousand clients do not retry in the same second). AWS shows that retrying immediately under overload “can make matters significantly worse” (AWS Builders’ Library).
- Permanent errors are the ones where trying again cannot help: card declined, invalid card, amount too large, idempotency key reused with different parameters. Do not retry. Return the error to the user and move the payment to “failed”.
The trap in this deep dive is a lock. Some candidates propose locking the customer’s row for the whole provider call. A provider call can take seconds, the lock holds a database connection the whole time, and a crash while holding it needs a separate cleanup. The idempotency key gives the same guarantee with no long-lived lock.
Deep dive two: the ledger and reconciliation (29 to 38 minutes)
If idempotency is how you avoid double charging, the ledger is how you prove you did not. The interviewer’s question here is usually “how do you know the books balance?” or “finance says the provider paid out 3.00 less than expected yesterday. Where do you look?”
Double-entry bookkeeping is an old accounting rule that engineers rediscover: every movement of money is written as two rows, one per account, that add up to zero. Money never appears or disappears. It only moves from one account to another, and both sides of the move are recorded. If you have never done bookkeeping, think of jars: a charge takes 50.00 out of the “customer owes us” jar and puts 50.00 into the “merchant balance” jar. Sum every jar and you always get zero, because every entry has an equal and opposite twin.
The design rules for the ledger table:
- Append-only. Rows are inserted, never updated or deleted. A mistake is fixed by writing a correcting pair of rows, not by editing the wrong one. This is what makes the ledger an audit trail: the history is the data.
- Two rows per movement, with the same transaction id, one negative and one positive, and a database check that the pair sums to zero before the transaction commits.
- Balances are derived. The merchant’s balance is the sum of the merchant’s rows. You do not store a balance column and hope it stays in sync; you compute it, and cache a running total for speed if you must, with the rows as the source of truth.
- Amounts in integer minor units (cents, not dollars), so 10 cents plus 20 cents is exactly 30, while 0.1 plus 0.2 in floating-point math comes out as 0.30000000000000004. Say this; interviewers at payment companies listen for it.
- A row per fee. The provider’s cut is its own movement, from the merchant balance to a provider fees account.
What to say: “The ledger has one job: say where every cent is and how it got there. Each payment writes two rows that sum to zero, the rows are never edited, and balances are sums. When finance asks why a payout is 3.00 short, we sum the rows for that day and compare them with the provider’s report.”
That comparison is reconciliation. It exists because two systems can both be correct about their own data and still disagree: your ledger might have a refund the provider has not processed yet, or the provider might have charged a dispute fee your system never heard about because a webhook was lost. The nightly job:
- Pulls the provider’s settlement report for the day (the list of every charge, refund, fee and payout the provider says it made).
- Sums your ledger for the same day, by type.
- Matches rows one to one on the provider’s reference id.
- Writes every mismatch to an exceptions list: in your ledger but not the report, in the report but not your ledger, or in both with different amounts.
What a mismatch looks like, and how each one is fixed:
- A charge in your ledger, missing from the report. Usually a payment you marked captured that the provider never finalised, or a timing difference. Hold it one more day, then query the provider for that reference.
- A fee in the report, missing from your ledger. Usually a dispute or a currency adjustment that arrived as a webhook you lost. Write the missing pair of rows with a reason code, and fix the webhook path.
- Same reference, different amounts. Usually a partial refund recorded on one side only. Query the provider, write a correcting pair.
The fix is never “edit the row”. It is always “write new rows and record why”. The exceptions list is the screen the finance team opens every morning.
Webhooks, the outbox and the saga, in one minute each
Three patterns come up as follow-ups. Know the one-sentence version of each.
- Webhooks are at-least-once too. The provider may send the same event twice, and may send events out of order. Each webhook carries the provider’s event id; store it, drop repeats, and let the state machine refuse moves that do not make sense (a “captured” event for a payment already captured is a no-op, not an error).
- The outbox pattern solves “I wrote the payment row, then the service crashed before publishing the event”. Write the event into an outbox table in the same database transaction as the payment row, and let a separate relay publish it to the queue. The transaction either commits both or neither (microservices.io).
- A saga is a sequence of local transactions across services, where each step has a compensating step that undoes it if a later step fails (microservices.io). Place order, charge card, reserve stock; if stock fails, refund the card. In the payment system itself you rarely need a saga, but the order system that calls you does, and a refund is the compensating step it will ask you for.
Reaching for a saga inside the payment service is usually over-engineering, the failure Hello Interview names most often (Hello Interview, January 2025). One primary database, one transaction per state change, and the outbox for events cover almost everything in scope.
Trade-offs and what you cut (38 to 43 minutes)
What to say: “I chose one primary database with every payment write in a transaction, because at 12 payments a second consistency is cheap and a lost or duplicated payment is expensive. The idempotency key store and the ledger live in the same database as the payments table so a crash can never leave them disagreeing. The cost is that this design does not scale past one primary without partitioning, and I would partition by merchant when it needs to. I used at-least-once everywhere, with the key store and the state machine making repeats harmless, because exactly-once over a network cannot be promised. What I cut: fraud scoring, which would sit in front of the payment service as a yes-or-no call; multi-currency, which adds an exchange-rate row to each ledger pair; and subscriptions, which are a scheduler on top of this. With more time I would add a second provider behind the adapter for failover, and a replay tool that re-runs lost webhooks from the provider’s event log.”
Choice, cost, what was cut, what comes next. Then stop.
What the interviewer probes at each level
The same question is asked from mid level to staff. The probes change.
- Mid level. Can you draw the happy path and explain why a retry does not double charge? Do you know what an idempotency key is? Do you refuse a refund on a payment that was never captured?
- Senior. The crash scenarios: crash after authorise, crash after capture, crash while writing the ledger. The retryable versus permanent split. Why the key check must hit the primary. What reconciliation finds and how it is fixed.
- Staff. The organisational version: what happens when the provider is down for an hour (queue the charges and tell the user “pending”, or fail fast?), how to add a second provider without rewriting the service, what the finance team needs that engineering never thinks of, and the cost of each guarantee. Hello Interview’s staff guide names refusing to pick an option as the most common staff-level failure (Hello Interview). Pick, and say why.
At every level the tell for a weak answer is the same: a throughput estimate followed by sharding, caching and a message queue, with no mention of what happens when a response is lost. The sentence the interviewer is waiting for is “exactly-once is not possible over a network, so I use at-least-once plus idempotency”.
Practice this question against the clock
Run it out loud with a 45-minute timer, drawing in a whiteboard tool. Then run the follow-ups: “the provider says captured, you have no record of it”, “two refunds for the same payment arrive in the same second”, “finance wants a balance per merchant per currency”. For the same shape on different questions, the rate limiter is the opposite problem (pure throughput, little correctness), and Instagram exercises fan-out. The 20 questions with answer outlines covers the rest of the list, and the one-page summary has the numbers to carry in. If you tend to over-build, read the mistakes interviewers report first; the payment question punishes that habit more than any other.
How InterviewStorm helps
The payment question is the one where the obvious answer is wrong, and the only way to learn that is to give the obvious answer once and have it corrected. InterviewStorm is a practice partner for that: describe the question in a mock call and it gives back the requirements to confirm, the number that actually matters (and why it is not throughput here), an architecture diagram it draws itself, the charge walked through with the idempotency check, the schema and APIs for the payments table and the ledger, the scaling moves, and the trade-offs to name. Run it, compare it with your own design, and redo the part that differed. See the system design feature.
Most companies do not allow AI help during the design round itself, and interviewers say they watch for it. Use it where the employer allows it, and to practise everywhere else. Follow each employer’s interview rules. Do not use InterviewStorm in proctored tests, exams, or anywhere AI help is not allowed.
The free trial is 20 minutes in total, up to 15 minutes per session, with no credit card. Try it free.
For the rest of the loop, read the guides on coding interviews and the STAR method.
Share Articles:
Similar Posts