Free learning / 40-minute Queue 101 lab
Follow a job from accepted to finished
Understand messages, workers and acknowledgements. Compare lost work, duplicated work and a safely reused result with a visual walkthrough and real local database writes.
No account needed. Use your own copy for writing and keep the original as a reference.
Engineering lab library / Run locally
Follow the job. Inspect the effect.
Predict four outcomes, then compare the saved rows. Change the retry identity and see why acknowledgement alone cannot prove the task was done.
Real local SQLite writes with synthetic data. Delivery timing and interruptions are modeled; no broker, cloud account or external effect is used.
Start here / Python 3.11+ · Standard library
Queue delivery and business effects
Compare missing, duplicated and reused drafts across four delivery cases; change the replay identity and explain the result.
Python 3.11+ standard library · Offline synthetic data
Original LockedIn Labs instruction · 40-minute Queue 101 lab · reviewed 21 October 2026.
An engineer asks your application to prepare a maintenance draft. That may take longer than the original web request. A queue lets the application retain the job while a separate worker performs it. It is a software component, not a language, an agent or a promise that the task is finished.
You will follow one fictional job, see why it can arrive twice, and run real local database writes to compare lost work, duplicated work and a reused result. No account, cloud resource, model or payment is required.
1. Meet the message, worker and acknowledgement
UNDERSTAND THE SYSTEM
Follow one job through two deliveries
A queue retains instructions for a worker to process later. Accepting the job, writing its result and acknowledging a delivery are separate events. Follow the fictional J-12 draft to see why a missing acknowledgement does not mean the work never happened.
See what moves and why.
Read the connections in plain English
- 01Request API → Message broker
Acceptance retains the instruction; it does not prove the draft exists.
- 02Message broker → Worker program
The worker receives a temporary delivery. This is not an exactly-once business guarantee.
- 03Worker program → Saved draft
Write the local effect and its operation receipt together.
- 04Worker program → Operation receipt
Match tenant, action and input. A changed input under the same key must conflict.
- 05Worker program → Message broker
Confirm that the current delivery was handled after the local result exists.
Check your understanding: If A acknowledges first and then stops before saving the draft, what would the queue know?
It would consider the delivery handled even though there is no draft. The early-ack lab case has a settled message and zero effects. Confirm the intended result before acknowledging; preserve a stable operation identity for retries.
Think of a work-order desk: accepting an order, assigning it to someone and finishing it are different events. In software, a producer submits a message to a queue. A worker receives that message and does the work. An acknowledgement tells the queue that this delivery has been handled.
| Term | What it means here | Familiar comparison |
|---|---|---|
| Message | The instruction to prepare draft J-12 | A work order |
| Queue | Storage and delivery of pending messages | The waiting tray |
| Worker | A program that handles a message | The person doing the job |
| In flight | Delivered, with acknowledgement still pending | Checked out of the tray |
| Visibility period or lease | A bounded interval before work may become available again | A temporary assignment |
| Acknowledgement | Confirmation to the broker about this delivery | Marking the order handled |
| Operation key | Stable identity of the intended business action | The same order number across attempts |
The example key is north / J-12:draft:v1. The tenant, job and action stay the same when another worker retries. The delivery receipt changes. A receipt for a delivery and a receipt proving a business effect are different records.
Follow the visual one event at a time. Before advancing, predict both the message state and the number of saved drafts. A queue cannot infer a database commit from silence. A worker can stop after committing the draft but before acknowledging.
2. Run four delivery cases
Download the Python lab into a new working folder. You need Python 3.11 or later. It uses only the standard library.
python3 --version
python3 fde-queue-delivery-lab.py test
python3 fde-queue-delivery-lab.py demoThe program creates separate temporary SQLite databases and removes them when it finishes. Each event reads committed state through a new database connection. The queue is a small teaching model: expiry uses explicit integer ticks and the interruption is an omitted acknowledgement. No worker is killed and no vendor broker is contacted. The database writes and transaction rollbacks are real.
Make predictions first. Then inspect the final event in each case:
| Case | Deliveries | Saved effects | Explanation |
|---|---|---|---|
normal | 1 | 1 | Write the draft, then acknowledge. |
duplicate-effect | 2 | 2 | Write, omit acknowledgement, then write again on redelivery. |
reuse-effect | 2 | 1 | Recognize the same action and reuse its committed result. |
early-ack | 1 | 0 | Acknowledge first, then stop before the draft exists. |
Notice that both normal and early-ack end with a settled message. A settled queue entry alone cannot demonstrate that the intended business action happened. Keep the trace lines that establish each conclusion.
3. Make the business action safe to repeat
Idempotency means repeating an operation has the same intended effect as doing it once. Here the safe path writes the effect and its receipt in one SQLite transaction. On a repeat, it checks the same tenant, operation key and payload, then reuses the recorded outcome. A changed payload under the same key is a conflict; a different action needs a deliberately different key.
Read apply() in the Python file. BEGIN IMMEDIATE starts the write transaction. The receipt and draft commit together. An exception between them rolls both back. In test_receipt_rolls_back_with_effect, the next attempt can still create the draft because no false success receipt remains.
Experiment in your own copy:
- In
run_case, change the second call to useoperation="J-12:draft:v2". Predict why the safe replay now creates a second effect. Rundemo. - Restore it. Change the second call to
payload="different draft"instead. Predict and observeoperation_conflictin the safe case. The refusal is intentional: it must not silently call changed work a repeat. - Restore the original. Explain why
receive(now=4)refuses a new delivery butreceive(now=5)permits one in this model. Inspect the boundary test. - Draw the two commits separately: the business effect, then acknowledgement. Mark where the interruption occurs and which evidence the next worker reads.
This model checks the current delivery receipt at acknowledgement time. It does not cancel an old process or fence a remote service. A real service must enforce authorization again at its write boundary and bind replay to the intended input. For an external action such as sending an email, a local receipt and the remote effect do not share a SQLite transaction. Use the destination's supported idempotency and reconciliation contract; an unknown outcome is not permission to send again blindly.
4. Recognize the cloud vocabulary
These are related delivery concepts, not interchangeable APIs. Start with the provider's documented delivery mode and client behavior before choosing retries.
| Service | Temporary delivery state | Successful handling |
|---|---|---|
| Amazon SQS standard queue | Visibility timeout | Delete the handled message |
| Google Cloud Pub/Sub pull subscription | Outstanding message with an acknowledgement deadline | Acknowledge the message on that subscription |
| Azure Service Bus Peek-Lock | A message lock | Complete the message |
SQS standard delivery can produce duplicates even during a visibility period. Pub/Sub subscriptions have their own delivery and acknowledgement settings. Service Bus also offers Receive-and-Delete, which has different loss behavior from Peek-Lock. Never translate the local lab into an exactly-once claim about a cloud service or an external business effect.
For your chosen service, record the delivery mode, acknowledgement operation, expiry behavior, bounded retry policy and the owner of repeatedly failing work. A dead-letter destination holds messages for investigation; it does not repair them. Ordering, retention, permissions and operational alerts need explicit decisions too.
Official references checked 21 October 2026:
5. Explain it to the receiving engineer
Keep your four predictions, the actual traces, one changed-key experiment and a diagram showing effect before acknowledgement. Explain the result without using the phrase “the queue handles it.” Name exactly which component recognizes a repeat and what evidence it stores.
Transfer challenge: the draft is now an email sent through another company's API. Your worker times out after submitting it. State what is unknown, how you would query or reconcile the original operation, and when a human must decide. The local transaction is evidence for a local write only.
Continue into the worker recovery lab for actual process interruption, lease fencing and competing workers, or open the guided Queue 101 lesson with your existing training access.