Skip to content
Inside Ledgerly

Engineering

Idempotency keys, explained with a coffee order

Why every write to Ledgerly takes a key, what we do when the same key arrives twice, and how long we remember.

Daniel Osei16 October 2026 · 7 min read

You order a flat white, the card machine hangs, and you are not sure it went through. Pay again and you might pay twice. An idempotency key is the receipt number you can show the barista: if this order has already been made, make it no more.

The rule

Every write to Ledgerly carries a key the caller chooses. The first request with that key does the work and we store its answer. Any later request with the same key gets the same answer back, without doing the work again.

post.sh
curl https://api.ledgerly.example/v1/transactions \  -H "Idempotency-Key: order-58213-capture" \  -d amount=12000 -d currency=gbp

Under load

Two requests with the same key can arrive in the same millisecond. The first takes a lock on the key; the second waits for the answer instead of starting the work. It is the same fixed-order locking we use for balances, applied to keys.

    Try "balances", "reconcile" or "idempotency".

    Talk to an engineer

    Thirty minutes with someone who builds the ledger, about how your money moves. No slides.

    Inside Ledgerly