Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Atomic intent and duplicate delivery with the outbox pattern

Examine double-write issues, transaction outboxes, duplicate deliveries, and recovery scans.

Learning objectives: The same transaction submits the task and the intention to be delivered, eliminating the double-write window of "task exists but notification is permanently lost"; actual delivery may still be repeated, and consumers must independently ensure that business processing can be reentrant.

Content checked: 2026-10-03 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Design · Explain the trade-offs. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Junior/mid-level AI application candidates with Python and backend fundamentals.

Atomic intent and duplicate delivery with the outbox pattern
The same transaction submits the task and the intention to be delivered, eliminating the double-write window of "task exists but notification is permanently lost"; actual delivery may still be repeated, and consumers must independently ensure that business processing can be reentrant.

How does the mechanism work?

Step-by-step explanation
  1. What happens if the sending succeeds but the tag fails?

    Move from atomically committing intent to the second failure window: external delivery.

  2. Does the message ACK mean the business is successful?

    Distinguish between transport-level success and task-level success.

  3. How to avoid deleting undelivered events when cleaning Outbox?

    A reliable delivery chain also needs a retention and cleanup lifecycle.

Design · Explain the trade-offs

Design · Parallel claims, retention and external actions

Objectives of this level: Specify safe changes beyond a single local dispatcher and deliver a cleanup decision function with explicit nondeletion controls.

Visual guide · Atomic intent, repeatable delivery

Atomic intent, repeatable delivery

Sender and consumer have separate local transactions. Duplicate delivery may occur; durable handoff acknowledgement does not prove tool or business completion. Select the figure to open it at full size.

Changed constraints

Design for two dispatchers, a 7-day replay window, 24-hour diagnostic retention after confirmed delivery, and a remote write API that can time out after accepting a request. These are exercise constraints, not implemented features of the standalone lab or capstone. Do not confuse a broker duplicate window with the consumer’s required replay retention.

Derive the next architecture

  1. Atomically claim a batch with owner/lease and guarded state transitions, or use a database mechanism appropriate to the deployment. Recover expired claims. A stale dispatcher cannot mark a newer claim complete. Concurrent delivery can still duplicate after a transport uncertainty; retain consumer idempotency.
  2. Preserve stable event ID and payload/revision on replay. A new random ID can make the consumer treat a repair as a new event. If different revisions arrive out of order, define skip-old or gap-recovery behavior for that business object.
  3. Monitor oldest pending age, attempts, stranded run/event discrepancies and dead letters. Retry transient transport failures with bounds/backoff; authorization or malformed-event errors require diagnosis. A scanner without capacity or a repeatedly failing oldest event does not establish eventual progress.
  4. Keep processed-event evidence for the stated replay period or preserve an equivalent durable business identity. Retaining outbox diagnostics for only 24 hours does not justify forgetting consumer dedup at 24 hours when replay can occur for 7 days. Never clean pending or unknown outcomes by creation age alone.
  5. For remote writes, durable handoff is only the start. Persist an operation intent, use target-supported idempotency/receipt lookup and bind results. If the target cannot provide these guarantees, keep unknown and require reconciliation; storing processed before the call can lose an action, and storing it after can repeat one.

Independent cleanup function

Implement cleanup_ids(rows, now, diagnostic_retention) for this controlled sender-diagnostic policy. Input now=200 and retention=50; rows are a(delivered=true, delivered_at=100, outcome="known"), b(false, null, "known"), c(true,180,"known"), d(true,100,"unknown"), e(true,null,"known"). Expected deletion IDs are ["a"] only. Eligibility requires delivered=true, a known delivered_at, outcome="known" and now-delivered_at >= diagnostic_retention. A delivered row without a confirmed delivery time, an unknown outcome or a pending row is retained. Reject negative retention. A second input changes a.delivered_at to 180 and b to delivered=true/delivered_at=100; it must return ["b"]. This function only chooses sender diagnostic records; it does not decide removal of consumer processed IDs or remote business audit evidence.

Submit code/assertions and a design note with a two-dispatcher race, 7-day replay after diagnostics cleanup, and remote timeout timeline. State which claims/queue/dead-letter/receipt mechanisms still need implementation. You should be able to explain the producer and consumer transactions and defend the experiment’s limits in an interview without calling it enterprise certification.

code example

Retries need an unchanged business identity

A compensating scan may resend an existing event, but creating a fresh event or operation key can bypass deduplication. Audit scans identify discrepancies; the chosen repair must preserve the established task/event/operation contract.

Acceptance task for this level

Implement cleanup_ids for the exact five-row fixture and negative-retention case; design the parallel-claim, replay-retention and remote-unknown policies with three failure timelines.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

If sender diagnostics are deleted at 24 hours, can consumer processed IDs also be deleted then?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.