CURRICULUM PREVIEWRevision 1 · Open for reviewReview the full course
CONNECTING THE PIECES10 min read

Idempotency

Make a repeated request have one intended effect.

Before you begintransactional-outbox

The problem and the pattern

A caller retries a booking after losing the response. Accept an idempotency key scoped to the tenant and operation, store a request fingerprint and result, and use a unique constraint to arbitrate concurrent requests. Reusing a key for different input should produce a documented conflict.

Follow the flow

Make it concrete

This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.

Focused example
text
UNIQUE (tenant_id, operation, idempotency_key)

Key exists + matching fingerprint → replay saved result
Key exists + different fingerprint → conflict
New key → commit effect and saved result together

Trade-offs

  • Idempotency reduces duplicate effects but requires durable state.
  • Define key retention and response replay semantics.
  • Do not put sensitive payloads in plain idempotency keys.

When to avoid it

Avoid claiming a GET-like read cache is sufficient protection for a state-changing operation.

Your turn

Two identical requests with one key arrive simultaneously. Why is an in-memory dictionary insufficient across two app instances?

Reveal a worked answer

Each process has its own dictionary and both can create a booking. Enforce uniqueness and commit the operation record with the business write in PostgreSQL. Test concurrency and recovery after process restart.

Keep exploring

One more piece connected.

Mark this lesson complete when you can explain the idea.