5,998 of 6,000 items paid for, none recorded twice
The same flash sale as the replay, this time all the way to payment. Some buyers pay, some decline, some just walk away. The payment provider is a fake, built to misbehave: notifications arrive twice, forged, or late.
Every bill settled
Every bill is settled: 5,998 paid, 1,115 cancelled, none left hanging. 2 items came back after buyers stopped arriving.
- created
- paid
- cancelled
Duplicate and forged notifications change nothing
The payment provider tells the shop through notifications. The shop trusts only notifications with a valid signature, and a bill can change status only once. A payment that arrives after the bill was cancelled is logged as a conflict, so the money can be refunded.
What buyers saw and what the shop recorded match exactly
The fake buyers (k6) log what happened to them. The shop logs what happened in Redis. Each is counted on its own, and both end on the same numbers.
Buyers (k6)
- Paid
- 5,998
- Declined
- 366
- Walked away
- 749
Shop (Redis)
- Paid
- 5,998
- Cancelled
- 1,115
- Still open
- 0
Books (Postgres)
- Bills stored
- 7,113
When every payment lands in one account
In a one-item flash sale, every payment is booked to the same revenue account. We measured 20,000 transfers from 32 concurrent writers in three ways. In every run, debits and credits balanced.
transfers a second
For this shop Postgres is enough: at the busiest second of the recording, only 214 payments cleared.
Show the technical side
One bill, step by step
- Buying only holds the item. The order waits with a 30-second due time.
- The API creates one Snap transaction per order at the provider (guarded by a Redis key), and the shop opens its payment page.
- Notifications are checked by their SHA-512
signature_keywith a constant-time compare, and theirgross_amountmust match. - Every status change is a single Lua script: only from waiting, only once. A cancel returns the stock. A payment that lands after a cancel is flagged as a conflict for a refund instead of selling the stock again.
- A sweeper runs every second for bills past due plus a 5-second grace: it asks the provider, cancels there first, and only then returns the stock.
- A worker writes every change to Postgres, including double-entry journal lines in the ledger.
Failures injected on purpose
- Duplicate notifications
- 10%
- Paid copies with a bad signature
- 5%
- Pending arriving after the final statusrandom delay up to 1,500 ms
- 10%
- Buyers who pay5% decline, the rest leave
- 85%
Other numbers
- From buying to the shop knowing it was paid: median 4.3 s, p95 6.4 s, including the 1 to 5 seconds k6 buyers take to pay.
- Peak load 3,318 requests a second, because buyers check their bill every second and notifications come in too.
- 395 k6 buyers ended with an unknown ticket: they were still queuing when stock briefly ran out, then stock came back from cancelled bills. The shop shows “your number is no longer valid” and offers a new one.
Per second
| Second | created | paid | cancelled |
|---|---|---|---|
| 1 | 0 | 0 | 0 |
| 11 | 0 | 0 | 0 |
| 21 | 222 | 177 | 9 |
| 31 | 224 | 155 | 9 |
| 41 | 216 | 193 | 12 |
| 51 | 12 | 27 | 22 |
| 61 | 36 | 22 | 27 |
| 71 | 14 | 11 | 26 |
| 81 | 1 | 2 | 1 |
| 91 | 1 | 1 | 2 |
| 101 | 1 | 1 | 3 |
| 111 | 2 | 0 | 0 |
| 121 | 0 | 0 | 0 |
| 131 | 0 | 0 | 0 |