Card 03/ 07
Heuristics Example: A Flash Sale Checkout
A spike of writes, a payment provider that times out, and clients that retry.
The same reading, pressure then heuristic then pattern, works on a brief that looks nothing like a news site. This example reads a flash sale checkout, which is about writes, failures and retries rather than reads, and arrives at different patterns by the same steps.
The brief. A shop sells 5,000 discounted sneakers at noon. For ten minutes, checkout traffic is fifty times normal. Payments go through a third-party provider that sometimes takes 30 seconds and times out. Shoppers' apps retry a checkout that times out. No pair may be sold twice, and no shopper charged twice.
| Pressure in the brief | Heuristic | Pattern |
|---|---|---|
| Fifty times normal orders in ten minutes | A spike of writes | A queue in front of order processing |
| Bots and refreshing shoppers hammering checkout | Requests past the limit | Rate limiting at the edge |
| A spike at a known time, in seconds | Load that rises faster than servers start | Scale ahead on a schedule |
| Apps retry, and the provider is slow | Retries and safety | An idempotency key on every order and payment |
| Exactly 5,000 pairs | Correctness of stock | Stock counted in a relational database transaction |
The design that results. Rate limiting at the edge turns away excess requests. Servers, scaled ahead of noon, accept each order, reserve a pair in one database transaction, put a payment job on a queue, and reply "order received". Workers take the payments at the pace the provider can handle, each with the order's idempotency key, so a retry never charges twice.
What it shares with the news site. The method, and almost nothing else. There, the pressures were reads and distance, and the answers were at the edge and in the cache. Here, they are writes, failures and retries, and the answers are a queue, limits and keys. A CDN does nothing for the payment call; a cache does nothing for stock that must be exact.
So the reading transfers even when the patterns do not: find the pressures first, and let them choose the parts.
← → move through sections and cards