Pub / Sub Vs Observer Vs Reactive

When I used the pattern structure / Sub, as before MVVMLight, I saw that the caller is being processed synchronously. In terms of scalability, is this reactive structure like Rx scalable when the pub and subsystem are completely decoupled and scalable? Which template helps scalability?

+5
source share
1 answer

I do not know the specifics of MVVMLight, but in general Pub / Sub is a template where:

  • Publishers and subscribers do not know about each other. They only know about the broker, where they publish / consume messages.
  • As a result, the publication and consumption of messages are asynchronous and completely decoupled. This means that the publication / consumption side can be scaled independently, and in the event of a failure of one part, the other part can continue to work.

Reactive programming is now a template used to model changes and propagate them to multiple participants. Thus, it is not so much about implementation details, but is more focused on providing an abstract, declarative interface that simplifies working with event flows and performs processing on top of them. Straight from the ReactiveX documentation:

ReactiveX is not tied to a specific source of concurrency or asynchrony. Observables can be implemented using thread pools, event loops, non-blocking I / O, participants (for example, from Akka), or any other implementation that suits your needs, your style, or your experience. Client code considers all of its interactions with Observables to be asynchronous, regardless of whether your underlying implementation is blocking or not blocking, and yet you decide to implement it.

Thus, decoupling / scalability will mainly depend on the implementation used under it, the main advantage of the structure is mainly an abstract, declarative interface.

As for the observer pattern (which is mentioned in the title of the question), it is a rather low-level primitive that can be used to achieve the same goal, but can probably lead to a much more complex code base. For more information on the traps of the observer pattern compared to more abstract reactive frameworks, you can read the following document:

Eliminate the Observer pattern with Scala.React

0
source

All Articles