Message passing is a way for independent units of computation to communicate by sending messages rather than sharing mutable state directly.

It is the mechanism used by the Actor Model, and it is also the core idea behind broker-based Messaging systems.

In the Actor Model

In actor systems such as Erlang and Elixir, each process has its own mailbox.

  • A sender sends a message to a process
  • The message is copied into the mailbox
  • The receiving process handles messages one at a time
  • Processes stay isolated from each other

In broker-based messaging

In messaging systems, a producer sends a message to a broker, queue, topic, or stream.

  • Producers do not usually call consumers directly
  • Brokers or queues hold and route messages
  • Consumers receive messages asynchronously
  • Delivery may be one-to-one, fan-out, or log-based

Compare

Message passing is the bridge between the two worlds:

  • Actor Model uses message passing inside a runtime between isolated processes
  • Messaging uses message passing between services or systems through infrastructure
  • Object Oriented Programming can use message-like method calls, but that is a different model from actor or broker-based message passing