All koans

Which press paid?

The student pressed Pay three times. The master was charged once. Which press paid?

Charged: $0

Press Pay a few times. Then turn on the slow network, so the app thinks the first try failed and sends it again. Then turn off the ticket number and do it all again.

See the answer Hide the answer

The answer

Idempotency keys

When you pay online, the app sends a message to the bank and waits for an answer. Sometimes the answer gets lost on the way back. Did the payment go through? The app can’t know, so it asks again. Without care, asking again means paying again.

An idempotency key is a ticket number for one intention. The app writes it on every message about that order. The bank keeps a list of numbers it has already handled. A second message with the same number gets the same answer as the first, and no new charge.

So which press paid? The first one to arrive. The others were the same wish, asked again.