System Design

Core Concepts

Message Queues vs Event Streams

A queue is a shared work list where the broker remembers who has what. A log is a shared history where each reader remembers where it is. Every other difference between them follows from that one, and you can derive all of it.

Why you are doing this at all

Most comparisons of queues and streams are feature tables. Kafka keeps messages and Amazon SQS deletes them. Kafka guarantees order and RabbitMQ doesn't. Kafka scales to millions of messages a second and queues don't. Each of these is roughly true, none of it is easy to remember, and none of it tells you which one to use.

Underneath those tables is one difference, and everything in them follows from it.

A queue is a shared work list where the broker remembers who has what. A log is a shared history where each reader remembers where it is.

The broker is the server that holds the messages. A queue keeps state for every message on the broker. A log stores a sequence of records that never changes, and each reader keeps its own bookmark into it, called an offset. Once you have that, you don't need to memorise the feature table, because you can work it out.

Try it with the queue. The broker tracks each message, so it can hand messages to any number of consumers, and there's no limit on how many you run. If a consumer never acknowledges a message, meaning it never confirms it finished the work, the broker hands the message out again, so retry is built in. The broker can reject one message on its own, so a dead-letter queue comes naturally: a side queue for messages that keep failing. And once a message is acknowledged, the broker forgets it, so there's nothing to replay.

Now the log. Each reader owns its position, so adding a reader costs nothing. The data is read-only, and the new reader starts at whatever offset it likes. Replay is free, because you move the bookmark backwards. Order is kept, because a sequence read in order stays in order. And the number of readers working in parallel has a ceiling. A big log is split into partitions, separate sequences that are each read in order. A reader keeps one offset per partition, and two consumers can't both own the same offset. So at most one consumer works on each partition at a time.

Who keeps the position
On the left, the broker keeps a row for every message: available, delivered to a named consumer, or acknowledged. The broker decides which consumer gets what. On the right, the log is a numbered sequence that nobody deletes from. Each of the three readers keeps its own offset, at 3, 12 and 47, and moves it forward itself.On the left, the broker keeps a row for every message: available, delivered to a named consumer, or acknowledged. The broker decides which consumer gets what. On the right, the log is a numbered sequence that nobody deletes from. Each of the three readers keeps its own offset, at 3, 12 and 47, and moves it forward itself.
A queue tracks every message. A log gives each reader one number. On the left, the broker keeps a row for every message: available, delivered to a named consumer, or acknowledged. The broker decides which consumer gets what. On the right, the log is a numbered sequence that nobody deletes from. Each of the three readers keeps its own offset, at 3, 12 and 47, and moves it forward itself.

The question that actually decides it

The deciding question isn't which one is faster. It's this one:

Is this work, or is this history?

Work is a task that must happen once and is then finished: send this welcome email, resize this upload, charge this card, reindex this document. Nobody wants a record of the task afterwards. They want it done. Work belongs in a queue, because a queue's whole job is tracking what has and hasn't been done.

History is a fact that has already happened: order 4471 was placed, user 88 changed their address, a payment settled. Any number of teams may care about it, now or in six months. A fact never gets "completed". Different consumers want it for different reasons, and some of those reasons don't exist yet. History belongs in a log.

The most common design mistake here is putting one in the other. The second most common is not noticing that you have both. A system with both a Kafka topic and an SQS queue is not confused; it is usually correct. A Kafka topic is a named log. Orders go in the log because five teams care about them. Sending the confirmation email is work, so it goes in a queue.

When you need neither

A queue and a log both let a caller hand off work without waiting for the service that does it. If the caller needs the answer before it can reply to its user, you want neither. You want a direct call. A broker in between doesn't remove the wait, it only moves it, and it adds one more thing that can fail.

The test is one question: would the caller wait for the result? If yes, call the service. If no, and the work must happen eventually, put it in a queue. If no, and other teams might care about it, write it to a log.

The toolkit

Everything that follows from that one difference

Here is the feature table, worked out rather than memorised. The right column matters most. No row is a choice a vendor made. Each one follows from where the position is kept.

behaviourqueuelogbecause
how many consumersas many as you likeone per partition, per groupposition is per partition
adding a consumerbroker hands it workit starts at an offset, freedata is read-only
a second, independent readerneeds a fanout topologycosts nothingnobody's read deletes anything
after processingbroker forgets the messagerecord stays until retention expiresconsumption is not deletion
replaynot possiblemove the offset backthe history is still there
orderingper message group, if offeredper partition, alwaysa sequence read in order is ordered
retry of one messagenatural, it was never ackedawkward, offsets move forwardyou commit a position, not a message
poison messagedead-letter after N attemptsblocks the partitionyou cannot skip one and keep the rest
broker memory and IOgrows with in-flight messagesgrows with retention, not consumersper-message state versus per-reader state
a slow consumerholds one message invisiblefalls behind, affects nobodyit just has a smaller number

Look at the last row. In a queue, a delivered message is hidden from every other consumer until its visibility timeout runs out. The visibility timeout is how long the broker waits for the acknowledgement before it hands the message out again. So a stuck consumer holds a message that nobody else can see. In a log, a stuck consumer is at a lower offset, and no other reader notices. The same one difference gives you two very different things to run in production.

The parallelism ceiling, which is where logs get misused

In a log, the unit you can read in parallel is the partition. A consumer group is a set of consumers that share the work of reading one topic. Within one group, each partition is read by exactly one consumer, because the group keeps one offset per partition and two processes can't both own it. So your maximum useful consumer count equals your partition count, and every consumer beyond that sits idle.

Back of envelopeImage resizing: what a log ceiling costs you
Need to resize 5,000 images/s. Each takes 200 ms of CPU.

Concurrency required
  Little's Law: 5,000/s x 0.2 s        = 1,000 workers

On a log with 12 partitions
  useful consumers                     = 12 (the rest idle)
  throughput  12 / 0.2 s               = 60 images/s
  required                             = 5,000 images/s
  → 83x short, and adding machines changes nothing

To fix it inside the log model
  partitions needed                    = 1,000
  and in Kafka you cannot reduce partition count later,
  only increase it, so 1,000 is now permanent

On a queue
  workers                              = 1,000
  throughput  1,000 / 0.2 s            = 5,000 images/s
  partitions to configure              = 0

  ─────────────────────────────────────────────────────────
  The work is embarrassingly parallel and completely
  unordered, which is exactly the shape a queue is for.
  Choosing a log here means inventing a constraint the
  problem never had.
Throughput against consumers
Each consumer resizes 5 images a second, at 200 ms an image. The queue line, in green, keeps rising and reaches the 5,000 a second you need at 1,000 workers. The log line, in red, rises the same way up to 12 consumers and then stays flat at 60 a second. The 13th consumer and every one after it gets no partition.Each consumer resizes 5 images a second, at 200 ms an image. The queue line, in green, keeps rising and reaches the 5,000 a second you need at 1,000 workers. The log line, in red, rises the same way up to 12 consumers and then stays flat at 60 a second. The 13th consumer and every one after it gets no partition.
Past the partition count, more consumers add nothing. Each consumer resizes 5 images a second, at 200 ms an image. The queue line, in green, keeps rising and reaches the 5,000 a second you need at 1,000 workers. The log line, in red, rises the same way up to 12 consumers and then stays flat at 60 a second. The 13th consumer and every one after it gets no partition.

Head-of-line blocking, the other half of that mistake

The same property causes a second problem. This one shows up as an incident, not as a number in a capacity plan.

In a log, you commit a position, not a message. Committing offset 600 says that everything up to 600 is done. So if record 500 can't be processed, you can't acknowledge 501 to 600 without also claiming that 500 succeeded. One bad or slow record holds up everything behind it in its partition. This is head-of-line blocking.

Back of envelopeOne slow record, in each model
A partition receiving 1,000 records/s. One record takes 30 s,
because it triggers a call to an external API that hangs.

In a log
  the consumer cannot advance its offset past it
  records delayed  1,000/s x 30 s        = 30,000
  and they are delayed in order, so the newest ones
  are the most delayed

In a queue
  that message is checked out by one worker
  other workers are unaffected
  records delayed                        = 1

  ─────────────────────────────────────────────────────────
  30,000 against 1, from the same input.

And a record that ALWAYS fails is worse. In a queue it is
delivered N times and then moved to a dead-letter queue
automatically. In a log it blocks the partition until a
human decides to skip it, and skipping means either losing
it or hand-building the dead-letter path yourself.
One slow record, in each model
In the log, record 500 is stuck, so the consumer's offset can't move past it. Records 501 to 600 wait behind it, though nothing is wrong with them (1). In the queue, one worker holds the same message while the other four keep working (2). After a set number of failed attempts, the broker moves the message to the dead-letter queue by itself (3).In the log, record 500 is stuck, so the consumer's offset can't move past it. Records 501 to 600 wait behind it, though nothing is wrong with them (1). In the queue, one worker holds the same message while the other four keep working (2). After a set number of failed attempts, the broker moves the message to the dead-letter queue by itself (3).
In a log, one stuck record holds up its whole partition. In the log, record 500 is stuck, so the consumer's offset can't move past it. Records 501 to 600 wait behind it, though nothing is wrong with them (1). In the queue, one worker holds the same message while the other four keep working (2). After a set number of failed attempts, the broker moves the message to the dead-letter queue by itself (3).

Replay and fanout, which is where logs earn their keep

Now the case where a log wins. Say five teams care about "order placed": fulfilment, analytics, the recommendation model, fraud, and customer emails.

In a log, this costs almost nothing. Each team creates its own consumer group, starts at whatever offset it likes and reads the same records. The groups don't interact and can't slow each other down. A sixth team next quarter is one line of configuration. If the recommendation model has a bug, that team moves its offset back to last Tuesday and rebuilds.

In a queue, a message goes to one consumer. Two consumers on one queue compete for messages. They don't each get a copy. So you need a fanout: a topic, such as Amazon SNS, or a RabbitMQ exchange, that copies each message into five queues. That works. But now you own five subscriptions, five sets of alarms and five copies of every message. And you still can't replay, because each queue deleted its messages as they were acknowledged.

Five readers of the same events
On the left, one log is read by five consumer groups, each with its own offset. A sixth group joins without a new copy of anything (1), and one group moves its offset back to replay last Tuesday (2). On the right, SNS copies every message into five queues, one per consumer. A sixth reader needs a new queue and a new subscription. Replay is impossible, because each queue deletes a message once it is acknowledged.On the left, one log is read by five consumer groups, each with its own offset. A sixth group joins without a new copy of anything (1), and one group moves its offset back to replay last Tuesday (2). On the right, SNS copies every message into five queues, one per consumer. A sixth reader needs a new queue and a new subscription. Replay is impossible, because each queue deletes a message once it is acknowledged.
A log stores the data once. A fanout copies it for every reader. On the left, one log is read by five consumer groups, each with its own offset. A sixth group joins without a new copy of anything (1), and one group moves its offset back to replay last Tuesday (2). On the right, SNS copies every message into five queues, one per consumer. A sixth reader needs a new queue and a new subscription. Replay is impossible, because each queue deletes a message once it is acknowledged.
Back of envelopeFive consumers of the same events, priced
1 TB of events per day. Five independent consumers.

Log
  stored                                 1 TB/day
  read      5 x 1 TB                     5 TB/day
  adding a sixth consumer:               +1 TB/day read
                                         +0 storage
                                         +1 config line

Queue with fanout, one queue per consumer
  written   5 x 1 TB                     5 TB/day
  stored    5 x 1 TB                     5 TB/day
  read      5 x 1 TB                     5 TB/day
  adding a sixth consumer:               +1 TB/day stored
                                         +1 TB/day written
                                         +1 queue, +1 subscription,
                                          +alarms, +IAM

  ─────────────────────────────────────────────────────────
  5 copies of every message instead of 1, and the difference
  grows with every consumer, because a queue must copy and a
  log can share.

And the thing money cannot buy back: the queue has no
history, so a consumer bug means the data needed to fix it
is already gone.

Ordering, and the fact that it is the same knob as parallelism

Both models can give you ordering, and both charge for it in the same way.

A log orders records within a partition. Each record has a key, and the key decides its partition. So all records for one key are in order relative to each other. Records with different keys have no defined order. A queue that offers ordering does it within a message group, chosen by a group ID on each message.

The names differ and the mechanism is the same. In both, the scope you order within is also the unit you can parallelise across. If you order everything globally, you have one ordered stream, and that means one consumer. If you order per customer, you have millions of independent streams, and as much parallelism as you want.

SQS FIFO queues, which deliver in first-in, first-out order, show it with numbers. Without high throughput mode, a FIFO queue allows 300 transactions per second per API action. A transaction is one call, and a batch call carries up to 10 messages. With high throughput mode on, SQS spreads the queue over partitions and hashes each message group ID to pick one. All messages in one group land in the same partition, and each partition handles about 300 messages per second per API action, or 3,000 with batching. So one group can never go faster than one partition, and you scale by having more groups. That's Kafka's partition model with different words.

Back of envelopeWhat your ordering scope costs
SQS FIFO in high throughput mode: each message group lives
in one partition, roughly 300 messages/s per API action
without batching.

Order globally: one message group
  ceiling                                ~300 msg/s
  parallel consumers                     effectively 1

Order per region: 20 groups
  ceiling  20 x 300                      up to ~6,000 msg/s

Order per customer: 500,000 groups
  ceiling                                the queue's own quota,
                                         not your ordering
  parallel consumers                     as many as you fund

  ─────────────────────────────────────────────────────────
  Same principle on a log: one partition is one ordered
  stream and one consumer.

So the design rule is: order within the NARROWEST scope your
correctness actually requires. "Events must be in order" is
almost never true globally, and asking "in order relative to
what?" usually converts a 300/s ceiling into no ceiling.
Ordering scope sets the parallelism
Above, one global order puts every record in one sequence, so one consumer reads them all. Below, the same records are routed by customer into three ordered lanes, each with its own consumer. A log calls the routing value a partition key, and an SQS FIFO queue calls it a message group ID. It is the same knob.Above, one global order puts every record in one sequence, so one consumer reads them all. Below, the same records are routed by customer into three ordered lanes, each with its own consumer. A log calls the routing value a partition key, and an SQS FIFO queue calls it a message group ID. It is the same knob.
Order globally and you get one consumer. Order per customer and you get many. Above, one global order puts every record in one sequence, so one consumer reads them all. Below, the same records are routed by customer into three ordered lanes, each with its own consumer. A log calls the routing value a partition key, and an SQS FIFO queue calls it a message group ID. It is the same knob.

Delivery semantics, and what exactly-once actually means

Three phrases describe what delivery guarantees, and one of them is usually misunderstood.

At most once. The consumer acknowledges the message before processing it. If it crashes mid-work, the message is gone. This is fast and it loses messages, and sometimes that's fine: metrics samples, best-effort notifications.

At least once. The consumer acknowledges after processing. If it crashes after doing the work but before acknowledging, it gets the message again and does the work twice. Almost every real system gives you this, including the ones marketed as something better.

Exactly once. This is what everybody wants. Kafka's transactions do provide it, in a narrow scope that the documentation states clearly. Idempotent producers drop duplicates by sequence number. Transactional producers write to several partitions atomically, so all the writes land or none do. Consumers reading with read_committed only see records below the last stable offset, the point below which no transaction is still open. So they never see uncommitted work. That's a useful guarantee, and it only holds inside a single Kafka cluster. If your processing has a side effect outside Kafka, such as a write to your database or a call to a payment API, the transaction doesn't cover it. You need something else.

So the accurate statement is this: you do not get exactly-once delivery. You get at-least-once delivery and you build idempotent processing. Idempotent means that doing the work twice has the same effect as doing it once. This is a better design anyway, because it also survives retries, replays and an operator who resets an offset.

Where the acknowledgement goes
In the first row, the consumer acknowledges before working, so a crash in between loses the message. In the second, it works before acknowledging, so a crash in between brings the message back and the work happens twice. The third row is what you build: at-least-once delivery, plus an insert of the event id before the work. The duplicate finds the id already stored and does nothing.In the first row, the consumer acknowledges before working, so a crash in between loses the message. In the second, it works before acknowledging, so a crash in between brings the message back and the work happens twice. The third row is what you build: at-least-once delivery, plus an insert of the event id before the work. The duplicate finds the id already stored and does nothing.
Moving the acknowledgement changes what a crash costs. In the first row, the consumer acknowledges before working, so a crash in between loses the message. In the second, it works before acknowledging, so a crash in between brings the message back and the work happens twice. The third row is what you build: at-least-once delivery, plus an insert of the event id before the work. The duplicate finds the id already stored and does nothing.
Back of envelopeWhat at-least-once costs, and what makes it free
100M messages/day, duplicate rate 0.1% from retries,
rebalances and redeliveries.

  duplicates per day   100M x 0.001         = 100,000

If the handler charges a card
  duplicate charges/day                    = 100,000
  → unacceptable at any rate above zero

If the handler is an idempotent upsert keyed by event id
  duplicate effects                        = 0
  cost: one unique index and one lookup per message

  ─────────────────────────────────────────────────────────
  The duplicate rate did not change. What changed is whether
  a duplicate does anything, and that is entirely a property
  of your handler rather than of the broker.

Which is why "does this broker give exactly-once" is the
wrong question, and "is my handler idempotent" is the
right one. The second question you can actually answer yes to.

When your handler is slower than the broker's patience

This failure hits both models, and it shows up in production rather than in design review. It's the same bug in two forms. Both brokers assume your handler, the code that processes one message, is quick. Both run a timer. When the timer expires, both react by doing more work, and that extra work turns a slow handler into an outage.

In a queue, the timer is the visibility timeout. When a consumer receives a message, the broker hides it from everyone else for a fixed time and waits for an acknowledgement. In SQS that time defaults to 30 seconds, and you can set it anywhere from zero to 12 hours. If you don't acknowledge in time, the broker assumes you died and gives the message to another consumer.

So if your handler sometimes takes 45 seconds and the timeout is 30, the broker hands the same message to a second worker while the first is still working on it. Both finish, and whatever the handler does happens twice. If the handler isn't idempotent, that's a duplicate charge, a duplicate email or a duplicate row.

A 45 second handler and a 30 second timeout
Worker A receives the message at 0 s, and the broker hides it for 30 s. At 30 s, A is still working, so the message becomes visible again and worker B receives it (1). A finishes at 45 s and B at 75 s, so the work happens twice (2).Worker A receives the message at 0 s, and the broker hides it for 30 s. At 30 s, A is still working, so the message becomes visible again and worker B receives it (1). A finishes at 45 s and B at 75 s, so the work happens twice (2).
The broker gives the same message to a second worker. Worker A receives the message at 0 s, and the broker hides it for 30 s. At 30 s, A is still working, so the message becomes visible again and worker B receives it (1). A finishes at 45 s and B at 75 s, so the work happens twice (2).

In a log, the timer is the poll interval. A Kafka consumer calls poll to fetch its next batch of records. max.poll.interval.ms sets the longest allowed gap between two calls, and it defaults to 300,000 milliseconds, which is 5 minutes. The documentation is explicit about what happens if you go past it. The consumer is treated as failed, and the group rebalances: it hands that consumer's partitions to another member.

The reassignment does the damage. The new owner starts from the last committed offset, which is before the slow batch. So it processes the same records again, takes just as long, goes past the interval and is declared dead too. Nothing is ever committed. The group keeps rebalancing, throughput is zero and CPU is at 100 percent. Zero throughput at full CPU is a confusing pair of symptoms to see together.

A batch slower than the poll interval
Consumer A polls 500 records at 1.2 s each, 600 s of work. At 300 s it misses the poll deadline, and the group hands its partition to consumer B (1). B starts again from the last committed offset, so it gets the same batch, and it is declared dead at 600 s (2). The committed offset never moves, so the group makes no progress while every consumer runs at full CPU.Consumer A polls 500 records at 1.2 s each, 600 s of work. At 300 s it misses the poll deadline, and the group hands its partition to consumer B (1). B starts again from the last committed offset, so it gets the same batch, and it is declared dead at 600 s (2). The committed offset never moves, so the group makes no progress while every consumer runs at full CPU.
Each new owner restarts the same batch and is declared dead too. Consumer A polls 500 records at 1.2 s each, 600 s of work. At 300 s it misses the poll deadline, and the group hands its partition to consumer B (1). B starts again from the last committed offset, so it gets the same batch, and it is declared dead at 600 s (2). The committed offset never moves, so the group makes no progress while every consumer runs at full CPU.
Back of envelopeThe same bug, both models
QUEUE: handler p99 is 45 s, visibility timeout is the 30 s default

  messages exceeding the timeout    at least 1% of 1,000/s
                                    = at least 10/s
  each gets a second worker, which also takes 45 s,
  so it is redelivered again, and again

  → extra load makes the handler slower, which pushes more
    messages past 30 s, which adds more load. The loop is
    the outage; the slow handler was only the trigger.

LOG: poll returns 500 records, each takes 1.2 s

  time to process one batch  500 x 1.2 s          = 600 s
  max.poll.interval.ms default                    = 300 s
                                                    ─────
  600 s against a 300 s limit, so the consumer is declared
  dead mid-batch, every time

  offsets committed                               = 0
  records made progress                           = 0
  CPU                                             = 100%

  Fixes, in order of preference: process fewer records per
  poll (100 x 1.2 s = 120 s, comfortably inside), or move the
  slow part out to a queue where a 45 s task is normal.
  Raising the timeout works and hides a real problem.

A queue absorbs a spike, not a deficit

People often say a queue in front of a slow service protects it. It does, but only from a spike, not from a deficit. The two look identical for the first few minutes.

In a spike, messages arrive faster than you can process them for a short time, but on average you have enough capacity. The queue holds the extra messages, and the backlog, the messages waiting in the queue, drains afterwards. In a deficit, messages arrive faster than you can process them all the time. Then the queue protects nothing. It turns a throughput problem into a latency problem, and the latency keeps growing with no limit.

Back of envelopeA backlog is a latency measurement in disguise
Arrival 1,200 msg/s. Consumer capacity 1,000 msg/s.
Deficit 200/s, and no error anywhere.

  after  1 min   backlog 12,000    wait 12 s
  after 10 min   backlog 120,000   wait 120 s
  after  1 hour  backlog 720,000   wait 720 s (12 min)

  Nothing fails. Nothing times out at the broker. Every
  message is eventually processed, correctly, far too late.

  Then the reverse, which is the number worth carrying:
  a 720,000 backlog with 1,000/s capacity and arrival
  dropping to 800/s drains at 200/s, so recovery takes
  720,000 / 200 = 3,600 s, another full hour.

  ─────────────────────────────────────────────────────────
  The drain rate is spare capacity, not total capacity, so a
  system running at 80% of capacity takes an hour to recover
  from an hour at 120%. Which is why the useful alert is on
  backlog age rather than backlog size: 720,000 means nothing
  on its own, and "the oldest message is 12 minutes old"
  means something to everyone.
An hour of deficit, then an hour of recovery
For the first hour, 1,200 messages a second arrive and 1,000 are processed. The backlog grows by 200 a second to 720,000, and the oldest message is 12 minutes old. When arrivals drop to 800 a second, the backlog drains at the 200 a second of spare capacity, and it takes another full hour to clear.For the first hour, 1,200 messages a second arrive and 1,000 are processed. The backlog grows by 200 a second to 720,000, and the oldest message is 12 minutes old. When arrivals drop to 800 a second, the backlog drains at the 200 a second of spare capacity, and it takes another full hour to clear.
The backlog grows with no errors and drains only at the spare capacity. For the first hour, 1,200 messages a second arrive and 1,000 are processed. The backlog grows by 200 a second to 720,000, and the oldest message is 12 minutes old. When arrivals drop to 800 a second, the backlog drains at the 200 a second of spare capacity, and it takes another full hour to clear.

Compaction, which turns a log into a table

One more log feature, because it removes a line people assume is fixed: the line between a stream and a table.

Retention is how long a log keeps records. Normally it deletes by age: keep seven days, drop the rest. Compaction deletes old versions instead. It keeps at least the most recent record for each key, and it throws away older records for keys that have a newer one. A record written with a null value is a tombstone. It marks the key as deleted.

Take a compacted topic of records like "user 88's address is X". If you read it from the beginning, you get the current address of every user. You get the state, not the history. The log has become a table you can rebuild from, and it's still a stream you can subscribe to for changes.

Use it when a consumer needs the current state rather than what happened. That's more often than people expect: a cache that must be refilled after a restart, a service holding a local copy of a lookup table, a search index such as Elasticsearch. Without compaction, those consumers need a snapshot from somewhere else, plus a stream of the changes since that snapshot. You then have to line up exactly where the snapshot ends and the stream begins, which is easy to get wrong. With compaction, the log is both.

The cost is that compaction removes what the log was good at. You can no longer replay history, because the records in between are gone. So it's the right choice when consumers want the latest value per key, and the wrong one when they want to reprocess a sequence of events. Some designs keep both. An events topic with time-based retention serves anyone who needs the history. A compacted topic of current state serves anyone who needs to rebuild.

A topic before and after compaction
Above, every address change for users 88, 12 and 7 is in the log. After compaction, only the latest record for each key is left. User 12's latest record has a null value, a tombstone, so user 12 counts as deleted. Reading the compacted topic from the start gives every user's current address, but the earlier changes can no longer be replayed.Above, every address change for users 88, 12 and 7 is in the log. After compaction, only the latest record for each key is left. User 12's latest record has a null value, a tombstone, so user 12 counts as deleted. Reading the compacted topic from the start gives every user's current address, but the earlier changes can no longer be replayed.
Compaction keeps the latest record per key, so the log reads as a table. Above, every address change for users 88, 12 and 7 is in the log. After compaction, only the latest record for each key is left. User 12's latest record has a null value, a tombstone, so user 12 counts as deleted. Reading the compacted topic from the start gives every user's current address, but the earlier changes can no longer be replayed.

The technologies, placed

Every product below sits somewhere on one axis: who owns the position.

Products on one axis
On the left, the broker owns the position: SQS Standard, RabbitMQ classic queues, Redis lists, and Celery and Sidekiq built on them. Next to them, SQS FIFO and RabbitMQ's consistent-hash exchange add ordering within a group. On the right, the consumer owns the position: Kafka consumer groups, Kinesis, Redpanda and Event Hubs. The middle holds Pulsar, Kafka share groups, Google Pub/Sub and NATS JetStream, which keep messages like a log and still track each message at the broker.On the left, the broker owns the position: SQS Standard, RabbitMQ classic queues, Redis lists, and Celery and Sidekiq built on them. Next to them, SQS FIFO and RabbitMQ's consistent-hash exchange add ordering within a group. On the right, the consumer owns the position: Kafka consumer groups, Kinesis, Redpanda and Event Hubs. The middle holds Pulsar, Kafka share groups, Google Pub/Sub and NATS JetStream, which keep messages like a log and still track each message at the broker.
Every product sits between a broker-owned and a reader-owned position. On the left, the broker owns the position: SQS Standard, RabbitMQ classic queues, Redis lists, and Celery and Sidekiq built on them. Next to them, SQS FIFO and RabbitMQ's consistent-hash exchange add ordering within a group. On the right, the consumer owns the position: Kafka consumer groups, Kinesis, Redpanda and Event Hubs. The middle holds Pulsar, Kafka share groups, Google Pub/Sub and NATS JetStream, which keep messages like a log and still track each message at the broker.

The broker owns the position, so these are queues. Amazon SQS Standard, RabbitMQ classic queues, Redis lists used with a blocking pop, and the task frameworks built on top of them, such as Celery and Sidekiq. They allow any number of consumers and have no replay. SQS and RabbitMQ also acknowledge each message, redeliver automatically and offer dead-letter queues. A bare Redis list has none of that, because a popped item is gone, so the framework on top has to add it.

The same, plus ordering within a group. SQS FIFO, and RabbitMQ with a consistent-hash exchange. You gain order, and the group becomes your unit of parallelism.

The consumer owns the position, so these are logs. Apache Kafka with consumer groups, Amazon Kinesis, Redpanda and Azure Event Hubs. Each one keeps order per partition, replays by offset, adds readers almost for free, and caps parallelism at the partition count. Kinesis calls its partitions shards. Google Pub/Sub and NATS JetStream sit in the middle: they can keep messages like a log, but the broker still tracks the acknowledgement of each message.

The hybrids, which are the best evidence for the thesis

Two systems show the thesis directly. They let you choose the model without changing where the data is stored.

Apache Pulsar stores a log, and each subscription chooses how it reads it. A subscription is a named reader of a topic, like a consumer group. An Exclusive subscription gives one consumer all messages in order. That's log behaviour. A Shared subscription hands messages round-robin to many consumers, each message to exactly one of them, with no ordering guarantee. That's queue behaviour. Failover keeps one active consumer, with standbys ready to take over. Key_Shared sends all messages with the same key to the same consumer, in order. That gives you many parallel consumers on one partition and still keeps per-key order. Pulsar's documentation says it directly: by choosing a subscription type, you control whether the subscription behaves more like a stream or more like a queue.

Pulsar's four subscription types
Exclusive gives one consumer every message in order. Failover does the same, with a standby, in grey, ready to take over. Shared deals the messages to three consumers in turn, with no order, like a queue. Key_Shared sends every message for one key to the same consumer, so you get parallel consumers and still keep per-key order.Exclusive gives one consumer every message in order. Failover does the same, with a standby, in grey, ready to take over. Shared deals the messages to three consumers in turn, with no order, like a queue. Key_Shared sends every message for one key to the same consumer, so you get parallel consumers and still keep per-key order.
One stored log, read as a stream or as a queue. Exclusive gives one consumer every message in order. Failover does the same, with a standby, in grey, ready to take over. Shared deals the messages to three consumers in turn, with no order, like a queue. Key_Shared sends every message for one key to the same consumer, so you get parallel consumers and still keep per-key order.

Kafka share groups come at the same idea from the other side. They were proposed in KIP-932, a Kafka Improvement Proposal, and have been production-ready since Kafka 4.2, through the share consumer API. A share group lets multiple consumers process the same partition. Each message is acknowledged on its own, the broker counts how many times it was delivered, and a consumer can release, reject or extend its hold on each one.

Look at what Kafka had to build to do that. A share group tracks the state of each record in flight. When a consumer fetches a message, it doesn't only read it, it locks it. The record moves through states: available, acquired, acknowledged and archived.

This is the thesis in working code. To make a log behave like a queue, Kafka had to move position tracking from the consumer to the broker and keep state for each message in flight. Nothing else would do, because that's the difference between the two.

A record's states in a Kafka share group
Each record starts available. A consumer that fetches it acquires it, which is a lock with a time limit (1). If the consumer acknowledges it, the record is done (2). If the consumer releases it or the lock runs out, it goes back to available for another try (3). If the consumer rejects it, or it reaches the delivery limit, it is archived and never delivered again (4).Each record starts available. A consumer that fetches it acquires it, which is a lock with a time limit (1). If the consumer acknowledges it, the record is done (2). If the consumer releases it or the lock runs out, it goes back to available for another try (3). If the consumer rejects it, or it reaches the delivery limit, it is archived and never delivered again (4).
To act like a queue, the log keeps state for every message in flight. Each record starts available. A consumer that fetches it acquires it, which is a lock with a time limit (1). If the consumer acknowledges it, the record is done (2). If the consumer releases it or the lock runs out, it goes back to available for another try (3). If the consumer rejects it, or it reaches the delivery limit, it is archived and never delivered again (4).

The method

The method, applied to image resizing
Each box is one step, and the line under it is the answer for the image resizing example from the toolkit: work, one consumer, no ordering, 1,000 workers, a dead-letter queue, and the upload id plus the output size as the key. Steps 3 and 6 are marked as the ones people usually skip. Here, step 3's answer, no ordering at all, is what makes a queue fit.Each box is one step, and the line under it is the answer for the image resizing example from the toolkit: work, one consumer, no ordering, 1,000 workers, a dead-letter queue, and the upload id plus the output size as the key. Steps 3 and 6 are marked as the ones people usually skip. Here, step 3's answer, no ordering at all, is what makes a queue fit.
Six questions, and each answer narrows the design. Each box is one step, and the line under it is the answer for the image resizing example from the toolkit: work, one consumer, no ordering, 1,000 workers, a dead-letter queue, and the upload id plus the output size as the key. Steps 3 and 6 are marked as the ones people usually skip. Here, step 3's answer, no ordering at all, is what makes a queue fit.

1. Work or history? Check whether the messages are imperatives or past-tense facts. Work goes in a queue and history in a log, and a system with both is normal.

2. How many independent consumers, now and plausibly later? One consumer that does the work points to a queue. Several teams with unrelated interests point strongly to a log, because fanout is free there.

3. Ordered relative to what? Ask for the scope, not whether you need ordering. This step turns a 300 per second ceiling into no ceiling, because the answer is almost never "globally".

4. What concurrency does the throughput require? Multiply the rate by the time each message takes. If you picked a log, compare that number with your partition count before you go further.

5. What happens to a message that always fails? Name the dead-letter path. In a queue it's a setting. In a log you build it.

6. What is the idempotency key? Delivery is at least once, whatever the marketing says, so the handler has to make a duplicate harmless. Name the key and where it is stored.

Worked examples, start to finish

Four systems, and each one fails in a different way: a ceiling, a fanout topology, an ordering claim that is too broad, and a guarantee that doesn't exist.

Resizing uploaded images

Users upload photos, and you need four sizes of each. The peak is 5,000 images a second. Each image takes 200 milliseconds of CPU for all four sizes, there's no ordering requirement, and each job is independent.

The team already runs Kafka, so the images topic goes into Kafka. It works in staging. In production, throughput stays at 60 images a second, and adding machines changes nothing. The topic has 12 partitions, so consumers 13 onwards get no work at all.

The image resizing worksheet in the toolkit explains why. This is work. It's embarrassingly parallel, meaning each image can be processed on its own with no coordination, and it has no order. A log's defining feature is a constraint this problem doesn't have.

Naive

Add more consumers, then more partitions

The first response is to add consumers, which does nothing. The second is to raise the partition count, which works. So this isn't wrong, but you have to keep doing it as traffic grows. You now need 1,000 partitions for a workload with no ordering requirement. In Kafka, you can increase the partition count but never decrease it, so the number is permanent. You have also taken on head-of-line blocking in every one of those partitions.

Senior

Put the work in a queue and leave the events in the log

Notice that two different things were mixed up. "Image uploaded" is history, and it belongs in the log, where the analytics and moderation teams can also read it. "Resize this image" is work, and it belongs in a queue. There, 1,000 workers can pull messages independently, one slow image blocks nobody, and an image that always fails goes to the dead-letter queue on its own.

The cost is two systems in the path, plus a small component that reads the log and puts the work on the queue. That component joins the two systems. It has to be idempotent, because it will sometimes see a record twice.

History in the log, work in a queue
The upload service writes 'image uploaded' to Kafka. Analytics and moderation read it as their own consumer groups. A small enqueuer, a third group, turns each event into a 'resize this image' message on a queue (1). 1,000 workers pull from the queue (2), and an image that keeps failing goes to the dead-letter queue (3).The upload service writes 'image uploaded' to Kafka. Analytics and moderation read it as their own consumer groups. A small enqueuer, a third group, turns each event into a 'resize this image' message on a queue (1). 1,000 workers pull from the queue (2), and an image that keeps failing goes to the dead-letter queue (3).
The log keeps the upload event, and a queue hands out the resize jobs. The upload service writes 'image uploaded' to Kafka. Analytics and moderation read it as their own consumer groups. A small enqueuer, a third group, turns each event into a 'resize this image' message on a queue (1). 1,000 workers pull from the queue (2), and an image that keeps failing goes to the dead-letter queue (3).
Staff

Ask whether the fan-out belongs in the message at all

Question the assumption that one message is one unit of work. Here one upload produces four resizes. So each worker takes a message holding four tasks that run one after another, and the upload isn't done until all four have run.

Split the work when you enqueue it: one message per output size, keyed by upload and size. Now the four sizes run in parallel on different workers. The total CPU is the same, so you still need about 1,000 workers, but the thumbnail no longer waits behind the larger sizes. And if the largest size fails, it doesn't block the thumbnail the user is waiting to see.

Here are the numbers. In one message, the thumbnail waits for every size that runs before it, up to the full 200 ms. Split up, the thumbnail takes only its own time, about 40 ms if it's the cheapest of the four, and the total CPU is unchanged. You bought lower latency by making the messages smaller, not by adding machines.

One message per size
Each bar is the CPU time for one size. Above, one message runs all four sizes in turn, and with the thumbnail last, it is ready at 200 ms. Below, four messages run on four workers at once, and the thumbnail is ready at 40 ms. The total CPU, 200 ms, is the same in both. The split between sizes is assumed.Each bar is the CPU time for one size. Above, one message runs all four sizes in turn, and with the thumbnail last, it is ready at 200 ms. Below, four messages run on four workers at once, and the thumbnail is ready at 40 ms. The total CPU, 200 ms, is the same in both. The split between sizes is assumed.
Split up, the thumbnail no longer waits for the large sizes. Each bar is the CPU time for one size. Above, one message runs all four sizes in turn, and with the thumbnail last, it is ready at 200 ms. Below, four messages run on four workers at once, and the thumbnail is ready at 40 ms. The total CPU, 200 ms, is the same in both. The split between sizes is assumed.

You give up two things: you send four times the messages, and you have a new question of when the upload is finished. "The upload is fully processed" is now built from four separate acknowledgements instead of one. If anything downstream needs that fact, you have to track it somewhere, and that tracking is extra code and extra state. So this is right when each size is useful on its own, and wrong when nothing can go ahead until all four exist.

An order that five teams care about

An order is placed. Fulfilment needs to ship it and analytics needs to count it. The recommendation model wants it as a training signal, fraud wants to score it, and marketing wants to send a confirmation.

The team already runs SQS, so they create an orders queue, and fulfilment consumes it. Then analytics wants the same orders and adds a consumer to the same queue. Now the two split the orders between them. Half are shipped and not counted, and half are counted and not shipped. So somebody puts SNS in front, with five queues behind it, and now there's a fanout topology to run.

Two consumers on one queue
Orders 1 to 6 go into one SQS queue. Fulfilment receives 1, 3 and 5, and analytics receives 2, 4 and 6. Each sees half the orders, so half are shipped and not counted, and half are counted and not shipped. Nothing reports an error.Orders 1 to 6 go into one SQS queue. Fulfilment receives 1, 3 and 5, and analytics receives 2, 4 and 6. Each sees half the orders, so half are shipped and not counted, and half are counted and not shipped. Nothing reports an error.
Consumers on one queue split the messages. They don't each get a copy. Orders 1 to 6 go into one SQS queue. Fulfilment receives 1, 3 and 5, and analytics receives 2, 4 and 6. Each sees half the orders, so half are shipped and not counted, and half are counted and not shipped. Nothing reports an error.

That works until six months later, when the recommendation model turns out to have had a bug for three weeks and needs to reprocess. The data is gone, because each queue deleted its messages when they were acknowledged.

This is history, not work. It goes in a log, and the five consumers become five consumer groups with their own offsets. The fanout worksheet in the toolkit shows the saving you get straight away. Replay is the saving that matters more.

Ordering, and the requirement nobody checked

A payments system processes account transactions. The requirement arrives as "transactions must be processed in order". That sounds absolute, so the design uses one message group. The throughput ceiling is about 300 a second, or 3,000 with batching. The business needs 20,000.

One question resolves it: in order relative to what?

Transactions for the same account must be in order, because a withdrawal after a deposit can have a different outcome from the reverse. Transactions for different accounts have no relationship at all. Ordering them relative to each other is a guarantee nobody asked for and nobody can observe.

So the message group is the account, not the whole queue. With 500,000 active accounts, you have 500,000 independent ordered streams, and the ordering ceiling disappears. The design is also more correct than before, because the ordering guarantee is now stated exactly instead of assumed for everything.

Two things to note.

With ordering per key, a hot key, one that gets far more traffic than the rest, is a hot partition. You can't spread it, because spreading it would break its order. A single account with very high volume, such as a corporate settlement account, needs its own handling.

And the ordering scope becomes part of your interface. Once consumers rely on per-account ordering, changing the key breaks them, and no type system will catch it. So write the ordering scope down where the schema lives.

Publishing an event and writing to the database

The last one is a bug rather than a choice, and almost every first implementation has it.

Your handler does two things. It writes the order to the database, and it publishes "order placed" to the broker. These are two writes to two separate systems, and no transaction covers both. So there are four outcomes, and two of them are wrong. If the database write succeeds and the publish fails, you have an order that nothing downstream knows about. If the publish succeeds and the database write rolls back, five consumers act on an order that doesn't exist.

Kafka's transactions don't help here, and its documentation says so. The guarantees hold within a Kafka cluster, and a side effect outside Kafka, such as a database write, is not covered.

Naive

Write to the database, then publish, and log any publish failure

Almost everyone writes this first. It works most of the time, and that's the problem. The publish fails rarely: a broker hiccup, a timeout, a pod stopped between the two calls. When it does, the order exists, and no downstream system will ever hear about it. Nothing detects this. There's no error to show the user, and the log line scrolls past. The failure is silent and permanent, and it happens exactly as often as a publish fails.

Senior

An outbox table written in the same transaction

Write the order, and a row in an outbox table, in one database transaction, so both happen or neither does. A separate process, the relay, reads unpublished outbox rows, publishes them and marks them done. Now the all-or-nothing decision happens inside one database, where transactions work. Publishing becomes a background job that can retry, instead of a step squeezed between two calls.

The costs are another moving part, a table that grows and needs pruning, and at-least-once publishing, because the relay can crash after publishing and before marking the row. That's fine, since your consumers are already idempotent.

Staff

Stop writing the event at all, and derive it

Question the assumption that the application should publish events at all. The database already keeps an ordered, durable record of every change: its own write-ahead log, which it writes before it changes any data. A replication slot keeps that log until CDC has read it. Change data capture (CDC) reads that log and publishes it, with a tool such as Debezium. So the event is a consequence of the commit, not a second action that may or may not happen alongside it.

This gives you what the outbox only approximates. Nothing can commit without producing an event. The connector reads every change in commit order, and each row's changes keep that order. And no application code can forget to publish, because no application code publishes.

The cost is large enough that this isn't automatically right. Your events are now shaped like your tables instead of like your business events, so consumers depend on your schema, and renaming a column breaks them. The usual fix is a translation step that turns row changes into business events. That's extra work, and it puts you halfway back to the outbox. So the rule is CDC when the consumers are your own pipelines and analytics, and an outbox when the events are a published contract that other teams build against.

Three ways to publish an order event
In the naive panel, the handler writes the database (1) and then publishes (2), so a crash between the two loses the event. In the senior panel, the order and its outbox row commit in one transaction (1), and a relay publishes the row afterwards (2). In the staff panel, the handler only writes the database (1), and CDC reads the write-ahead log and publishes every commit (2).In the naive panel, the handler writes the database (1) and then publishes (2), so a crash between the two loses the event. In the senior panel, the order and its outbox row commit in one transaction (1), and a relay publishes the row afterwards (2). In the staff panel, the handler only writes the database (1), and CDC reads the write-ahead log and publishes every commit (2).
Only the outbox and CDC tie the event to the commit. In the naive panel, the handler writes the database (1) and then publishes (2), so a crash between the two loses the event. In the senior panel, the order and its outbox row commit in one transaction (1), and a relay publishes the row afterwards (2). In the staff panel, the handler only writes the database (1), and CDC reads the write-ahead log and publishes every commit (2).

Where it goes wrong

These are ordered by how often they turn up.

1. Using a log as a work queue

This gives you the parallelism ceiling and head-of-line blocking, both from the same cause. The sign is a topic full of imperatives, or a partition count that keeps going up for a workload with no ordering requirement. If you're already committed to Kafka, share groups are now a real alternative. They work by moving position tracking to the broker.

2. Using a queue as an event log

The signs are two consumers splitting messages instead of both receiving them, a fanout topology that keeps growing, and no replay. Teams find out when someone needs to reprocess and the data is gone.

3. Claiming ordering you do not need

"In order", without "relative to what", turns a parallel problem into a serial one. In the payments example, it capped the design at one message group, about 300 a second. Ask for the narrowest scope that correctness needs.

4. Believing in exactly-once

Delivery is at least once. Kafka's transactional guarantees are real, but they hold only inside one Kafka cluster and stop at any side effect outside it. If you build idempotent handlers with an explicit key, the question stops mattering.

5. Dual writes

This is writing to the database and publishing separately, with no transaction across them. Use an outbox or CDC. Treat this as a default rule, not a case-by-case decision, because the failure is silent.

6. Retention chosen as a storage setting

A log's retention is not a disk decision. It is how far back you can rebuild a broken consumer. With 24 hours of retention, a bug that started on Friday evening and was noticed on Monday morning can't be fixed from the log. With seven days, you have to notice within a week. Pick retention from how long it takes you, in practice, to notice a bug, and then price the disk, not the other way round.

Retention against detection time
A consumer bug starts on Friday at 18:00 and is noticed on Monday at 09:00, 63 hours later. With 24 hours of retention, the log only goes back to Sunday at 09:00, so the first 39 hours of bad output can't be rebuilt from it. Seven days of retention reaches back past the start of the bug.A consumer bug starts on Friday at 18:00 and is noticed on Monday at 09:00, 63 hours later. With 24 hours of retention, the log only goes back to Sunday at 09:00, so the first 39 hours of bad output can't be rebuilt from it. Seven days of retention reaches back past the start of the bug.
Retention has to reach back to when the bug started. A consumer bug starts on Friday at 18:00 and is noticed on Monday at 09:00, 63 hours later. With 24 hours of retention, the log only goes back to Sunday at 09:00, so the first 39 hours of bad output can't be rebuilt from it. Seven days of retention reaches back past the start of the bug.

7. A handler slower than the broker's patience

These are the visibility timeout in a queue and max.poll.interval.ms in a log. Both default to something shorter than people assume, both treat a slow consumer as a dead one, and both respond by creating more work. In a queue, the extra work is a duplicate delivery. In a log, it's a rebalance that processes the batch again. Before you ship, compare both timers with your p99 handler time, the time within which 99 percent of messages finish, not with your average.

8. Alerting on backlog size instead of backlog age

Queue depth and consumer lag both go up for unrelated reasons, including a producer speeding up and somebody resetting an offset on purpose. Neither number means anything to a person without a drain rate next to it. Convert them to time and alert on that. And remember that recovery runs at spare capacity. A system at 80 percent of capacity takes an hour to recover from an hour at 120 percent.

9. No dead-letter path

In a queue, this is a setting you skipped. In a log, it's a component you didn't build. The first record that can never be processed will stop its partition until someone steps in by hand.

10. Ignoring the hot key that ordering created

If you order by key, you can't spread that key, so the busiest key has to fit inside one partition's throughput. This is the one skew problem where hashing can't help, because the ordering requirement is what prevents it.

If you memorise nothing else

factwhy it matters
A queue: the broker remembers who has whatper-message state, so unlimited consumers and free retry
A log: each reader remembers where it isone offset per partition, so replay and fanout are free
Every other difference is a consequence of that oneyou can derive the feature table instead of memorising it
The question is "work or history," not "which is faster"imperative or past tense is a reliable tell
A log's max useful consumers equals its partition countconsumer 13 of 12 partitions is assigned nothing
Kafka partition count can be increased, never reducedso a number chosen for throughput is permanent
In a log you commit a position, not a messageone bad record blocks everything behind it
One 30 second record delays 30,000 behind it, or 1 in a queuesame input, two blast radii
A queue must copy for fanout, a log can share5 consumers means 5 copies or 1
Ordering scope and parallelism unit are one knoborder globally and you get one consumer
An SQS message group and a Kafka key do the same job~300/s per group unbatched, so more groups is more throughput
Ask "in order relative to what," not "do we need order"the answer is almost never "globally"
Delivery is at least once. Build idempotent handlers0.1% duplicates on 100M/day is 100,000 a day
Kafka transactions hold inside Kafka, not to your databaseexternal side effects need an outbox or CDC
Writing to a database and publishing is a dual writeit fails silently, and the fix is a rule not a judgement
Retention is your rebuild window, not a disk settingpick it from your detection time
SQS visibility timeout defaults to 30 s, max 12 hoursa 45 s handler gets a second worker on the same message
Kafka max.poll.interval.ms defaults to 5 minutesexceed it and the group rebalances and reprocesses
Both brokers answer a slow consumer with more workwhich is why these incidents escalate rather than plateau
A queue absorbs a spike, never a deficit200/s short for an hour is a 12 minute wait, with no errors
Backlogs drain at spare capacity, not total capacityan hour at 120% load takes an hour to clear at 80%
Compaction keeps the last value per keyso the log becomes a table you can rebuild state from
Compaction and replay are mutually exclusiveintermediate records are gone, so keep both topics if needed
Pulsar subscriptions and Kafka share groups choose the modelwhich proves the distinction is about who tracks position

What is expected at each level

Mid-level

Know that a queue delivers each message to one consumer and forgets it afterwards, and that a log keeps records so several consumers can read the same ones. Know what a dead-letter queue is for. Be able to name Kafka and SQS or RabbitMQ and say which is which.

You are not expected to raise the parallelism ceiling, head-of-line blocking or delivery semantics unprompted. You are expected to answer sensibly when asked. If you're asked what happens when a second team wants these events too, the answer is short. "With a queue they would compete for messages, so I would need a fanout, or a log where each team has its own position" is a good mid-level answer.

The mistake to avoid is reaching for whichever technology is already installed without asking whether the messages are tasks or facts.

Senior

You drive this, and three things must appear unprompted.

Work or history, stated as the reason for the choice. Don't say "we will use Kafka". Say "these are facts several teams consume, so a log, and the emails are tasks, so a queue." Naming both in one design is a good sign, not a complication.

The concurrency arithmetic against the partition count. Rate times duration gives the workers you need. If that's more than your partition count, say so. This is the most common miss at senior level, and nobody sees it until production.

Idempotency, with a named key. Say that delivery is at least once, and name the key and where it lives. "We will use exactly-once" invites the follow-up you don't want.

And when you're asked how you would monitor it, answer in units of time: backlog age, or lag as the number of seconds the consumer is behind. A record count means nothing without a drain rate.

Two answers are disqualifying. One is publishing an event and writing to the database as two separate operations with no outbox. The other is claiming global ordering without noticing that it caps you at one consumer.

Staff+

The question moves from choosing a broker to deciding what the messages mean.

Question the ordering requirement. "In order relative to what?" is the most useful question here. The answer usually turns a serial design into a parallel one, and it makes the guarantee more precise rather than weaker. Then point out that the ordering scope is now part of the published interface.

Treat dual writes as a rule, not a case. Any handler that writes to a data store and publishes separately is wrong by default, and an outbox or CDC is the standard answer. The failure is silent, so neither testing nor users will catch it.

Pick retention from detection time. That's how long it takes a person to notice a bad consumer, plus a margin. It's a reliability number that happens to be expressed in gigabytes. And know that retention has a second mode. Compaction lets a consumer that needs current state rebuild from the log itself, and that removes a component from the design.

Compare the handler's p99 against the broker's timers. The visibility timeout and max.poll.interval.ms are the two settings most likely to turn a slow week into an incident. Both brokers respond to a slow consumer by giving it more work. If you say this in the design review, you don't have to say it in the postmortem.

Know that the models are separate from the products. Pulsar chooses the model per subscription, and Kafka share groups add per-message state at the broker to a log. So "we already run Kafka" is not automatically an argument for using log behaviour for work.

And say what you would not build. Each of these can cost a team a quarter.

The first is a partition count raised into the thousands for a workload with no ordering requirement, when a queue had no such number. The second is a hand-built dead-letter and retry framework on top of a log, rebuilding what a queue does with one setting. The third is a fanout of one queue per consumer for events that six teams read, which writes every event six times and loses replay.

The fourth is a custom deduplication service built to manufacture exactly-once, when a unique index on an event id in the consumer's own database was the whole answer. The fifth is a second message broker adopted for queue behaviour, before anyone checked whether the one already running offers it. And the sixth is an event schema taken straight from database rows, which turns every future column rename into an outage downstream.

Sources

Every figure attributed to a project or vendor below comes from that published source. The concurrency, fanout, ordering and duplicate arithmetic is worked in the article with its inputs stated.

  • Messaging concepts, Apache Pulsar. The four subscription types, Exclusive, Failover, Shared and Key_Shared, and what each does with ordering and consumer count. And that choosing a subscription type is how you control whether a subscription behaves more like a stream or more like a queue.
  • KIP-932, Queues for Kafka and Kafka queue semantics with the share consumer API, and the Apache Kafka 4.2.0 release announcement, which made share groups production-ready. Share groups allowing several consumers to process one partition, and per-message acknowledgement with delivery counts. The acquire, release, reject and extend operations. And the per-record states of available, acquired, acknowledged and archived.
  • Troubleshoot FIFO throttling issues, high throughput for FIFO queues and high throughput mode for FIFO queues, Amazon SQS. The 300 transactions per second per API action limit without high throughput mode, and up to 3,000 messages per second with batching. And that in high throughput mode SQS hashes each message group ID to one partition. Each partition handles up to 300 messages per second per API action, or 3,000 with batching, so throughput scales with the number of groups.
  • Transactions and exactly-once semantics and Exactly-once semantics with Kafka transactions. Idempotent producers deduplicating by sequence number. Transactional producers writing atomically across partitions, and read_committed consumers seeing only records below the last stable offset. And that transactions are supported inside a single Kafka cluster and do not cover externally observable side effects, for which the transactional outbox pattern is the named remedy.
  • Amazon SQS visibility timeout, Amazon SQS. The 30 second default, and the range of zero seconds to 12 hours. That the timeout begins when the message is delivered. That a message not deleted before it expires becomes visible again and can be received by another consumer. And that extending the timeout does not reset the 12 hour ceiling measured from first receipt.
  • Consumer configurations, Apache Kafka. That max.poll.interval.ms is the maximum delay between calls to poll under consumer group management, and that its default is 300,000 milliseconds. And that if poll is not called before it expires the consumer is considered failed and the group rebalances so its partitions are reassigned to another member.

Spot a mistake, or something unclear? . Or get in touch.

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.