Work queues vs publish/subscribe

Queues, Kafka and event-driven systems Junior Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Pick the fix

OrderPlaced must reach billing, shipping and analytics, each processing every order once. Design?

Options
Hint 1 of 1

Should each service see every order?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Publish to one topic; each service uses its own consumer group

Correct. Every group gets every event; within a group, instances share the work.

A topic keeps one log that every consumer group reads in full. Each service gets its own group, so all three see every order, and instances within a group share the partitions.

Why not the others?
  • B One queue that all three services read from. Each message would reach only one of the three.
  • C The order service calls all three over HTTP. Couples the order service to every consumer's availability.
  • D Redis pub/sub. Disconnected subscribers lose events.

30-second answer

In a work queue each message goes to one of several competing workers, which spreads load: resize these images, send this email. In publish/subscribe each message goes to every subscribing group, which fans out one event to independent consumers: OrderPlaced goes to billing, shipping and analytics. Kafka does both at once: within a consumer group, partitions are shared like a queue; each separate group receives every message like pub/sub.

Practise saying it · 30 s. No recording, just a timer

Queue or pub/sub?

Say your answer out loud, then check which of these points you covered:

  • Queue: one consumer per message
  • Pub/sub: every subscriber
  • Kafka groups do both
  • Commands vs events

Deep dive

RabbitMQ: queues for work; exchanges (fanout, topic) for pub/sub routing.

Pub/sub decouples producers from consumers: adding a subscriber doesn't change the producer.

Redis pub/sub drops messages for subscribers that aren't connected; Redis streams keep them.

Commands ('ShipOrder') usually go to one handler; events ('OrderPlaced') to many.

Common mistakes

  • Using pub/sub for jobs that must run exactly one time each.
  • Fire-and-forget pub/sub for data that can't be lost.
  • One giant topic that every service reads and filters.

Senior take & follow-ups

Contrast one-of-N with all-of-N delivery, give an example of each, and explain Kafka's groups.

Follow-up questions

Think of your answer first, then open the hint.

  1. How does Kafka give both models?

    Show hint

    Partitions are split within a group; every group gets all messages.

  2. Command vs event?

    Show hint

    A command asks one service to act; an event states a fact others may react to.

Suggest a fix if something here is wrong or out of date.