SA-301a · Module 3

Pub/Sub Topologies

3 min read

Pub/sub is the communication pattern where publishers emit events without knowing who consumes them, and subscribers process events without knowing who produced them. The decoupling is the value. But the topology — how publishers, brokers, and subscribers are arranged — determines the system's throughput, ordering guarantees, and failure characteristics. Three topologies dominate production systems, and choosing the wrong one is a load-bearing mistake.

  1. Fan-Out One publisher, many subscribers, each receiving every event. Use case: an order event triggers inventory update, notification, and analytics simultaneously. Each subscriber processes independently. Failure in one subscriber does not affect the others. The topology scales with subscriber count because subscribers are parallel and independent.
  2. Competing Consumers One publisher, many subscribers in a consumer group, each receiving a partition of events. Use case: high-throughput processing where a single consumer cannot keep up. The broker distributes events across consumers in the group. Ordering is guaranteed within a partition but not across partitions. Scale by adding consumers up to the partition count.
  3. Event Routing Events are routed to specific subscribers based on content or metadata — topic-based routing, content-based filtering, or header matching. Use case: different event types require different processing pipelines. Order events go to the fulfillment service. Payment events go to the billing service. Routing reduces processing waste by sending events only to subscribers that need them.