LESSON 14 / 15·2 min readAdvanced

What are idempotency and the outbox pattern?

01 Understand02 Recall03 Prepare

Understand the concept

Idempotency makes repeated requests for one logical operation produce one intended effect. The outbox pattern stores an event record in the same database transaction as the business change, allowing a later publisher to send it reliably. These solve related but different failure windows: duplicate work and losing the message between a commit and publication.

Important ideas

  • Idempotency makes repeated processing have one intended effect; enforce keys atomically.

  • Outbox: save business changes and an event record in one database transaction.

  • A publisher sends stored events later; consumers still need duplicate handling.

  • Store a unique operation key and result atomically, and reject reuse of a key for a different request payload.

Outbox flow:

  1. Start a database transaction.
  2. Save the business change and an outbox row with a stable event ID.
  3. Commit both together.
  4. A publisher reads unsent outbox rows and sends the events.
  5. Mark publication progress; a crash before this step can cause redelivery.
  6. A consumer uses the event ID or an idempotent operation to avoid duplicate effects.
PAUSE & RECALL

Can you explain it without the notes?

What are idempotency and the outbox pattern?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Idempotency makes repeated requests for one logical operation produce one intended effect. The outbox pattern stores an event record in the same database transaction as the business change, allowing a later publisher to send it reliably. These solve related but different failure windows: duplicate work and losing the message between a commit and publication.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • The outbox publisher can resend after a crash, so consumers still need deduplication or idempotent state changes.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: How do I handle partial failure across services?

Adapted from 07_SYSTEM_DESIGN_ARCHITECTURE.md · “What are idempotency and the outbox pattern?”. Examples are study fragments; framework behavior can depend on your version.