Key points of this lesson, in order.
Idempotency and Duplicate Prevention
What you will learn
Your objective. By the end of this lesson, you will be able to explain idempotency and duplicate prevention. Duplicates happen because payments move across networks where a sender cannot always tell whether the first attempt succeeded.
Why it matters. This matters because operations is where payments are reconciled, investigated and fixed. The work in this lesson is what keeps the money right.
Chapter objective: How payments are tracked, recovered and controlled in operations
Key learning points
- Duplicate payment causes
- Without a duplicate control
- Corporate system
- Idempotency key retention
- System marks the second copy
Key terms
Idempotency: The property that repeating the same request has the same effect as sending it once. In payments, an idempotency key lets a client safely retry a request after a timeout without creating a duplicate...
Settlement: The final movement of funds between banks to discharge obligations created by cleared payments. Settlement is usually made in central bank money or through correspondent accounts.
Retry: Repeating a failed request or message delivery after a delay, usually with a limit on attempts and a back off period.
Banking architecture diagram showing Idempotency and Duplicate Prevention.
Insights and practice scenarios
Worked insights and practice scenarios for this lesson. Each one is a reusable PaymentForge case, so the same case may appear in more than one lesson.
Practise this lesson
Exercise
Write the request and the expected response for the API call described in this lesson.
Use the API resources, operations and fields named in this lesson.
- What to do. Write the JSON request with the required fields, the success response, and one error response with its error code.
Correct result. A correct request has all mandatory fields, a valid idempotency key, and the right resource and operation. The success response confirms acceptance, and the error response names the field or rule that failed.
Why. An API contract is a promise between two systems. If the request is wrong, the API must reject it cleanly, not fail silently.
Check your understanding
Practice question
Which of the following best describes idempotency and duplicate prevention?
Takeaway and next step
What to remember
Duplicates happen because payments move across networks where a sender cannot always tell whether the first attempt succeeded.
Reconcile the payment in this lesson against its statement and find the break.
Open the Accounting and Reconciliation Lab →
Builds on "Payment State Machines and Correlation".
Transcript and full text
Show transcript
Duplicates happen because payments move across networks where a sender cannot always tell whether the first attempt succeeded. A customer system times out while waiting for an acknowledgement and sends the instruction again, a user double clicks a submit button, or a batch job resends a file after a partial failure. Each of these is normal behaviour in a distributed system, so the payment platform must expect duplicates rather than assume they will never happen. In the worked example, the London corporate system sends the USD 120,000 instruction to Meridian Bank, waits thirty seconds for an acknowledgement, receives nothing because of a network delay, and sends the same instruction again. Without a duplicate control, the bank would process two payments of USD 120,000 for one invoice. An idempotency key is a unique value the sender attaches to an instruction, and the receiving system stores that key with the result of the first processing. When the same key arrives a second time, the system returns the stored result instead of processing the payment again, so the sender gets a successful answer and no second payment is created. The key must be unique per instruction, stable across retries, and stored in a place that survives a system restart, because a key lost in a crash cannot protect anything. In the worked example, the corporate system sends the USD 120,000 instruction with key INV-2026-5521-01, Meridian Bank stores the key with the accepted result, and the retry with the same key receives the same accepted result without a second debit. Testing this control means sending the same key twice and confirming one debit, one payment, and two identical responses. A dedupe window is the period during which the system remembers a key and treats a repeat as a duplicate, and the length of the window is a business decision with real risk. A window that is too short lets a late retry through as a new payment, while a window that is too long stores keys forever and slows the system down. Most banks keep keys for days rather than minutes, covering the life of the payment plus the period in which a retry is plausible. In the worked example, Meridian Bank keeps idempotency keys for seven days, so a retry that arrives the next morning is still recognised as a duplicate. Testing the window means sending a duplicate just inside it and confirming it is blocked, and sending the same instruction after it has expired and confirming the system treats it as new. When the same payment arrives twice despite the controls, operations must decide which copy is the real payment and which copy is the duplicate, and that decision must be recorded. The system marks the second copy as a duplicate, links it to the first payment, and sends the sender the original result so the sender knows the payment is already in progress. The duplicate never reaches the ledger, never reserves funds, and never creates a settlement instruction, so the customer account is debited only once. In the worked example, Harbour Bank receives the USD 120,000 payment twice after the correspondent retry, accepts the first copy, marks the second as a duplicate, and returns the original acceptance for both. Testing this path means checking the duplicate record, confirming one debit, and confirming the sender receives the same result for both attempts.
Duplicates happen because payments move across networks where a sender cannot always tell whether the first attempt succeeded. A customer system times out while waiting for an acknowledgement and sends the instruction again, a user double clicks a submit button, or a batch job resends a file after a partial failure. Each of these is normal behaviour in a distributed system, so the payment platform must expect duplicates rather than assume they will never happen. In the worked example, the London corporate system sends the USD 120,000 instruction to Meridian Bank, waits thirty seconds for an acknowledgement, receives nothing because of a network delay, and sends the same instruction again. Without a duplicate control, the bank would process two payments of USD 120,000 for one invoice.
An idempotency key is a unique value the sender attaches to an instruction, and the receiving system stores that key with the result of the first processing. When the same key arrives a second time, the system returns the stored result instead of processing the payment again, so the sender gets a successful answer and no second payment is created. The key must be unique per instruction, stable across retries, and stored in a place that survives a system restart, because a key lost in a crash cannot protect anything. In the worked example, the corporate system sends the USD 120,000 instruction with key INV-2026-5521-01, Meridian Bank stores the key with the accepted result, and the retry with the same key receives the same accepted result without a second debit. Testing this control means sending the same key twice and confirming one debit, one payment, and two identical responses.
A dedupe window is the period during which the system remembers a key and treats a repeat as a duplicate, and the length of the window is a business decision with real risk. A window that is too short lets a late retry through as a new payment, while a window that is too long stores keys forever and slows the system down. Most banks keep keys for days rather than minutes, covering the life of the payment plus the period in which a retry is plausible. In the worked example, Meridian Bank keeps idempotency keys for seven days, so a retry that arrives the next morning is still recognised as a duplicate. Testing the window means sending a duplicate just inside it and confirming it is blocked, and sending the same instruction after it has expired and confirming the system treats it as new.
When the same payment arrives twice despite the controls, operations must decide which copy is the real payment and which copy is the duplicate, and that decision must be recorded. The system marks the second copy as a duplicate, links it to the first payment, and sends the sender the original result so the sender knows the payment is already in progress. The duplicate never reaches the ledger, never reserves funds, and never creates a settlement instruction, so the customer account is debited only once. In the worked example, Harbour Bank receives the USD 120,000 payment twice after the correspondent retry, accepts the first copy, marks the second as a duplicate, and returns the original acceptance for both. Testing this path means checking the duplicate record, confirming one debit, and confirming the sender receives the same result for both attempts.
Full lesson text (all scenes)
Completing a lesson updates your progress dashboard on the homepage.
Scene timestamps are estimated by allocating the narration text proportionally across the real audio length. The audio playback position is the source of truth: pause freezes the visual, seeking restores the correct scene, replay restarts the scene animation.