Amazon SQS
easy 25 minAmazon SQS is a managed queue: producers send messages over HTTPS, consumers poll for them, and a message is hidden, not removed, while somebody works on it.
See it run
Send, hide, delete. Then crash a worker, keep a long job alive, block a FIFO group and empty the dead letters.
Operations
One message
The normal path: nothing is removed until the worker says so.
Step 1 of 4
Send
Visible
order 42
In flight
The producer sends order 42. SQS stores copies and answers with a message id.
Step 1: Send
send(body)msg, handle = receive(wait=20)work(msg)delete(handle)- Delay
- One poll plus the work
- Promise
- At least once
- Delete before the work
- a crash loses it
Delete is the last line of the worker, after the result is saved.
In the real world
The same amazon sqs doing real jobs. Pick one and step through it.
Work takes 45 seconds, the timeout is 30.
Step 1 of 4
Second 0
Visible
In flight
order 42
Worker A starts order 42.
Step 1: Second 0
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Deleting before the work
criticalIf the worker dies in between, nobody has the message any more.
Wrongdelete(handle)work(msg)Rightwork(msg)delete(handle)Not safe to repeat
criticalAt-least-once delivery means that a second run will happen some day.
Wrongcharge(card, amount)Rightcharge(card, amount, key=order_id)Short polling in a loop
majorEmpty answers cost requests, and messages may be missed for a moment.
Wrongreceive(WaitTimeSeconds=0)Rightreceive(WaitTimeSeconds=20, MaxNumberOfMessages=10)One message group for all
majorA constant group makes the FIFO queue a single lane that one failure blocks.
WrongMessageGroupId="orders"RightMessageGroupId=cart_id
Interview tips
How to explain it
- Receive hides, delete removes.
- The timeout replaces crash detection.
- So the same work may run twice.
Memory trick
- A cup over the token.
- Done box: deleted.
- Ask drawer: dead letters.
Reach for it when
- Work can wait but must not be lost.
- Load is spiky.
- You want no broker to run.
Be careful when
- Somebody needs a replay.
- Many teams read the same event.
- Work lasts longer than the timeout.