Browser simulation
Request Replay
An interactive model of at-least-once delivery. Send one event through a queue, a worker and a store, then replay a duplicate or a lost acknowledgement and compare the worker with and without an idempotency guard.
- Type
- Browser simulation
- Models
- Queue, worker, store and acknowledgement
- Event
- One fictional order.created event
Try it
Pick a scenario and a guard setting, then run it or go one step at a time. Select any step in the trace to inspect the state at that moment.
Reduce motion is on. Run shows the result at once, and Next step walks through it with nothing moving.
- Queue
- Worker
- Store
- Acknowledgement
Ready
Completed run: One delivery and one acknowledgement. Nothing repeats, so the guard has nothing to catch. Try a duplicate or a lost acknowledgement.
Completed run: One delivery and one acknowledgement. Without a repeat, the unguarded worker looks fine. The difference only appears when an event arrives again.
Completed run: The second delivery found the event in the ledger and got job_1 back. Two deliveries, one job.
Completed run: Without the guard, each delivery created a job. One order now has two fulfillment jobs.
Completed run: The commit happened before the acknowledgement was lost. The redelivery found the ledger record and got job_1 back, so retrying was safe.
Completed run: The work had already succeeded, but the redelivery created job_2. A timeout is not proof that the work failed.
- Deliveries
- 0
- Jobs created
- 0
- Original job returned
- 0
- Acknowledgements lost
- 0
Inside the store
| Key | Payload digest | Job |
|---|
No completed events recorded yet.
Fulfillment jobs
Deliveries
Event traceNo steps yet
Walkthrough
The three scenarios step by step with the guard on, as the model runs them.
Single delivery
- Queue: Event queued. order.created evt_7Q2K9 enters the queue as delivery dlv_1, attempt 1.
- Worker: Worker takes dlv_1. The worker receives attempt 1 of evt_7Q2K9. It handles one delivery at a time.
- Store: Committed job_1. One transaction finds no record for fulfillment:evt_7Q2K9, creates job_1 and records the event as completed by job_1.
- Acknowledgement: Acknowledged dlv_1. The acknowledgement reaches the queue, which removes dlv_1.
- Result: 1 delivery, 1 job.
Without the guard: 1 delivery, 1 job.
Duplicate delivery
- Queue: Event queued. order.created evt_7Q2K9 enters the queue as delivery dlv_1, attempt 1.
- Queue: Same event queued again. evt_7Q2K9 is queued a second time as dlv_2. At-least-once delivery allows duplicates, for example after a publisher retry.
- Worker: Worker takes dlv_1. The worker receives attempt 1 of evt_7Q2K9. It handles one delivery at a time.
- Store: Committed job_1. One transaction finds no record for fulfillment:evt_7Q2K9, creates job_1 and records the event as completed by job_1.
- Acknowledgement: Acknowledged dlv_1. The acknowledgement reaches the queue, which removes dlv_1.
- Worker: Worker takes dlv_2. The worker receives attempt 1 of evt_7Q2K9. It handles one delivery at a time.
- Store: Returned job_1. The ledger already records fulfillment:evt_7Q2K9 with the same payload, so the transaction returns job_1 and creates nothing.
- Acknowledgement: Acknowledged dlv_2. The acknowledgement reaches the queue, which removes dlv_2.
- Result: 2 deliveries, 1 job. The repeat returned job_1.
Without the guard: 2 deliveries, 2 jobs. The repeat created a duplicate job.
Acknowledgement lost
- Queue: Event queued. order.created evt_7Q2K9 enters the queue as delivery dlv_1, attempt 1.
- Worker: Worker takes dlv_1. The worker receives attempt 1 of evt_7Q2K9. It handles one delivery at a time.
- Store: Committed job_1. One transaction finds no record for fulfillment:evt_7Q2K9, creates job_1 and records the event as completed by job_1.
- Acknowledgement: Acknowledgement lost. The commit already succeeded, but the acknowledgement for dlv_1 never reaches the queue.
- Queue: Redelivered as dlv_2. No acknowledgement arrived before the visibility timeout. The queue cannot tell whether the work happened, so it delivers evt_7Q2K9 again as dlv_2, attempt 2.
- Worker: Worker takes dlv_2. The worker receives attempt 2 of evt_7Q2K9. It handles one delivery at a time.
- Store: Returned job_1. The ledger already records fulfillment:evt_7Q2K9 with the same payload, so the transaction returns job_1 and creates nothing.
- Acknowledgement: Acknowledged dlv_2. The acknowledgement reaches the queue, which removes dlv_2.
- Result: 2 deliveries, 1 job. The repeat returned job_1. The lost acknowledgement did not mean the work failed.
Without the guard: 2 deliveries, 2 jobs. The repeat created a duplicate job. The lost acknowledgement did not mean the work failed.
What it shows
With at-least-once delivery, an event can arrive more than once. A worker that acts once per delivery will then sometimes act twice. Here, acting twice means two fulfillment jobs for one order.
The guard makes the worker idempotent. It keys a ledger by the event's scoped ID, so a repeat gets back the job that already exists instead of creating another.
A lost acknowledgement is not a failure
In the third scenario the store commits job_1, and then the acknowledgement is lost. The queue only knows that it did not hear back before the visibility timeout. A crash before the commit and a lost acknowledgement after it look the same from there, so delivering again is the safe choice.
That is why a timeout cannot be read as failure. The retry has to be safe to run again, and the guard is what makes it safe.
One transaction, not a lookup
The guard reads the ledger and writes the job and its completion record in one transaction. If the event is already recorded with the same payload, it returns the stored job ID. If the same scoped ID arrives with a different payload, it rejects the delivery instead of guessing which version is right.
Checking a cache and then creating the job is not enough. A crash between the two steps, or two workers racing, can still produce two jobs. Effects that leave the database, such as a payment or an email, need more. A transactional outbox records the intent to send in the same transaction as the ledger, but the relay that delivers it can still send it more than once. The receiving service or external API therefore still has to handle duplicates, for example by honouring an idempotency key that the sender reuses on every attempt.
What is modelled
- One fictional order.created event, evt_7Q2K9, with deterministic delivery and job IDs.
- A single worker that handles one delivery at a time, and a store whose transaction is one step of the model.
- Counts on this page are read from the model's records. Playback speed and motion settings never change them.
- It runs in your browser and saves nothing. It is not a real queue or database, it is not durable, and it is not proof of exactly-once execution in production.
- Nothing connects to Shopify, DeskLab or any live service.
How it is checked
The model is a small pure JavaScript module. Its tests cover every scenario with the guard on and off, reuse of the original job ID, rejection of a conflicting payload, the atomic ledger and job commit, deterministic traces and snapshots that cannot change afterwards.
Separate tests drive the page controller: replacing a run, pausing, resetting, hidden tabs, and reduced motion from the site switch, the device setting and another tab. Both run in this site's checks. They test the model and this page, not a production system.