Comparison
Observer patternvsPublish-subscribe
Observer pattern
you changed one field and four other things updated, and finding out which four meant reading a subscription list.
A subject holding a list of dependents and notifying each of them when it changes. It is in-process and direct: the subject holds references to its observers, so the two know about each other in a way publish-subscribe deliberately avoids. Its recurring problems are all lifetime problems — observers that are never unsubscribed keep their subject alive, and notification order is an unwritten dependency people come to rely on.
Full entry →Publish-subscribe
you publish the event once and three different services each get their own copy without the publisher knowing they exist.
A pattern where publishers emit to a topic and every interested subscriber receives a copy. It removes the publisher's knowledge of consumers, which is what makes adding a fourth consumer a zero-change operation upstream. The trade is that nobody owns the contract, so a field the publisher considers cosmetic can be load-bearing for a subscriber it has never heard of.
Full entry →