A buffer between producers and consumers that decouples them, absorbs spikes as backlog, and lets work happen at the consumer's pace.
A message queue is a buffer that sits between the parts of a system that *create* work (producers) and the parts that *do* it (consumers). A producer drops a message in and moves on instead of waiting for the work to finish — asynchronous decoupling. The queue absorbs spikes as a backlog, and adding more consumers drains it faster, so work happens at the consumer's own pace rather than the producer's.
What happens if a consumer crashes mid-processing? The answer is the queue's delivery guarantee. At-most-once: deliver and forget — a crash means the message is lost (fast, lossy). At-least-once: the broker redelivers until the consumer acknowledges success — nothing is lost, but a crash *after* the work but *before* the ack causes a duplicate. Exactly-once is the ideal but is genuinely hard end-to-end; in practice you get at-least-once delivery plus idempotent consumers, so processing a duplicate has no extra effect.
INSERT ... ON CONFLICT DO NOTHING — so a redelivered "charge the card" message doesn't charge twice.If producers persistently outrun consumers, the backlog grows without bound and eventually the broker runs out of storage. Backpressure is the set of mechanisms that push back: bounded queues that block or reject producers when full, slowing them to the consumers' pace; or a lag signal that triggers autoscaling of consumers. The goal is to keep the backlog *finite* rather than letting it silently balloon into an outage.
Kafka models a queue as a topic split into partitions — each an append-only, ordered log. A message's position in a partition is its offset, a monotonically increasing number. Consumers don't have messages pushed and deleted; instead each consumer group tracks its own offset — the position it has read up to — and advances it as it processes. This is why Kafka can replay: rewind the offset and reread old messages.
topic "orders", partition 0 (append-only log):
offset: 0 1 2 3 4 5 6
[m0] [m1] [m2] [m3] [m4] [m5] [m6]
^ ^
consumer committed log end
offset = 3 (read 0..2)
- ordering is guaranteed WITHIN a partition, not across them
- messages with the same key go to the same partition
- parallelism = number of partitions (one consumer per partition)