← Lessons

quiz vs the machine

Gold1450

System Design

Idempotency keys

How to make retries safe so a double-click can't double-charge.

5 min read · core · beat Gold to climb

The problem

Networks are unreliable. A client sends "create payment", the server processes it, but the response is lost. The client retries — and now you've charged twice.

The fix: idempotency keys

The client generates a unique key per logical operation and sends it with every retry. The server records the key the first time it commits, and on any retry with the same key, it returns the stored result instead of re-executing.

Key idea

The uniqueness constraint on the key is what makes it safe — the database enforces "process this exactly once" even under concurrent retries.

Practice this →

Check yourself

Answer to earn rating on the learn ladder.

1. Who generates the idempotency key?

2. What actually enforces exactly-once under concurrent retries?