Data and Distributed Systems · 16 min · free with an account

Idempotency and Retries

Lesson preview · about 30%

A retry is only safe if the operation is idempotent.

Core idea

At-least-once delivery plus an idempotency key gives effectively-once behaviour.

Start with the idea

Retries and lost responses can cause the same logical request to reach a server more than once. Reads and overwrites are naturally idempotent; increments, appends, and charges are not. The fix is an idempotency key the server records with the result, so a repeat returns the first outcome instead of doing the work again. Retries also need jitter, or they synchronise into a thundering herd.

A retry may repeat an operation when the caller cannot tell whether the first attempt succeeded. A timeout is ambiguous: the server might have committed the change and lost the response. Idempotency means repeating the same logical request has the same intended effect as performing it once.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep