How does the Observer pattern scale in event-driven and distributed systems?
Answer
The classic GoF Observer has limitations at scale: the subject holds direct references to observers, making it synchronous, in-process, and tightly coupled. In event-driven architectures, this evolves into a publish-subscribe (Pub/Sub) model with a message broker (Kafka, RabbitMQ, Redis Pub/Sub) as the intermediary. Publishers emit events to a topic; subscribers consume from topics independently. This decouples producers and consumers completely — they don't know about each other, can run in separate processes, and can scale independently. Additional capabilities emerge: durable subscriptions (events are stored and can be replayed), fan-out (one event to thousands of consumers), and back-pressure. In microservices, this becomes the Event-Driven Architecture (EDA) pattern where services communicate exclusively through domain events, enabling loose coupling and eventual consistency across services.
Previous
What is the difference between dependency injection and the Service Locator pattern?
Next
How can you use the Composite and Visitor patterns together?
More Design Patterns (Gang of Four) Questions
View all →- Advanced How do you implement a thread-safe Singleton using double-checked locking?
- Advanced How do the SOLID principles relate to GoF patterns?
- Advanced What is the difference between GoF anti-patterns and the patterns themselves?
- Advanced How are GoF patterns used in modern frameworks like Spring and Django?
- Advanced What criteria should guide pattern selection?