.NET Architecture & System Design Interview Question #41

What is the difference between a queue and a publish-subscribe model?

Caching, CDN, Queues & Asynchronous Processing Junior Beginner

Quick Interview Answer

A queue commonly represents competing consumers: one logical message is processed by one consumer from a consumer group. Publish-subscribe distributes an event to multiple independent subscribers that each need to react.

Detailed Explanation

A queue commonly represents competing consumers: one logical message is processed by one consumer from a consumer group. Publish-subscribe distributes an event to multiple independent subscribers that each need to react.

The exact semantics depend on the messaging technology, but the design question is whether the work should be performed once or whether several independent consumers should receive the event.

Code Example

Queue:
Message -> [Worker A OR Worker B]

Publish/Subscribe:
Event -> Billing
      -> Analytics
      -> Notification