Skip to slide
Chapter 13 · Reliability: Retries, Idempotency, and Failure Handling
123 / 191

CHAPTER 13 · Reliability: Retries, Idempotency, and Failure Handling · 4 / 12

Idempotency for actions with side effects

Retries are only safe if repeating an operation doesn't duplicate its effect. Design side-effecting operations to be idempotent: safe to run more than once with the same result:

  • Use deterministic keys / upserts. "Create or update by this key" instead of "insert," so a retried create doesn't make duplicates.
  • Make processing steps re-runnable. A reprocessed document shouldn't spawn duplicate versions or orphaned files; check-then-act, or key derived work so re-running converges.
  • Guard at natural unique constraints. Let the database reject a duplicate (unique constraint) rather than relying solely on application checks.

Idempotency is what turns "retrying might double-charge / double-create" into "retrying is safe," which is what makes retries usable at all.

← → arrow keys work too