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
- What happens if the sending succeeds but the tag fails?
Move from atomically committing intent to the second failure window: external delivery.
- Does the message ACK mean the business is successful?
Distinguish between transport-level success and task-level success.
- How to avoid deleting undelivered events when cleaning Outbox?
A reliable delivery chain also needs a retention and cleanup lifecycle.
Foundation · Understand the concepts
Understand the principle · Three commits, three meanings
Objectives of this level: Derive atomic intent, transport retry and consumer handoff independently; do not infer remote business success from local acknowledgments.
Visual guide · 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.
Fixed task and failure windows
Submit run r1 with status queued and event r1:created:1, type run.created, payload_version 1. The event requests durable acceptance of this logical run; it does not request an already-approved refund. Sender task/outbox rows share one SQLite database, and consumer processed/handoff rows share another. The two databases are separate transaction domains.
Consider these observations:
- Failure before sender transaction commit: neither the run nor event should remain. A run row without its event is an orphaned intent.
- Sender commits and stops before delivery: one queued run and one pending event remain. A scanner can find that committed event after restart.
- Consumer commits its processed ID and accepted handoff, but the sender stops before marking delivery: consumer has one handoff, sender still has a pending event.
- Sender repeats the same event: consumer recognizes its stable event ID and identical payload, returns duplicate, and keeps one handoff. Sender may now mark delivery.
- Consumer acknowledgment exists, but there is no remote tool receipt: only durable handoff is established. It cannot prove the whole Agent run or a business action completed.
Why one transaction solves only the first gap
Writing the task then notifying a queue has a crash gap; notifying first can expose a nonexistent or rolled-back task. Commit the task and pending event together, then deliver outside that transaction. This guarantees recoverable local intent under the database’s durability contract, not eventual progress if no scanner ever runs.
Sending and marking cannot be one transaction across independent systems. If marking fails after acceptance, redelivery is expected. Consumer identity checks and its own processed/handoff transaction prevent this local duplicate from becoming a second logical run. Different event IDs can still be out of order; idempotency does not supply revision ordering.
The next layer is a standalone standard-library experiment with two local database files and synchronous function calls standing in for transport. The current capstone has durable task/receipt recovery; it does not implement this general outbox dispatcher or real queue. AWS’s transactional outbox guidance explains the general pattern.
code example
Different events may arrive out of order
Deduplicating event E1 cannot stop a distinct older revision E0 from overwriting E1. Sequence-sensitive updates need object revision checks and possibly gap handling. Stable event identity and object order are independent requirements.
Acceptance task for this level
For the five observations, record sender counts/state, consumer counts/state, permitted recovery action and what success is still unproven. Mark the three separate commit domains: sender intent, consumer handoff and remote business action.
Reading this browser’s record…
Hide the answer and check your understanding
Why can “send succeeded” and “event still pending” both be true?
Expand reference derivation
The consumer/transport acceptance and sender mark belong to separate commits. Acceptance can succeed before the sender loses its response or stops. A pending row requires safe same-event replay or reconciliation; it does not prove the first acceptance was absent.
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.