Chapter Twenty-Four · Problem Eighteen

Payment System

An outside party holds half the truth: one charge through a processor that can go silent, a ledger that explains every balance, and a daily file that says what really moved.

4 lessons · 45 minutes
The Question

"Design the payment backend for an online marketplace: charge buyers through a card processor and pay out sellers."

Your system can do everything right here and still not know whether a buyer paid. The card processor sits outside every transaction you hold, and when a call to it goes silent, the money may or may not have moved. Throughput barely matters in this problem. What matters is what you do in that silence, and how you prove afterwards where the money went.

It draws on three earlier chapters. Chapter 5's Transactions Across Partitions gives you the saga, the orchestrator and the outbox, and it names payments as its case. Chapter 6's Delivery Semantics at Scale and Failure Across Many Services give you exactly once as an effect, and what a slow dependency does to its callers. Chapter 4's Consistency Models That Come Up gives you the words for a total that may lag. Backend Deep Dive built one service's client side: the timeout as an unknown, the idempotency key, the provider call, the webhook and the nightly job. This chapter names those and moves on, because it is the platform around them: the ledger, the payouts, and many services.

The round is pitched at senior, and since nothing here is a throughput problem, it is judged on how you reason about failure. Expect three hard parts. The first is one effect through an unreliable processor: a key that holds end to end, and an unknown outcome after a timeout. The second is the ledger, double-entry and append-only, with balances derived from it. The third is reconciliation against the processor's settlement files, its daily lists of what really moved, which are the source of truth for money.

The neighbours show what is special here. In Chapter 15's notification system, a duplicate is a second message. Here it is a second charge, and you may not know it happened. Chapter 23's hotel left a timed-out card call and a late refund for this chapter, and both get an owner in Scaling It. In Chapter 25's wallet, both sides of every transfer are yours, so nothing stays unknown once your own decision is recorded.

Start a 45-minute timer and sketch your own design before you open Scope. When your sketch reaches the processor, draw what happens if no answer comes back. Ten minutes go to Scope, ten to First Design, ten to Scaling It, and the last fifteen to deep dives and curveballs.

The 45 minutes of this problem, lesson by lesson
Scopeminutes 0-10
→
First Designminutes 10-20
→
Scaling Itminutes 20-30
→
Deep Divesminutes 30-45

Lessons in This Chapter