Scala Reactive Programming
上QQ阅读APP看书,第一时间看更新

Message-Driven

The core or base principle of the Reactive systems is Message-Driven architecture. It is the foundation principle or method for the rest of the three principles—Elasticity, Resilience, and Responsiveness.

This means a Reactive system depends on asynchronous message-passing between its components to use the benefits of Message-Driven architecture for free.

In simple words, Message-Driven = React to messages.

Even though RP represents the system's changes in terms of events, a Reactive system converts them into messages under the hood.

One more important point to note is that in a Reactive system, even failures are represented as messages, so it's easy to perform failure handling.

So, in a Reactive system, all of its components communicate with each other by sending messages. The Message-Driven approach gives us the following benefits:

  • Messages are immutable by design
  • They share nothing, so are thread-safe by design
  • They provide loose coupling between system components
  • They can work across the network, so they support Location Transparency
  • They support scalability
  • They support Resilience because they avoid single-point-of-failure using partitioning and replication techniques
  • They support better throughput
  • They provide easy-to-apply backpressure

So in RP, we write code in a stream of events, and then Reactive systems convert them into a stream of messages.