Skip to content

Idempotency: recap and quiz

  1. 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.
  2. 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.
  3. 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.
  4. 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.
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”
  1. Who can repeat it? The client, a proxy, a queue, an operator replaying messages. List them. (Duplicate requests)
  2. Is it idempotent by nature? If it sets a state, it is. If it adds to one, it is not. (Idempotency keys)
  3. Where does the key come from? The client, once per intent, kept until it has an answer.
  4. What happens if the same key arrives with a different request? Reject it.
  5. Are the key and the work saved together? One transaction, and a unique constraint for requests at the same moment.
  6. Does the queue deliver at least once? Then the consumer must expect duplicates. (Duplicate messages)
  7. How is an event published without being lost? An outbox, and a relay that can publish twice.
  8. 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)
  9. Did you run the failure? The duplicate-request lab shows the numbers.

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.

Question 1 of 6

The shop asks for 180 writes per second. The API waits 500 ms, a round trip takes 600 ms, and the API retries once.

How many writes per second does the primary do?

Enter a number and choose its unit.

Question 2 of 6

Which HTTP method is not idempotent by definition?

Choose one answer.

Question 3 of 6

A client reuses the key of an earlier charge of 25 for a new charge of 99.

What should the server do?

Choose one answer.

Question 4 of 6

Which statements about a transactional outbox are true?

Choose every answer that applies.

Question 5 of 6

Why does a service keep idempotency keys only for a window?

Choose one answer.

Question 6 of 6

In the duplicate-request lab you switch on the idempotency key.

What does the lab still show as reported failed?

Choose one answer.

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.