Skip to main content
biology computer-science journalism-media-studies-and-communication sociology

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

Internal structure of observer: a table of its component slots and the concepts that fill them.

Relationships

Relationship neighborhood of observer: a graph of the concepts it connects to and the concepts it is a part of.
  • 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

every addEventListener is observer registration.

Biological signaling · biology

hormones bind receptors on many target cells; one-to-many notification cascade.
Endocrine signaling broadcasts: a gland secretes a hormone into the bloodstream, where it travels everywhere in the body at once. The gland does not address any particular recipient. What makes the signal land on the right cells is that only cells bearing the matching receptor can bind the hormone and respond — every other cell is bathed in the same molecule and ignores it. The body achieves targeted response not by routing the message but by who is equipped to receive it.Inference: This is the publish-subscribe reading of the observer shape, with receptor possession as the subscription mechanism. The_subject is the secreting gland whose hormone level is the state of interest; the_observers are the target cells; the_notification is the circulating hormone, present at very low concentration so receptors must bind it with high affinity to detect it. The decisive role here is the_subscription: a cell “subscribes” to a hormone by expressing its receptor, and the gland never has to enumerate its audience. That asymmetry — the publisher ignorant of subscribers, subscribers self-selecting by receptor — is exactly the dependency direction that marks an observer, distinguishing endocrine broadcast from synaptic signaling, where the message is delivered down a dedicated wire to a known target.
observer baked into the actor model.
Fenby’s account of the major wire agencies — Associated Press, Reuters, Agence France-Presse, United Press International — describes an architecture that is observer-shaped at its core. An agency gathers news through a global network and pushes bulletins out over its wire to every subscribing newspaper, radio station, and broadcaster the moment a story breaks. The agency does not know or care what each outlet will print; it only knows who has signed the subscription. At the time, this fan-out carried roughly four-fifths of the international news circulating in the non-Communist world.Inference: The_subject is the agency as a continuously updating source of news state; the_observers are the subscribing outlets; the_notification is the wire bulletin, carrying enough of the story for each editor to decide whether and how to run it. The_subscription is explicit and contractual — an outlet registers by paying for the feed, and the agency’s reach is exactly its subscriber list. The dependency runs the canonical observer direction: subscribers know and depend on the agency, while the agency is indifferent to each subscriber’s downstream editorial behavior. The same indifference is what Fenby’s NWICO-era critics worried about — one source fanning out to thousands of dependents concentrates influence precisely because the push path is one-to-many and the subscribers don’t coordinate.
The Gang of Four catalog defines Observer as a behavioral pattern: a subject maintains a list of dependents (observers) and notifies them automatically of any state changes, usually by calling one of their methods. The subject does not need to know what its observers do with the notification; it only needs that they have registered. The naming preserves the everyday-English connotation — a watcher who is informed of changes but does not author them.Inference: Observer is structurally a one-to-many push-on-change. The wider pub-sub family generalizes the same shape across address spaces and protocols — DOM event listeners, OS signal handlers, file watchers, message brokers, RSS feeds, webhook deliveries. The diagnostic for an Observer match is the direction of the dependency: observers know the subject, but the subject does not know the observers’ identities or downstream behavior. That asymmetry is also what distinguishes Observer from neighboring patterns — 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 models collective action — a riot starting, a strike spreading, a norm tipping — as a population of individuals each carrying a personal threshold: the number or proportion of others who must already have joined before they will join too. Each person watches the running count of prior participants and reacts the instant it crosses their threshold. The aggregate outcome depends not on the average disposition but on the exact distribution of thresholds, so a single low-threshold person can set off a cascade that draws in everyone, while a near-identical crowd missing that one person never moves at all.Inference: This is the threshold reading of observer, with the catch that the observers also constitute the thing they observe. The_subject is the running participation count — a shared aggregate state; the_observers are the individuals monitoring it; the_notification is each visible increment in the count; the_subscription is membership in the population that is watching and able to act. The structural signature is reaction-on-threshold-crossing: nobody is commanded, each agent independently fires when the observed state passes its trigger. Because every observer’s action raises the count that other observers are watching, the notification path closes into the amplifying feedback loop that produces the bandwagon — the same observer-as-substrate-for-feedback structure that quorum sensing shows in bacteria.
publishers don’t enumerate subscribers; subscribers attach and get pushed updates.
kernel-level observer mechanism.
observer at the infrastructure tier.
whole architectures rest on the observer shape; this is one of the most-reused primitives in modern software
The Reactive Streams specification (and implementations including RxJava, RxJS, Project Reactor, and Akka Streams) generalizes Observer in two directions. First, the notifications are first-class streams of values over time rather than individual events. Second, the protocol adds a backpressure channel: subscribers can signal demand upstream, so a fast producer does not overwhelm a slow consumer.Inference: The Reactive Streams variant illustrates how a structural primitive evolves under operational pressure. The bare Observer pattern is fragile when notification rate exceeds processing rate; adding a demand-signaling channel preserves the one-to-many-on-change shape while gaining flow control. The combination is structurally Observer + backpressure — a composition the catalog can name explicitly without losing either component’s diagnostic value.
Trygve Reenskaug’s Model-View-Controller architecture, developed for Smalltalk-80, embedded the Observer relationship as a load-bearing structural choice: views register as observers of the model and update themselves when the model changes. The decoupling lets multiple views display the same underlying state independently, and lets the model remain unaware of which views exist.Inference: MVC predates the GoF coinage of “Observer” by more than a decade, suggesting the pattern was already structural enough to recur independently. The diagnostic recurs whenever a representation (view, projection, summary) must stay consistent with a source it should not directly drive — the alternative (polling, or pushing through coupling) costs either latency or modularity.
Bacteria continuously secrete small signaling molecules called autoinducers. As a population grows, the extracellular concentration of autoinducer rises with cell density, and once it crosses a minimal threshold, the whole population detects it and coordinately switches gene expression — turning on bioluminescence, virulence, or biofilm formation that only pays off when done en masse. No cell directs another; each one reads the ambient signal and reacts when the signal says “enough of us are here.”Inference: This is the threshold flavor of observer. The_subject is the shared autoinducer concentration — a piece of state that becomes interesting as it changes; the_observers are the individual cells; the_notification is the autoinducer level itself, carrying just enough information (how crowded is it?) for each cell to decide whether to react. The_subscription is implicit rather than explicit — any cell expressing the cognate receptor is “registered” to respond, and cells without it simply don’t hear the broadcast. What distinguishes this from a plain push-on-change observer is that the observers are also the producers of the signal, so the notification path closes into a population-scale feedback loop rather than a one-directional fan-out.
HTTP-level observer registration; the subject POSTs to subscriber URLs on events.