Message passing is the fundamental method for communication in a distributed system, where data, commands, or requests are exchanged between nodes through network messages.
- It allows different components, which may be running on separate machines or nodes connected via a network, to coordinate their activities, share information, and collaborate to achieve common goals.
Key Concepts related to Message Passing
1.) Message
- A message is a unit of communication that carries data from one process to another within a distributed system. It can be request message, response message or notification.
2.) Synchronous vs Asynchronous Communication
- In synchronous communication, the sender sends a message and waits for a response before continuing its operation.
- In asynchronous communication, the sender sends the message and does not wait for an immediate response. The sender can continue processing other tasks.
3.) Communication Models
- Point-to-Point: In point-to-point communication, a message is sent directly from one process to another process. It is a simple, one-to-one communication model.
- Publish-Subscribe: In the publish-subscribe model, messages are sent by publishers and received by subscribers.
- Request-Reply: A request-reply communication model involves one process sending a request message, and the other process sending a reply message.
4.) Communication Protocols
- Communication protocols define the rules for exchanging messages between processes in a distributed system
5.) Reliability and Fault Tolerance
- Reliability and fault tolerance in message passing ensure that messages are delivered correctly and consistently, even in the event of system failures.
6.) Message Queues
- A message queue is a communication buffer that temporarily stores messages until they can be processed by the receiving process.
7.) Coordination and Synchronization
- Coordination and synchronization mechanisms ensure that processes in a distributed system operate in a consistent and orderly manner, especially when accessing shared resources or performing concurrent tasks.
8.) Security and Authentication
- Security and authentication in message passing ensure that messages are sent securely, and only authorized processes can send or receive messages.
Use Cases of Message Passing
- Inter-process Communication (IPC): Nodes in a distributed system use message passing to coordinate and synchronize their processes.
- Resource Allocation: Nodes communicate to access and release resources in a coordinated manner.
- Distributed Databases: Message passing enables the synchronization and replication of data across multiple nodes.
Types of Message Passing in Distributed Systems:
- Synchronous Message Passing
- Asynchronous Message Passing
1.) Synchronous Message Passing:
In synchronous message passing, the sender and receiver processes must both be ready and available at the same time for the message exchange to occur. This means that the sender waits until the receiver is ready to receive the message, and the receiver waits until it receives the message from the sender.
Features of Synchronous Message Passing
- Blocking Nature:
The sender is blocked (halts processing) until it receives an acknowledgment or response from the receiver, and the receiver is blocked until the message arrives. This blocking behavior synchronizes both processes.
- Reliability:
Since both processes are aware of each other’s state (ready to send/receive), synchronous message passing is often used when a reliable exchange of information is needed, as both parties can confirm that communication has occurred.
- Immediate Feedback:
Because both processes interact in real time, synchronous message passing allows immediate feedback, making it suitable for scenarios requiring real-time data exchange or command-response interactions.
2.) Asynchronous Message Passing:
In asynchronous message passing, the sender sends a message to the receiver and continues its processing without waiting for the receiver to acknowledge receipt. The receiver processes the message whenever it becomes available, and both sender and receiver can operate independently of each other.
Example:
In an email system, when a sender sends an email, they do not wait for the recipient to read it. The email is sent asynchronously, and the recipient accesses it at their convenience. The sender can continue with other tasks without delay.
Features of Asynchronous Message Passing
- Non-Blocking Nature:
The sender sends the message and continues its work without waiting for the receiver, and the receiver processes the message when it’s ready. This non-blocking behavior allows more efficient use of resources.
- Decoupling of Processes:
Since there is no dependency on both processes being ready at the same time, asynchronous message passing allows for more flexibility and independence between sender and receiver.
- Improved System Throughput:
By allowing processes to continue independently, asynchronous message passing often leads to higher system throughput, as neither process is delayed waiting for the other.
- Reliability and Ordering Considerations:
As messages are sent independently, ensuring message reliability and ordering can require additional mechanisms. For example, message queues or acknowledgment systems may be used to confirm message delivery and order.
