Out-of-order events debugging lab. The courier says delivered. Our tracking page says out for delivery, an hour later. Fix it live, then prove it under load.
Practice debugging a out-of-order events in a live, broken production system in your browser, with RabbitMQ and PostgreSQL. Find the root cause in the logs, terminal and code, fix it, and a load test checks that the fix holds under real traffic.
1. The Incident Context
On Monday the tracking consumer was scaled from 1 to 6 instances to keep up with peak season. Since then customers have been watching parcels move backwards: delivered, then out_for_delivery, sometimes in_transit. One customer got the "Your parcel was delivered" email and then, a few seconds later, "Your parcel is out for delivery". The courier's own tracking is correct, and its webhooks almost always reach us in the right order.
2. Observed Symptoms & Metrics
- Affected Endpoints / Components:
POST /webhooks/courier (ingest), the RabbitMQ queue tracking.events, the tracking consumer (6 replicas, c1–c6 in the logs), the Postgres shipments table, GET /shipments/{id}, and the mail provider at localhost:9300.
- Behavior: Every courier event is accepted with
202 and shows up in the logs as applied. For most parcels the final status is right. For a few percent, the status on the tracking page is older than the courier's latest event, or it moves forward and then back again while the customer is watching. Some customers get the same email twice, or get emails in the wrong order.
- Error Rate: HTTP looks clean. About 4% of shipments end in a status that is not their latest courier status, and about 1% of customers get an email out of order.
- System Metrics: Broker and database are healthy. No errors, no lock waits, no redelivery storms.
3. Application Logs
2026/10/12 09:00:00 tracking consumer c3 started
2026/10/12 09:14:22.104 c3 shipment 5521 -> delivered (courier seq 7, courier ts 09:14:21)
2026/10/12 09:14:22.109 c5 shipment 5521 -> out_for_delivery (courier seq 6, courier ts 08:02:10)
2026/10/12 09:14:22.110 c5 email shipment 5521: "Your parcel is out for delivery"
# psql
SELECT id, status, updated_at FROM shipments WHERE id = 5521;
id | status | updated_at
------+------------------+----------------------------
5521 | out_for_delivery | 2026-10-12 09:14:22.109+00
4. Your Objective
Step into the live environment while synthetic traffic is running, find the root cause, and patch the code.
To clear this stack, your fix must pass these checks during a 2-minute run: 1,500 parcels with 4 to 8 courier events each, some events arriving in the wrong order, 5% duplicates, 2% stale replays sent 10–45 seconds late, 6 consumer replicas, and one replica killed with SIGKILL partway through:
- Correctness: At the end, every shipment's status equals its highest-seq courier event (
final_state_mismatches == 0).
- Monotonic reads: Polling
GET /shipments/{id} during the run never shows a status move backwards (regressions_observed == 0).
- Notifications: Each status triggers at most one customer email, and no email goes out for a status older than one already emailed (
out_of_order_emails == 0). Customers must still get their emails.
- Performance: P99 time from webhook to visible status is below 2 seconds (
p99_propagation_ms < 2000), so pushing every event through a single consumer one at a time is too slow.
Environment note: every courier event carries parcelId, a per-parcel seq that only ever goes up, the courier's status, the depot that scanned it, and the courier's ts. Depot clocks drift by up to 90 seconds, so ts is not safe to order by. A parcel can legitimately go from out_for_delivery back to in_transit when a delivery attempt fails. The app runs as 6 replicas; each one serves the webhook, consumes the queue and serves GET /shipments/{id}. Your app's startup code can change the schema. The mail provider at localhost:9300 accepts an optional Idempotency-Key header and ignores a repeated key.
Toolbox: psql "$DATABASE_URL", curl localhost:8080/shipments/5521, curl 'localhost:9300/emails?shipment=5521', curl -su guest:guest localhost:15672/api/queues, curl -X POST localhost:8080/webhooks/courier -H 'Content-Type: application/json' -d '{"parcelId": 1, "seq": 1, "status": "picked_up", "depot": "LHR1", "ts": "2026-10-12T08:00:00Z"}'. Save a file in the editor to rebuild and restart the app. Click Verify when you think it's fixed.
Terms in this lab: replica (one running copy of the app), consumer (a process that reads messages from a queue), broker (RabbitMQ), seq (the courier's sequence number for a parcel's events), webhook (an HTTP call the courier makes to us), SIGKILL (kills a process instantly, no cleanup), p99 (99% of requests are faster than this).
You can browse stacks without an account. To run labs you sign in with your email or Google account. BustedStack uses your email address to
sign you in, and your name and profile picture to show your account and pre-fill certificates. We never access your Gmail, contacts or Drive,
sell your data or run ad trackers.
This site needs JavaScript to run labs.