Message queues & streams
At-least-once vs at-most-once, Kafka partitions and consumer groups vs RabbitMQ routing, ordering guarantees, DLQs, backpressure. Decoupling with eyes open.
The mental model
A message queue is the kitchen ticket rail in a busy restaurant. Waiters (producers) clip orders onto the rail and immediately go back to serving tables; cooks (consumers) pull tickets when they are ready to cook. The waiter never waits for the food, the cook never waits for a waiter, and if the kitchen falls behind, tickets simply pile up on the rail instead of orders being lost. The rail decouples the pace of taking orders from the pace of cooking them — that decoupling is the entire point.
In software terms: instead of service A calling service B synchronously and waiting (and failing if B is down), A publishes a message and moves on; B consumes it when able. This buys three things — decoupling (A does not know or wait for B), buffering (a traffic spike queues instead of overwhelming B), and resilience (if B is down, messages wait rather than erroring). You trade immediate consistency for these; the order is not cooked the instant it is taken.
Why this exists — what breaks without it. Synchronous chains fail together: if checkout calls inventory calls email calls analytics, a slow email service makes checkout slow, and a down analytics service can fail the checkout. A traffic spike that a queue would absorb instead hammers every downstream at once. Long work (video encoding, report generation) done inline holds an HTTP connection for minutes. And there is no natural place to retry — a failed synchronous call is just an error to the user. Queues fix all four, but they introduce their own hard problems that define the interview: delivery is at-least-once, so duplicates happen; ordering is only guaranteed within a partition; a poison message can block a queue; and "exactly-once" is a marketing term for idempotent processing. Decoupling "with eyes open" means knowing these.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision