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.