SystemExpertsSystemExperts
Pricing

Patterns

35 items

Horizontal Scaling Pattern

15mbeginner

Retry with Backoff Pattern

15mbeginner

Queue-based Load Leveling Pattern

20mintermediate

Replication Pattern

25mintermediate

Caching Strategies Pattern

25mintermediate

Fan-out Pattern

20mintermediate

Fan-in Pattern

20mintermediate

Persistent Connections Pattern

20mintermediate

Load Balancing Pattern

20mintermediate

Circuit Breaker Pattern

20mintermediate

Bloom Filters Pattern

20mintermediate

Time-Series Storage Pattern

20mintermediate

Bulkhead Pattern

20mintermediate

Batch Processing Pattern

20mintermediate

Write-Ahead Log Pattern

20mintermediate

API Gateway Pattern

20mintermediate

Backend for Frontend Pattern

20mintermediate

Sidecar Pattern

20mintermediate

Idempotency Pattern

20mintermediate

Rate Limiting Pattern

20mintermediate

Backpressure Pattern

20mintermediate

Pub/Sub Pattern

25mintermediate

Eventual Consistency Pattern

25mintermediate

Sharding Pattern

25madvanced

Conflict Resolution Pattern

25madvanced

Strong Consistency Pattern

30madvanced

Leader Election Pattern

25madvanced

Consensus Protocols Pattern

30madvanced

Stream Processing Pattern

25madvanced

Change Data Capture Pattern

25madvanced

Distributed Locking Pattern

25madvanced

Two-Phase Commit Pattern

25madvanced

LSM Trees Pattern

25madvanced

Event Sourcing Pattern

30madvanced

CQRS Pattern

28madvanced
System Design Pattern
Communicationpub-submessagingdecouplingtopicssubscribersintermediate

Pub/Sub Pattern

Decoupled message distribution through topics

Used in: Kafka, Redis Pub/Sub, Google Pub/Sub|25 min read

Summary

The Publish/Subscribe pattern decouples message producers (publishers) from consumers (subscribers) through an intermediary message broker. Publishers send messages to named topics without knowing who will receive them, while subscribers express interest in one or more topics and receive only relevant messages. This decoupling enables scalable, flexible communication in distributed systems and is the foundation of event-driven architectures.

Key Takeaways

Decoupling Through Topics

Publishers and subscribers never communicate directly. Instead, they interact through named topics managed by a message broker. This loose coupling is fundamental to microservices architectures.

Dynamic Discovery and Fan-out

Subscribers can dynamically join or leave topics at runtime without affecting publishers or other subscribers. When a message is published, the broker automatically fans it out to all active subscribers.

At-Least-Once vs Exactly-Once Semantics

Most pub/sub systems guarantee at-least-once delivery: messages may be delivered multiple times during failures. This requires subscribers to implement idempotent message handlers.

In traditional point-to-point communication, services make direct requests to each other. This creates tight coupling: availability coupling, temporal coupling, knowledge coupling, and scalability limitations.

Pub/Sub Architecture

Summary

The Publish/Subscribe pattern decouples message producers (publishers) from consumers (subscribers) through an intermediary message broker. Publishers send messages to named topics without knowing who will receive them, while subscribers express interest in one or more topics and receive only relevant messages. This decoupling enables scalable, flexible communication in distributed systems and is the foundation of event-driven architectures.

Key Takeaways

Decoupling Through Topics

Publishers and subscribers never communicate directly. Instead, they interact through named topics managed by a message broker. This loose coupling is fundamental to microservices architectures.

Dynamic Discovery and Fan-out

Subscribers can dynamically join or leave topics at runtime without affecting publishers or other subscribers. When a message is published, the broker automatically fans it out to all active subscribers.

At-Least-Once vs Exactly-Once Semantics

Most pub/sub systems guarantee at-least-once delivery: messages may be delivered multiple times during failures. This requires subscribers to implement idempotent message handlers.

Message Ordering Guarantees

Global message ordering across all publishers is impossible in distributed pub/sub systems. Most systems guarantee ordering per partition or per publisher, not globally.

Push vs Pull Consumption Models

Pub/sub systems use either push (broker sends to subscribers) or pull (subscribers fetch from broker) models. Choose based on latency and backpressure requirements.

Topic Design and Granularity

Topic granularity significantly impacts system performance and flexibility. Fine-grained topics enable precise subscriptions but increase overhead.

Pattern Details

In traditional point-to-point communication, services make direct requests to each other. This creates tight coupling: availability coupling, temporal coupling, knowledge coupling, and scalability limitations.

Pub/Sub Architecture

Trade-offs

AspectAdvantageDisadvantage

Premium Content

Sign in to access this content or upgrade for full access.