Observer
Description
The observer pattern decouples who has state from who cares about state changes. A subject doesn’t have to know which components depend on it; observers don’t have to poll. Instead, observers register their interest, and the subject notifies them when state changes. This inverts the dependency direction in the obvious way: the subject pushes to the observers it never had to enumerate at design time. The shape generalizes far beyond OOP. Pub-sub messaging systems, event-driven UIs, biological signaling cascades, reactive frameworks, blockchain mempool propagation, and news feeds are all observer-shaped at the structural level: one source-of-changes, many subscribers, an explicit subscription mechanism, and a notification payload that carries enough context for the observer to act.Triggers
User-initiated: User describes one-to-many fanout, wanting components to “react when X happens” without the subject knowing about each reactor. Vocabulary cues: “notify,” “publish,” “subscribe,” “listen for,” “fire an event when,” “react to change in.” Agent-initiated: Agent notices polling loops, repeated state checks, or tight coupling between a state-holder and many consumers of that state. Candidate inference: “invert this; let the consumers register with the state-holder and get pushed updates.” Situation-shape signals: UI views that need to stay in sync with model changes. Components that currently poll. Cross-cutting “when X happens, do Y, Z, W” rules that are tangled across the codebase. Event-sourcing or audit-log requirements.Exclusions
- Single subscriber, stable coupling — if there’s exactly one consumer and the relationship is permanent, the indirection of observer is overhead without payoff; direct call is clearer.
- Synchronous order-sensitive logic — observers fire in unspecified or implementation-dependent order; if the dependents must execute in a specific sequence with specific interleavings, observer obscures the contract.
- High-frequency state with low-value notifications — pushing every change quickly overwhelms observers with noise; either downsample at the subject or switch to a pull-based protocol (the inverse).
- Observers with side-effects that escape the system — if observer reactions can themselves trigger arbitrary further events, debugging the cascade becomes pathological. Mediator + explicit ordering is sometimes the cleaner shape.
Structure
Relationships
- feedback-loop — when an observer’s reaction eventually affects the subject again, you have an observer-based feedback loop; the polarity (amplifying vs damping) decides whether the system stabilizes or runs away.
- multi-channel-ingest — observer is the one-to-many sibling; multi-channel-ingest is many-to-one. Both show up in event-bus architectures with the bus as the mediator.
- mediator — mediator and observer are dual: mediator centralizes coordination; observer decentralizes notification. Many message-bus systems are both at once (bus = mediator; subscriptions on the bus = observer).
- cadence — observer-driven systems have an event-cadence; recognizing the cadence is load-bearing for thinking about throughput.
- backpressure — observer’s default behavior (push-on-every-change) is unbounded; sustained systems need backpressure on the notification path.
Examples
DOM event listeners · computer-science
DOM event listeners · computer-science
addEventListener is observer registration.Biological signaling · biology
Biological signaling · biology
Alberts, B., Johnson, A., Lewis, J., Raff, M., Roberts, K., & Walter, P. Molecular Biology of the Cell. Garland Science / W. W. Norton (multiple editions). · biology
Alberts, B., Johnson, A., Lewis, J., Raff, M., Roberts, K., & Walter, P. Molecular Biology of the Cell. Garland Science / W. W. Norton (multiple editions). · biology
Erlang/OTP `gen_event` · computer-science
Erlang/OTP `gen_event` · computer-science
Fenby, J. (1986). The International News Services: A Twentieth Century Fund Report. Schocken Books. · journalism-media-studies-and-communication
Fenby, J. (1986). The International News Services: A Twentieth Century Fund Report. Schocken Books. · journalism-media-studies-and-communication
Gamma, Helm, Johnson, Vlissides (1994), Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four). Behavioral pattern, ch. 5. · computer-science
Gamma, Helm, Johnson, Vlissides (1994), Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four). Behavioral pattern, ch. 5. · computer-science
mediator routes peers through a coordinator (different topology); request-response has the caller awaiting a reply (different temporal shape). Reversing the direction or changing either contrast would make it a different pattern.Granovetter, M. (1978). Threshold Models of Collective Behavior. American Journal of Sociology, 83(6), 1420–1443. · sociology
Granovetter, M. (1978). Threshold Models of Collective Behavior. American Journal of Sociology, 83(6), 1420–1443. · sociology
News feeds / RSS · computer-science
News feeds / RSS · computer-science
OS signals / inotify / file watchers · computer-science
OS signals / inotify / file watchers · computer-science
Pub-sub messaging (Kafka, Redis Streams, RabbitMQ fanout) · computer-science
Pub-sub messaging (Kafka, Redis Streams, RabbitMQ fanout) · computer-science
Reactive / event-driven architectures (Kafka, Redux, RxJS, Elm, Erlang/OTP) · computer-science
Reactive / event-driven architectures (Kafka, Redux, RxJS, Elm, Erlang/OTP) · computer-science
Reactive Streams specification / RxJava / RxJS — the modern reactive-programming continuation. · computer-science
Reactive Streams specification / RxJava / RxJS — the modern reactive-programming continuation. · computer-science
Smalltalk MVC (Reenskaug, 1979) — observer baked into the original MVC. · computer-science
Smalltalk MVC (Reenskaug, 1979) — observer baked into the original MVC. · computer-science
Waters, C. M., & Bassler, B. L. (2005). Quorum Sensing: Cell-to-Cell Communication in Bacteria. Annual Review of Cell and Developmental Biology, 21, 319–346. · biology
Waters, C. M., & Bassler, B. L. (2005). Quorum Sensing: Cell-to-Cell Communication in Bacteria. Annual Review of Cell and Developmental Biology, 21, 319–346. · biology
Webhooks · computer-science
Webhooks · computer-science