Patterns
35 items
35 items
Distributing writes to many readers efficiently
Fan-out is a messaging pattern where a single message is distributed to multiple consumers simultaneously. When a producer publishes a message, it's delivered to all subscribed consumers in parallel, enabling broadcast communication. This pattern is fundamental to notification systems (one post notifies all followers), event-driven architectures (one order event triggers inventory, shipping, and billing services), and cache invalidation (one update invalidates caches across all servers). Fan-out enables loose coupling since producers don't need to know who or how many consumers exist.
A single message from one producer reaches many consumers simultaneously. This is the opposite of load balancing where messages go to one of many workers. Every subscriber receives every message.
Producers don't know how many consumers exist or who they are. Consumers can be added or removed without changing producer code. This loose coupling enables independent scaling and deployment.
All consumers receive and process the message concurrently. This maximizes throughput when multiple systems need to react to the same event. Total processing time is the slowest consumer, not the sum.
Modern applications need to notify multiple systems when something happens:
E-commerce Order Example: When a customer places an order, you need to: - Update inventory (reserve items) - Process payment (charge credit card) - Send confirmation email - Update analytics (track conversion) - Notify warehouse (prepare shipment) - Update recommendation engine (purchase history)
Without fan-out, you would need synchronous calls to each system, creating tight coupling and slow response times.
With fan-out, the Order Service publishes one message and returns immediately. All downstream processing happens asynchronously and in parallel. Response time drops from sum of all calls to just the publish time.