May we use cookies so Meta, Google, LinkedIn and ChatGPT see your visit and we learn which ads work? PrivacyMay we use cookies to see which pages help, and let Meta, Google, LinkedIn and ChatGPT see your visit, so we know which of our ads work? That way we spend less on ads that do not work. We do not sell your data, and the site works the same if you decline. You can change your answer at any time under Cookie settings at the foot of the page. Privacy policy
Loading...
System Design and AI Engineering, by Roni Das. 989 interactive lessons in two courses.: 770 in System Design and 219 in AI Engineering.
Start LearningSystem design interview guide
Short answer
A payment system moves money from a customer to a merchant without ever charging twice or losing a cent. Every request carries an idempotency key, so a retry is safe. Every money movement goes into a double-entry ledger whose rows add up to zero. A timeout leaves the payment pending, not failed. Every day, the ledger is reconciled against the provider and the bank.
in this guide
8 parts open to everyone · 3 with a free account · 3 with the course
You can read 8 of 14 parts. A free account opens the deep dive; the course opens all of it.
Most system design questions forgive small mistakes. A like count can be wrong for a second. A payment cannot. So this question tests whether you think about failure first. Interviewers listen for a few things. Do you make retries safe with idempotency keys? Do you keep money in a ledger instead of one balance number? Do you know that a timeout does not mean failure? Do you reconcile with the bank every day? And do you know when to choose consistency over speed? A candidate who only draws boxes and arrows misses all of this.
This page is the free part.
₹1,111 in India$35 everywhere elseonce, for the whole course
The System Design course covers the Payment System design across a run of lessons, not one page. These 4 alone are about 93 minutes of step-by-step reading, every one with a quiz.
Always clarify these in the first 5 minutes of the interview. Do not start drawing boxes until both lists are agreed.
This guide is built on these 6 lessons. Each one teaches one piece of the Payment System design above, step by step.
Lifetime access for ₹1,111 in India or $35 elsewhere. Interactive diagrams, quizzes, and 20 capstone projects to practise on.
This one question is not enough for the interview.
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (268 diagrams in all). A PDF you keep, junior to staff level.
Two courses by the author of this page:
770 lessons · 18 free to read
₹1,111 in India · $35 elsewhere, once
Get System DesignYou own this course
219 lessons · 10 free to read
₹1,333 in India · $35 elsewhere, once
Get Generative AI and Agentic AIYou own this course
Save your progress and get the interview checklist PDF
Businesses on Stripe moved $1.9 trillion in 2025 (Stripe annual letter, February 2026). At the 2025 Black Friday peak, Stripe handled more than 152,000 transactions a minute. That is about 2,500 every second. India's UPI handled 24.51 billion payments in August 2026, about 9,000 a second on average. At that scale, rare failures happen every minute. A timeout, a retry or a lost message can charge someone twice or lose money. The design exists to make that impossible.
A payment system takes money from a customer and gets it to a merchant. It never charges twice and never loses a cent. Speed is not the hard part. Correctness under failure is. The network can time out after the bank has already taken the money. A server can crash between two writes. A webhook can arrive twice, or out of order. So the design rests on a few ideas. Every request carries an idempotency key, so a retry is safe. Every money movement is written to a double-entry ledger, where debits and credits always add up to zero. A payment whose result is unknown stays pending. It is never marked failed by guesswork. Events are saved in the same transaction as the ledger write, so none are lost. Every day, the ledger is matched against the payment provider and the bank. Stripe, Razorpay, UPI and PayPal all follow this pattern on different rails.
Where it shows up
A standard question at payments companies such as Stripe, PayPal, Adyen, Razorpay and PhonePe. It also comes up at any company that takes money online. Think of e-commerce, ride-hailing, food delivery and subscription apps. It appears in other forms too. Design a payment gateway. Design a wallet. Design a checkout that never double charges.
Spec sheeta Payment System
worked through below, with the maths
The hard parts of this design are taught step by step in the System Design course: Idempotency, Idempotency Keys and ACID Properties.
Why some operations are safe to retry and others charge you twice, and how to make everything safe.
Safely retry failed API requests without causing duplicate side effects.
Database transaction guarantees that keep your data correct.
Guarantee that your database write and message publish either both happen or neither does.
all part of
System Design Masterclass
770 lessons · about 290 hours · 18 free to read
₹1,111in India, by UPI
$35everywhere else, by card or PayPal
You own this course
Continue with Idempotencypay once,
yours for life
Every payment system rests on the same few ideas: an idempotency key so a retry never charges twice, a double-entry ledger so no money appears or vanishes, and daily reconciliation against the bank. These guides show those ideas inside real products.
Lessons these guides rest on
Terms in one paragraph
Live from the course bench
Real interview questions, live diagrams and measured lab results, pulled at random from the lessons. A new set every time you come back.
Show your math. Pulling numbers from thin air signals you have not thought about the load.
Payments per day (interview example)
10 million
A good number to design for in an interview. It is large but not extreme. State it, then do the math from it.
Average and peak writes
~120 per sec, ~1,200 at peak
10 million divided by 86,400 seconds is about 116 a second. Sales and paydays can bring ten times that. This is an estimate.
Ledger rows per day
20 million or more
Each payment writes at least two postings: one debit and one credit. Fees, refunds and payouts add more. Estimate.
Ledger storage per year
~1.5 TB
20 million rows at about 200 bytes is about 4 GB a day. Times 365, that is about 1.5 TB a year. Estimate.
A real peak: Stripe, Black Friday 2025
152,000+ per minute
Stripe's own number for the 2025 Black Friday to Cyber Monday weekend. That is about 2,500 a second at peak.
A real average: UPI, August 2026
~9,000 per second
24.51 billion UPI payments in the month, from NPCI data. That is about 791 million a day.
Start with the main path of one payment. The merchant's checkout calls your Payment API with an idempotency key. The API gateway checks the merchant's key and applies rate limits. The Payment Service checks the idempotency store first. If it has seen this key, it returns the saved answer and does nothing else. If the key is new, it saves the payment as PENDING before calling anyone. Then a risk service scores the payment for fraud. Next, a PSP adapter sends the payment to the outside world. That means a card network, a bank, or UPI. The answer can be approved, declined, or no answer at all. On a clear answer, one database transaction does three things. It updates the payment's state. It writes balanced rows to the ledger. It adds an event to an outbox table. A relay process reads the outbox and publishes events to a queue. From the queue, other services send webhooks, update the merchant's balance view, and feed analytics. Off the main path, two jobs keep everything honest. A status checker asks the provider about payments stuck in PENDING. A daily reconciliation job matches the ledger against the provider's report and the bank statement. Card numbers never enter this path at all. They go straight to a separate vault, and every other service sees only a token.
In a real interview, sketch this on the whiteboard before diving into any single box.
This is one card payment, from the click to the money in the merchant's bank. UPI and wallets change the rails in steps 6 and 9. The rest stays the same.
The merchant's server creates a payment and sends a unique key with it, such as a random UUID. If the call times out, it retries with the same key.
The customer types the card into a field hosted by the payment provider. The card number goes to a secure vault. Your servers only see a token.
Seen this key before? Return the saved answer and stop. A new key? Save it in the same database as the payment, so the two cannot disagree.
Write the payment row before calling anyone outside. If the server crashes after this, the payment is still on record and a job can finish it.
A risk service looks at the card, the device, the amount and recent history. It returns allow, review or block in milliseconds.
The provider sends the request through the card network to the customer's bank. The bank approves or declines, and holds the money on approval.
One database transaction updates the payment, writes balanced ledger rows and adds an outbox event. Either all three are saved, or none are.
The payment is captured now or later, for example at shipping. A webhook tells the merchant. The merchant ships when the webhook arrives, not on the browser redirect.
Real money moves later, in batches. The card network settles with the provider, and the provider pays the merchant's bank on a schedule.
A job matches every ledger row against the provider's settlement report and the bank statement. Any mismatch becomes a ticket for a person to fix.
Walk through each service. The interviewer wants to hear what each one owns, not just the names.
The front door. It checks the merchant's API key, applies rate limits and validates the request. Every write call must carry an idempotency key.
Owns the life of one payment as a state machine. States are PENDING, AUTHORIZED, CAPTURED, FAILED and REFUNDED. Only allowed moves between states are accepted.
Remembers each key, a hash of the request, and the saved response. Keep it in the same database as the payments, so one transaction covers both.
Scores each payment before money moves. It uses rules and a model. One feature might be how often this card was used in the last hour.
One adapter per outside rail: a card processor, a bank, UPI. Each turns your request into that rail's format and turns its answer back into your states.
An append-only double-entry ledger. Every money movement is a set of rows that add up to zero. Balances are sums of rows, never a number you edit.
Reads new rows from the outbox table and publishes them to a queue such as Kafka. Webhooks, notifications and analytics all read from that queue.
Delivers events to the merchant's URL with a signature. It retries with growing waits. Receivers must expect duplicates and events out of order.
Finds payments stuck in PENDING and asks the provider for their real status. It moves each one to a final state. It never guesses.
Each day, it matches the ledger against the provider's settlement file and the bank statement. It flags missing, extra or different rows.
A small, locked-down service that stores card numbers and gives out tokens. Only it is in full PCI DSS scope. Everything else sees tokens.
payments. One row per payment. Amounts are whole numbers in the smallest unit, such as cents or paise, never floats. Shard by merchant_id.
Every table for a Payment System, its keys, and which store fits it and why.
Idempotency keys: the retry that must not charge twice. The client sends a payment. The server charges the card. Then the reply is lost on the network. The client sees a timeout and retries. Without protection, the customer…
9 deep dives on the parts that break at scale: Idempotency keys: the retry that must not charge twice; A timeout is not a failure: the unknown state; The double-entry ledger: money never appears or vanishes.
Idempotency keys in the payments database vs in Redis. Redis is fast, but it is a second system. A crash between the Redis write and the database write leaves them disagreeing. Keeping keys in the payments database lets one…
6 decisions an interviewer expects you to defend, each with the alternative and why it loses here.
A refund saga has written the reversing ledger entry, but the call to the provider to send the refund times out. What now?
4 follow-up questions with model answers, the interview scorecard for this question, and a mock interview on Design a Payment System with the AI tutor.
Stripe has published a lot about how it keeps payments correct. Its API docs explain idempotency keys in detail. Results are saved even for failed calls, and a key reused with different parameters is rejected. Its webhook docs say events are retried for up to three days and are not delivered in order. Stripe's Ledger, described in February 2024, is a double-entry system of record. It sees five billion events a day. Clearing accounts that should return to zero reveal missing or late transactions. Stripe's product applications use DocDB, a database service built on MongoDB Community. In June 2024, Stripe said DocDB serves over five million queries a second across more than 2,000 shards. For scale, Stripe reported $1.9 trillion in total volume for 2025. Over Black Friday to Cyber Monday 2025, it processed more than 578 million transactions. It peaked above 152,000 a minute, and API uptime was above 99.9999%. India's UPI shows the same pattern on public rails. NPCI's central switch routes each payment between two banks. A timeout leaves the payment pending until its real status is known. UPI handled 24.51 billion payments in August 2026.
Sources
If any of these topics are fuzzy, the interviewer will catch it. Each lesson is 15 to 60 minutes with diagrams, code, and a quiz.
Idempotency
foundation / core fundamentals
Idempotency Keys
intermediate / api design protocols
ACID Properties
foundation / core fundamentals
Transactional Outbox Pattern
intermediate / messaging event systems
Idempotent Consumer
intermediate / messaging event systems
Saga Pattern
advanced / distributed systems core
Two-Phase Commit
advanced / distributed systems core
Timeout Patterns
advanced / reliability resilience
Capstone: Design a Payment System
capstone / capstone
interview readiness
Three questions from this guide. Answer them without scrolling up, the way you would have to in the room.
Pay by UPI, cards or netbanking through Razorpay. Pay by card or PayPal, in US dollars. Download at once from My packs.
NEWSystem Design Hands-On
Postgres Sharding: Complete Hands-On (PgBouncer + Citus). 2 h 36 min and 20 chapters: one PostgreSQL loaded until it breaks, then four shards behind a router you write, PgBouncer and Citus, with the 139-page slide deck. The first 15 minutes are free to watch.
Free PDF · 79 pages
25 real tech interview questions, answered in full
Five from each of our AI, GenAI, Inference, Maths for ML and Forward Deployed packs. Each with a diagram and a model answer. Free by email.
free tool
Check these numbers yourself
Put in your own guesses for a Payment System and see requests per second, storage, bandwidth and servers, with every sum written out.
Open the Capacity EstimatorIt is really nice and good Please join the course