Available for consulting: payments, backend performance and platform engineering.Book a call
Saravana Thiyagarajan · The Backend Guy
Book a call
Handbook · Payment System Design

The Payment Systems Engineering Handbook

How to build payment systems that stay correct through retries, duplicate events, timeouts, crashes and provider outages, written from the parts of the job you only meet in production.

8 parts · 21 chaptersComplete: all 8 partsUpdated 24 Nov 2026

Payment systems fail in ways most backend systems don't. A retried request can charge a customer twice. A webhook can arrive after you've given up on a payment. A queue can hand the same message to two workers. A database commit can succeed while the message that announces it is lost. None of this is exotic; on any system with real traffic it happens every week.

This handbook is about building payment infrastructure that stays financially correct anyway. It starts from what a payment is and works up to a complete, event-driven architecture, covering ledgers, idempotency, locking, queues, outboxes, retries, observability and reconciliation along the way. The chapters have diagrams you can watch draw themselves, and code in Go, Python and PostgreSQL.

Three principles

The three principles of payment system designThree boxes: never move money twice; never lose track of money; never blindly trust a component. 1Never movemoney twiceidempotency · state machines2Never losetrack of moneyledgers · reconciliation3Never blindlytrust a componentconstraints · verification
Every chapter comes back to these three rules. When a design decision is hard, ask which of the three it protects, and what happens to the other two.
  1. Never move money twice. Any operation that moves or records money has to be safe to repeat, because in a distributed system everything gets repeated sooner or later.
  2. Never lose track of money. You should be able to explain every balance from an immutable record of what happened. A number you can't explain is a number you can't trust.
  3. Never blindly trust any component. Not the provider, not the network, not the queue, not your own database. Any of them can be late, wrong or duplicated, so we verify, constrain and reconcile.

Who it is for

  • Graduates and engineers new to fintech who want to understand what happens behind the “Pay” button.
  • Backend engineers building wallets, payment gateway integrations, banking integrations or financial platforms.
  • Senior engineers designing event-driven systems who want a reference for idempotency, outboxes, retries and recovery.
  • Engineering leads weighing trade-offs, who want to know what can go wrong before it does.

The major chapters follow the same path. Each describes the problem in plain words and why it happens, shows what the obvious implementation gets wrong, and gives a better mental model, with a diagram, working code, the trade-offs, common mistakes and a checklist for production.

Contents

The handbook is complete: all eight parts are out.

Part 1 · read nowUnderstanding Payment SystemsWhat actually happens when someone pays, and how to model it as a state machine you can trust.
  1. Why processing payments is harder than it looks
  2. Designing a payment lifecycle
Part 2 · read nowFinancial Data CorrectnessRepresenting money without rounding bugs, building an immutable ledger, and enforcing financial invariants.
  1. Representing money and financial values
  2. Building an immutable financial ledger
  3. Transaction consistency and financial invariants
Part 3 · read nowIdempotency and ConcurrencyChoosing idempotency keys, atomic deduplication, row locks, compare-and-swap, and where Redis locks fit.
  1. Idempotency: the most important property of payment processing
  2. Database locks, compare-and-swap and concurrency control
  3. Why Redis is not always the answer for distributed locking
Part 4 · read nowEvent-Driven Payment ArchitectureSNS and SQS payment pipelines, visibility timeouts, and reliable transactional outbox and inbox patterns.
  1. Building an event-driven payment engine
  2. Understanding SQS visibility timeout and worker concurrency
  3. Designing reliable transactional outbox and inbox patterns
Part 5 · read nowWorkflow Design and Database PerformanceResumable workflows, connection pools, short transactions and PostgreSQL query performance.
  1. Designing resumable payment workflows
  2. Database connections, connection pooling and short transactions
  3. Database query optimisation and scaling
Part 6 · read nowResilience and Failure RecoveryRetries, exponential backoff with jitter, recovery storms, and compensating for failures safely.
  1. Retry strategies, exponential backoff and recovery storms
  2. Failure handling and compensation
Part 7 · read nowObservability and Production EngineeringStructured logs, tracing, metrics that matter, profiling Go services, and reconciliation as the final safety net.
  1. Structured logging and distributed tracing
  2. Metrics, monitoring and alerting
  3. Profiling and performance engineering
  4. Reconciliation: the final safety net
Part 8 · read nowPutting It All TogetherOne end-to-end payment architecture, walked through for payments, withdrawals, duplicates and cancellations.
  1. End-to-end payment architecture

About the author

Portrait of Saravana Thiyagarajan

Saravana Thiyagarajan · The Backend Guy

I'm a backend engineer in Bengaluru. Most of my recent work has been payment and ledger systems in Go, Python and PostgreSQL on AWS, the kind of system where a duplicate message can mean a customer gets paid twice. This handbook is what I wish I'd had when I started, with the reasoning behind each pattern written down next to it.

If you're building something like this and want a second pair of eyes, see my payments and backend consulting.

Frequently asked questions

What is payment system design?

It is the work of designing software that moves money and records it correctly: how payments are modelled, how they are stored, how the system talks to payment providers and banks, and how it behaves when any of those parts fail or answer twice. The goal is easy to say and hard to meet: never move money twice, and never lose track of it.

What is idempotency in payment processing?

An operation is idempotent if doing it twice has the same effect as doing it once. In payments it means a retried request, or a webhook delivered twice, cannot charge or credit anyone a second time. The usual way to build it is a unique key per operation plus a database constraint that rejects the duplicate.

Does a timeout mean a payment failed?

No. A timeout only means you stopped waiting. The provider may never have received the request, may have declined it, or may have charged the customer and lost the response. Treat it as an unknown state and find out the real result by checking the payment status, waiting for the webhook, or reconciling.

Why shouldn't money be stored as floating-point numbers?

Binary floating-point numbers cannot represent most decimal fractions exactly, so a sum like 0.1 + 0.2 comes out slightly wrong, and across many transactions the errors add up. Store money as integers in minor units (such as cents) or as fixed-precision decimals, and round only at defined points with a written rule.

Does an SQS visibility timeout guarantee a message is processed only once?

No. The visibility timeout hides a message from other consumers for a while after one consumer receives it, but if processing takes longer than the timeout, or the message is not deleted, it can be received again. Standard SQS queues deliver at least once, so correctness has to come from idempotent processing and database constraints.

Is a Redis lock enough to stop double payments?

Not on its own. A Redis lock is a lease that can expire while the holder is still working, for example during a long pause or a network problem, and then a second worker can take it. Locks are fine for coordination, but the database should enforce the rule that money moves only once, with unique constraints and conditional updates.

Who is this handbook for?

Backend engineers new to fintech, graduates who want to understand how real payment systems work, engineers building wallets, payment gateways or banking integrations, and senior engineers and leads who want a reference for the trade-offs. It begins with first principles and finishes with a complete architecture.

If this was useful

If you know someone building or fixing a payment system, send it their way, or share it with your network. The handbook is free, and people passing it on is how it reaches the engineers it was written for.

I post new writing on LinkedIn and X.

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.