CONCEPT SHEET · Concepts

Message Queues and Streams

One-liner: A broker decouples producers from consumers in time and rate; queues deliver each message to one worker, topics fan out to many.

ArticleConcepts© Arthur Bernier Jr647 words1 code block

Say this#

How it works#

TEXT
producers -> [topic: orders | p0 | p1 | p2 | p3]  -> consumer group A (4 consumers, 1 partition each)             key=user_id -> hash -> partition     -> consumer group B (analytics, independent offsets)
  1. Producer sends with a key; broker hashes key → partition (same key ⇒ same partition ⇒ ordered).
  2. Broker persists (Kafka: append-only log replicated across brokers, acks=all for durability).
  3. Consumers in a group pull from their partitions, process, commit offsets.
  4. Failure: uncommitted messages are reprocessed → at-least-once → consumer must be idempotent.
  5. Repeated failure → DLQ after max retries; alert and inspect.

Queue vs stream: a queue deletes on ack (RabbitMQ, SQS); a log retains and lets many groups replay (Kafka, Kinesis).

Trade-offs#

ChoiceProCon
KafkaHuge throughput, replay, ordering per key, many consumer groupsOperational weight (brokers + KRaft/Zookeeper), partitions fixed-ish, no per-message ack
RabbitMQFlexible routing (exchanges), per-message ack, low latency, prioritiesLower throughput; no replay; queues are the bottleneck
SQSZero ops, infinite scale, cheapNo ordering (standard), 256 KB messages, no fan-out alone (pair with SNS)
Redis StreamsAlready have Redis, simpleMemory-bound, weaker durability
More partitionsMore parallelismMore files/metadata, rebalance pain, less global ordering
Sync RPC insteadImmediate response, simpleTight coupling, cascading failures, no buffering

Numbers#

  • Kafka: millions of msgs/s per cluster; a single partition commonly 10-50 MB/s; end-to-end latency ~5-20 ms.
  • RabbitMQ: tens of thousands of msgs/s per node order of magnitude.
  • SQS: standard queues effectively unlimited throughput; FIFO 300 msgs/s per group without batching (3,000 with batching, higher in high-throughput mode); max message 256 KB; retention up to 14 days (default 4).
  • Kafka default retention 7 days; max message size default 1 MB.

In the interview#

See also