1. Introduction
Distributed computing involves multiple processes running on different machines, collaborating to achieve a common goal. The two fundamental models for communication between these processes are:
-
Message Passing System
-
Shared Memory System
Understanding the distinctions, advantages, limitations, and use cases of each is crucial in distributed systems design.
2. Message Passing System
Definition
In this model, processes communicate by explicitly sending and receiving messages. There is no shared address space; instead, data is transmitted over a network.
Key Features
-
Explicit communication
-
Communication via
send()andreceive()calls -
Works across heterogeneous systems
-
Synchronization often implicit in communication
-
Suitable for physically distributed systems
Advantages
-
Modularity: Processes are independent, reducing side effects.
-
Security: No shared memory eliminates race conditions and unauthorized access.
-
Scalability: Easily scalable across machines or networks.
-
Fault Isolation: Failure of one process doesn’t directly affect others.
Disadvantages
-
Latency: Message transmission over the network introduces delay.
-
Complexity: Requires careful design to handle synchronization, reliability.
-
Overhead: Requires serialization, deserialization, and message buffering.
Examples
-
MPI (Message Passing Interface)
-
Actor Model in Erlang
-
Client-server systems
-
Microservices architecture
3. Shared Memory System
Definition
In shared memory systems, multiple processes share a common memory space and communicate by reading and writing to shared variables.
Key Features
-
Implicit communication via shared variables
-
Fast data access due to memory proximity
-
Requires synchronization mechanisms (mutexes, semaphores)
-
Usually used in tightly coupled systems (SMP)
Advantages
-
Low Latency: Direct memory access is faster than message passing.
-
Ease of Communication: Data can be read/written without serialization.
-
Efficient for small systems: Great for multicore or multithreaded environments.
Disadvantages
-
Synchronization issues: Race conditions, deadlocks, and starvation.
-
Difficult debugging: Bugs due to improper synchronization are hard to find.
-
Not scalable: Poor performance over distributed systems due to latency.
Examples
-
POSIX Shared Memory
-
OpenMP
-
Shared memory between threads in C/C++
-
Multicore CPU systems

4. Detailed Comparison Table
| Feature | Message Passing | Shared Memory |
|---|---|---|
| Communication | Explicit | Implicit |
| Synchronization | Implicit | Explicit |
| Data Access | Via send/receive | Via shared variables |
| Suitable Systems | Distributed | Tightly coupled |
| Scalability | High | Low |
| Performance | Lower (due to overhead) | Higher (within single system) |
| Fault Tolerance | High | Low |
| Security | High | Low |
| Programming Complexity | High | Moderate |
| Synchronization Overhead | Low (built-in) | High (must manage explicitly) |
5. Use Case Scenarios
Message Passing Use Case
Distributed Web Services – Microservices architecture uses REST APIs or gRPC to exchange data between services.
Shared Memory Use Case
Multithreaded Applications – A game engine where physics, rendering, and input threads share the game state in memory.
6. Programming Example: Message Passing
7. Programming Example: Shared Memory
8. Real-World Examples
| Application | Communication Model |
|---|---|
| Chat Applications (WhatsApp, Signal) | Message Passing |
| Operating Systems (Kernel Threads) | Shared Memory |
| Banking Transactions (Inter-bank) | Message Passing |
| Simulation Software (Game Engines) | Shared Memory |
9. Hybrid Approach
Some systems combine both models:
-
Use message passing for inter-process communication
-
Use shared memory for intra-process/thread communication
Example: A web server using processes to handle requests (via message passing) and threads inside each process to handle tasks (via shared memory).
Emulating Message Passing on a Shared Memory System (MP → SM)
-
Shared memory can simulate message passing by dividing memory into parts for each processor.
-
Send/Receive: A processor writes to or reads from another’s assigned memory space.
-
Synchronization is needed to coordinate these read/write actions.
-
A mailbox (dedicated memory slot) can be used between each pair of processes.
Emulating Shared Memory on a Message Passing System (SM → MP)
-
Each shared memory location is represented by a process.
-
Write: Send an update message to the process owning that memory.
-
Read: Send a query message and wait for the response.
-
This method is slow and costly due to communication overhead and latency.
