Design Patterns interview question · Most asked

What is the difference between Observer and Pub/Sub?

Summary

In Observer, the subject holds direct references to its observers and usually notifies them synchronously in the same process. In Pub/Sub, publishers and subscribers only know a broker and topic names; delivery is typically asynchronous, can cross processes and services, and failures are isolated with retries and dead-letter queues.

Longer Answer

Observer is simpler and immediate (UI events, in-process domain events). Pub/Sub decouples further and scales across services (SNS/SQS, Kafka, RabbitMQ, Google Pub/Sub), at the cost of eventual consistency, duplicate deliveries (subscribers must be idempotent) and harder debugging.

Key Points

  • Observer: direct references, synchronous, in-process.
  • Pub/Sub: broker and topics, asynchronous.
  • Pub/Sub isolates failures but brings eventual consistency.
  • Make Pub/Sub subscribers idempotent.

Deep dive: Design Patterns, Explained Simply: Pub/Sub and the Event Bus

Explanation

What interviewers look for

Coupling, synchronicity and failure-isolation differences.

More most-asked Design Patterns questions

← All Design Patterns questions