Observer vs Pub-Sub pattern

Many times I've asked myself the same question, Is the observer pattern the same as pub-sub pattern?

Well, It isn’t.

The Observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.

The Publisher-Subscriber is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead categorize published messages into classes without knowledge of which subscribers exist. Similarly, subscribers express interest in one or more classes and only receive messages that are of interest, without knowledge of which publishers there are.

The observer pattern is mostly implemented synchronously. The subject calls a specific method of all its observers when an event occurs.

The pub-sub pattern is mostly implemented asynchronously. The publisher publishes an event in an event channel and then, the channel will be in charge to fire the event, mainly using a message queue.

They are quite similar, but...

In the observer pattern, the subjects maintains a list of the observers and the observers are aware of the subjects.

In the pub-sub pattern the components are loosely coupled. Neither publishers know subscribers nor vice versa. Everything works thanks to the use of a single communication channel.