Boss lesson · Unit 03
An upload pipeline
From upload to thumbnail: events, a queue, idempotent workers and a dead-letter queue
What you practise
- Queues and events between services, at-least-once delivery and idempotent workers (from 14), a dead-letter queue
- An image upload processed end to end
Try a question from this lesson
Pick one
Making a thumbnail takes 4 seconds. For one minute, uploads arrive at 50 a second. What should the upload request do?
Correct answer
Save the file, queue the resize, answer at once
Why
The user needs to know the file is safe, not that the thumbnail exists. Saving and queueing takes milliseconds. The slow work happens later, at whatever pace the workers manage.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Events and queues
A bucket can emit an event when an object is created: a small JSON message saying which bucket and which key. It is a notice, not the file.
A queue holds messages until a worker takes them. The sender does not wait for the worker, or even know it exists.
AWS: S3 Event Notifications can feed an SQS queue, an SNS topic, a Lambda function or EventBridge. Cloudflare: R2 event notifications feed Queues, consumed by a Worker.
upload --> bucket --> event --> queue
|
thumbnail <-- worker <----'Concept
At least once
A worker receives a message, and the queue hides it from other workers for a while. If the worker finishes and deletes it in time, it is gone for good.
If the worker crashes or is too slow, the message reappears and is delivered again.
So every message arrives at least once, and sometimes twice. Workers must be idempotent: handling the same message twice leaves the same result as once.
Standard SQS queues and Cloudflare Queues both deliver at least once.
Concept
The dead-letter queue
Some messages can never succeed: the file is corrupt, the user was deleted. With at-least-once delivery such a poison message would come back forever.
So the queue counts deliveries. After a set number of failures it moves the message to a separate dead-letter queue, where it waits for a person to look.
AWS SQS: a redrive policy with maxReceiveCount. Cloudflare Queues: dead_letter_queue on the consumer. Without one, a message that runs out of retries is deleted.
9 more exercises in the app
- 3× multiple choice
- 1× order the lines
- 2× type the answer
- 2× fill the blanks
- 1× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.