Name of “notification-and-check” pubsub architecture?

余生颓废 提交于 2021-02-17 03:28:26

问题


Basic pubsub architecture question. At a high level, when designing pubsub, I sometimes face a choice between two architectures:

  1. Publish mutations or "new-state".

Some DB state is mutated, and publishers notify of that change via pubsub. But they include enough information in the message so that the subscriber doesn't need to do a look-up on the DB. Imagine the subscriber has a cache of the DB. It could receive the mutations or new-state, and update its cache without doing a look-up.

  1. Notification-and-check The publishers only notify that "there is a new change", which prompts the subscriber to pull the latest from the DB. This is more robust IMO. The pubsub may not guarantee order of delivery, and this architecture is robust to that, while #1 is not, if the mutations are order-sensitive.

My question is, is there a common name for these 2-types of architectures? Thanks!


回答1:


Publish/Subscribe is known as the Observer Pattern in the Gang of Four Design Patterns book. On page 298 they describe these two variations as push and pull models.

Implementations of the Observer pattern often have the subject broadcast additional information about the change. The subject passes this information as an argument to Update. The amount of information may vary widely.

At one extreme, which we call the push model, the subject sends observers detailed information about the change , whether they want it or not. At the other extreme is the pull model; the subject sends nothing but the most minimal notification, and observers ask for details explicitly thereafter.

The pull model emphasizes the subject's ignorance of its observers, whereas the push model assumes subjects know something about their observers' needs. The push model might make observers less reusable, because Subject classes make assumptions about Observer classes that might not always be true. On the other hand, the pull model may be inefficient, because Observer classes must ascertain what changed without help from the Subject.



来源:https://stackoverflow.com/questions/63321138/name-of-notification-and-check-pubsub-architecture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!