Browse Java Design Patterns & Enterprise Application Architecture

Observer Pattern vs. Pub/Sub Models

Compare in-process Observer with broader pub-sub models in Java so local listeners are not confused with brokered event systems.

On this page

Observer and pub-sub both distribute reactions to events, but they operate at different scales and with different assumptions.

    flowchart LR
	    A["Observer"] --> B["Subject knows listener registration"]
	    B --> C["Usually in-process and direct"]
	    D["Pub-sub"] --> E["Publisher and subscriber decoupled by topic or broker"]
	    E --> F["Often distributed or infrastructure-backed"]

Observer

Observer is usually:

  • in-process
  • direct
  • synchronous unless designed otherwise
  • built around explicit listener registration

Pub-Sub

Pub-sub is usually:

  • brokered or topic-based
  • more loosely coupled in addressability
  • often asynchronous
  • more infrastructure-aware

Java Shortcut

If one object inside the same process needs to notify listeners, start by thinking Observer.

If events need routing through topics, infrastructure, or service boundaries, think pub-sub or event-driven messaging instead.

Revised on Thursday, April 23, 2026