Available for consulting: payments, backend performance and platform engineering.Book a call
Saravana Thiyagarajan · The Backend Guy
Book a call
System design interview · Payments

Payment system design interview questions, with answers.

These are the questions I would expect in a payment system design round, and the answers I would give. Each answer is short on purpose. The link under it goes to the chapter of The Payment Processing Handbook that explains it properly, with diagrams and tested Go, Python and PostgreSQL code.

Read the handbook
Fundamentals

Start with what a payment is.

How would you model the lifecycle of a payment?

As a state machine with one status column and a fixed list of allowed moves, such as CREATED to PENDING to SUCCESS or FAILED. Every update is conditional on the state you expect, so a change that shouldn't happen fails instead of slipping through. Boolean flags like is_paid and is_refunded can combine into states that make no sense.

Go deeper: Part 1: Designing a payment lifecycle

The provider call timed out. Did the payment fail?

You don't know, and saying so is the answer interviewers want. A timeout means you stopped waiting. Mark the payment as unknown, then find out from the provider's status API, the webhook, or reconciliation. Treating it as failed and letting the user retry is how people get charged twice.

Go deeper: Part 1: Why processing payments is harder than it looks

Money and the ledger

Get the money right before anything else.

How do you store money in a database?

Never in a binary float. Use integer minor units, such as cents or paise, or a fixed-precision decimal, and always store the currency next to the amount. Decide each rounding rule on purpose and apply it in one place.

Go deeper: Part 2: Representing money and financial values

Design a ledger for customer balances.

A double-entry ledger: an append-only table of journals where each journal's entries sum to zero, so money always leaves one account and enters another. A balance is a sum of entries, which means you can explain any balance from its history. Mistakes are fixed with a reversing journal, never an UPDATE or DELETE.

Go deeper: Part 2: Building an immutable financial ledger

What invariants would you enforce, and where?

Every journal sums to zero, a wallet can't be spent below what it holds, and a payment settles once. Each rule gets up to three guards: a database constraint, a runtime check in the same transaction, and a reconciliation query that finds a violation the same day. If a rule can be a constraint, make it one, because constraints are the only guard no race or script can get past.

Go deeper: Part 2: Transaction consistency and financial invariants

Idempotency and concurrency

The questions that decide most payment interviews.

How do you make a payment API idempotent?

The client sends an idempotency key that stays the same on every retry of one operation. Store the key behind a unique constraint, in the same transaction as the effect, along with the response. A repeat with the same key gets the stored response; a repeat with the same key and a different body is rejected.

Go deeper: Part 3: Idempotency

Two requests debit the same wallet at the same time. What happens?

Under PostgreSQL's default isolation, two transactions that read, compute and write can erase each other's update. Let the database do the arithmetic in the UPDATE, use compare-and-swap on the value you read, or lock the row with SELECT ... FOR UPDATE. Keep the lock short and never call a provider while you hold it.

Go deeper: Part 3: Locks, compare-and-swap and concurrency control

Would you use a Redis lock to stop double payments?

Not as the only guard. A Redis lock is a lease, and it can expire while its holder is still working, so two workers can both think they own it. That's fine when the worst case is wasted effort. When the worst case is money moving twice, the guarantee has to come from the database.

Go deeper: Part 3: Why Redis is not always the answer

Events and queues

Moving payments between services.

How do you handle payment webhooks reliably?

Verify the signature, store the raw event durably, then reply with success, and do the real work afterwards on a worker. If you process first and crash before replying, the provider retries; if you reply first and crash before saving, the event is lost. Deduplicate on the provider's event ID.

Go deeper: Part 4: Building an event-driven payment engine

How do you update the database and publish an event without losing either?

The transactional outbox. Write the event to an outbox table in the same transaction as the change, and have a separate process publish it. Publishing can repeat, so each consumer keeps an inbox of processed message IDs and skips duplicates.

Go deeper: Part 4: Transactional outbox and inbox patterns

When should an SQS consumer delete the message?

Only after the work it triggered has committed. If the worker dies first, the message becomes visible again after the visibility timeout and runs again, and the inbox makes the repeat harmless. The visibility timeout only decides when a message comes back. It is not a correctness guarantee.

Go deeper: Part 4: SQS visibility timeout and worker concurrency

Failures and retries

What happens when things break.

A withdrawal has three steps. How does it survive a crash halfway?

Record progress in a status column, make every step safe to run again, and run a sweeper that picks up withdrawals stuck in one state for too long. Whoever runs next continues from the last recorded step. If the payout call timed out, check with the provider before refunding, or you may pay twice.

Go deeper: Part 5: Designing resumable payment workflows

Which errors would you retry, and how?

Timeouts and connection resets with the same idempotency key, 5xx responses, 429s (slower, honouring Retry-After), and database deadlocks or serialization failures. Not 4xx client errors or a declined card. Wait with exponential backoff and full jitter so clients don't all come back at once and cause a retry storm.

Go deeper: Part 6: Retry strategies, backoff and recovery storms

How many database connections should the service use?

Count what the database sees: pool size times every pod of every service. Size pools from the work, keep transactions short, and keep network calls out of transactions, or one slow provider holds connections until the pool runs dry.

Go deeper: Part 5: Connection pooling and short transactions

Running it in production

How you know it works.

What is reconciliation and why do you need it?

Comparing your records with the provider's and the bank's every day. Match on references you sent, store every difference with both sides, and resolve only the clear cases automatically, through the normal code path. It is the net that catches whatever the rest of the design missed.

Go deeper: Part 7: Reconciliation, the final safety net

What would you monitor and alert on?

What customers feel: failed payments, slow payments, stuck states. Not CPU. Put the payment ID and trace ID on every log line and span, carry trace context through the outbox and queue, and give every alert a runbook.

Go deeper: Part 7: Metrics, monitoring and alerting

The whole design

Putting the answer together.

Design a payment system end to end.

PostgreSQL as the single source of truth. The API records intent with an idempotency key, the ledger holds balances, an outbox announces changes, workers apply them behind an inbox, providers are called outside database transactions, and reconciliation checks everything daily. Then walk through a duplicate webhook, a lost payout reply and a cancellation racing a redelivery, and show money moves once in each.

Go deeper: Part 8: End-to-end payment architecture

Preparing

How to use this page.

Interviewers rarely want a diagram of boxes. They want to hear what happens when a request is retried, a reply is lost or two things happen at once, and how your design keeps money from moving twice. Practise saying each answer out loud, then read the chapter and check you can explain the failure cases too.

If you are building a real payment system rather than preparing for an interview, I review payment and ledger designs as a fixed-price engagement.

Have a backend or payments problem to solve?

Tell me what you are building and where it hurts. I reply within one working day, usually with a time for a 30-minute call.