Three values
| Value | Scenario |
|---|---|
| Async | Send email, build reports; the main flow need not wait |
| Buffer peaks | Flash sale spikes enter the queue, consumed at a steady rate |
| Decouple | Services talk via events, not direct calls |
Typical shape
Producer to queue (durable) to consumer. The queue buffers in the middle; the producer can fail without losing work, and a slow consumer will not crush upstream.
Two caveats to settle
- Duplicate consumption: retries can deliver a message twice, so the consumer must be idempotent (dedup table, state machine);
- Ordering: one queue is usually ordered, but after sharding the same business key must route to the same shard to keep order.
Versus RPC
RPC is a synchronous "I need the result now" call; a queue is an asynchronous "handle it later" notice. Deduct stock on order via RPC, send the email via queue.