Idempotency: recap and quiz
The module in four sentences
Section titled “The module in four sentences”- Duplicate requests. A timeout does not say the work was not done, so a retry can do it twice, and each fix for it has a price.
- Idempotency keys. A key chosen by the client lets the server do an operation once and replay the saved answer, if it compares the request and saves the key with the work.
- Duplicate messages. A queue that cannot tell whether the work was done delivers the message again, and an outbox avoids lost events by allowing duplicates.
- Deduplication windows and idempotent consumers. Keys are only kept for a window, so the consumer itself must be safe, by being idempotent by nature or by recording ids with its effect.
How each one breaks
Section titled “How each one breaks”| Idea | What breaks | What you see | What helps |
|---|---|---|---|
| Retry | The answer is late but the work was done | The work done twice and a false failure reported | A key, and a timeout above the real latency |
| Key | A new key per attempt, or key and work saved apart | No protection, or work lost or repeated after a crash | One key per intent, saved in the same transaction as the work |
| Queue | An acknowledgement is lost | The message arrives again | An idempotent consumer |
| Window | A duplicate arrives after the key was forgotten | The work done again, as new | Idempotence by nature, or ids kept as long as a duplicate can take |
A checklist for an operation that may be repeated
Section titled “A checklist for an operation that may be repeated”- Who can repeat it? The client, a proxy, a queue, an operator replaying messages. List them. (Duplicate requests)
- Is it idempotent by nature? If it sets a state, it is. If it adds to one, it is not. (Idempotency keys)
- Where does the key come from? The client, once per intent, kept until it has an answer.
- What happens if the same key arrives with a different request? Reject it.
- Are the key and the work saved together? One transaction, and a unique constraint for requests at the same moment.
- Does the queue deliver at least once? Then the consumer must expect duplicates. (Duplicate messages)
- How is an event published without being lost? An outbox, and a relay that can publish twice.
- How late can a duplicate arrive, and how long are keys kept? The window must cover it, or the consumer must not depend on it. (Deduplication windows)
- Did you run the failure? The duplicate-request lab shows the numbers.
Check your understanding
Section titled “Check your understanding”Six questions cover the whole module. Every option is explained, whether it is right or wrong.
Idempotency: module quiz
This quiz needs JavaScript to check your answers.
Where this goes next
Section titled “Where this goes next”This module handled the doubt that a retry creates. The next modules on reliability cover when to retry, how long to wait and when to stop, and what a retry costs a struggling service. Idempotency is what makes those retries safe to attempt.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.