Chapter 4. Message passing

 

The fundamental notion on which message passing is built is that of an event: the fact that a certain condition has occurred (the event) is bundled together with contextual information—like who did what when and where—and is signaled by the producer as a message. Interested parties are informed by the producer using a common transport mechanism and consume the message.

In this chapter, we will discuss in detail the main aspects of message passing:

  • The difference between focusing on messages or events
  • Whether to do it synchronously or asynchronously
  • How messages can be transmitted without overwhelming the recipient and with varying degrees of reliability

You will also see how message passing enables vertical scalability. Finally, we will discuss the correspondence between events and messages—or how to model one in terms of the other.

4.1. Messages

In the real world, when you mail a letter to someone, you do not expect the contents of the letter to change after it is sent. You expect the letter that arrives to be the same as the one that was sent, and after it arrives you do not expect it to change into a different letter. This is true regardless of whether the letter is sent around the world and takes days or weeks to arrive, or is sent across town, or even is handed to the recipient in person. Immutability is important.

4.2. Vertical scalability

4.3. Event-based vs. message-based

4.4. Synchronous vs. asynchronous

4.5. Flow control

4.6. Delivery guarantees

4.7. Events as messages

4.8. Synchronous message passing

4.9. Summary