FreePatternSQS
Queues that absorb a traffic spike
In one sentence: A queue lets the front end say “got it” immediately while the slow work happens at a pace the back end can handle.
Animated diagrams are not available for printing. Get StackKinetic Pro to download this explainer.
Inspect:
Read this explainer as text
Place an order
Beginner
- You click “Place order”.
- The shop drops your order into the waiting line.
- The line confirms your order is safely stored.
- You see “Order received!” straight away, even though nothing has been packed yet.
- A worker picks your order from the front of the line.
- The worker records your order.
- The database confirms it’s saved.
- The worker tells the line this order is done, so it’s removed.
Practitioner
- The client sends the order to the API.
- The API checks the order and sends it to the queue.
- The queue confirms the message is durably stored.
- The API answers immediately. The real work happens later.
- A worker pulls the next message.
- The worker processes the order and writes it to the database.
- The write succeeds.
- The worker deletes the message from the queue.
Architect
- POST /orders reaches the producer.
- SendMessage after validation; payload kept small, large data stored by reference.
- Ack once the message is replicated across zones.
- 202 Accepted: user latency is decoupled from processing time.
- ReceiveMessage; the message is hidden for the visibility timeout.
- Idempotent write keyed by order ID, since delivery is at-least-once.
- Commit acknowledged.
- DeleteMessage; had the worker crashed, the message would reappear after the timeout.
Traffic spike
Beginner
- A flash sale starts and thousands of shoppers click at once.
- Every order still drops straight into the line. The line just gets longer.
- Everyone still sees “Order received!” quickly.
- Workers keep taking orders one by one. More helpers can join if the line gets long.
- The database gets a steady trickle instead of a flood, so it never falls over.
Practitioner
- Order requests jump to many times the usual rate.
- The API keeps enqueuing; the queue grows.
- Users get fast confirmations despite the spike.
- Workers process at their own pace and can scale out on queue length.
- Database writes stay at a safe, steady rate.
Architect
- Producer rate far exceeds steady-state consumer throughput.
- Queue depth climbs; producers are unaffected by consumer speed.
- Latency stays flat for users; the backlog is absorbed by the queue.
- Autoscale consumers on ApproximateNumberOfMessages or age of oldest message.
- Bounded consumer concurrency caps DB write pressure; the backlog drains after the peak.
Bad message
Beginner
- A worker picks up an order that has something wrong with it.
- The worker can’t handle it, so the order goes back in the line.
- Another try, in case the problem was temporary.
- It fails again. Some orders just can’t be processed.
- After a few tries, the order is moved to a separate pile so it stops blocking the line. Someone can look at it later.
Practitioner
- A worker receives a malformed message.
- Processing fails; the message becomes visible again.
- The message is retried.
- It fails again.
- The queue moves it to the dead-letter queue.
Architect
- Receive #1 of a poison message.
- No delete; the visibility timeout expires and the message is redelivered.
- Receive #2. Transient failures usually succeed here.
- Still failing; receive count reaches maxReceiveCount.
- Redrive policy moves it to the DLQ; an alarm on DLQ depth pages a human.
Now add…
Take it with you
Pro adds video downloads, with embeds and editable source coming soon. Core explainers are always free to watch.