Unit I - Communication Patterns
Unit I - Communication Patterns
in Distributed Systems
Remote Procedure Call
Concept:
● RPC allows a program to cause a procedure (subroutine) to execute in another address space (commonly on another physical
machine).
Key Points:
● Synchronous communication: The client waits for the server to finish processing and return the result.
● Abstraction: It abstracts the details of the network communication, making remote calls appear like local calls.
● Languages: Protocols like JSON-RPC, XML-RPC, and implementations in gRPC, Thrift.
● Simplicity: Abstracts the complexities of network communication, making remote calls look like local calls.
● Language Agnostic: Various implementations (e.g., gRPC) support multiple programming languages.
● Standardization: Many well-established protocols and libraries.
Cons:
● Synchronous Nature: Can lead to blocking calls, which may affect performance if the remote service is slow or unresponsive.
● Tight Coupling: The client and server need to agree on the interface, which can make versioning and changes more difficult.
● Error Handling: Network issues and remote failures can complicate error handling.
Remote Method Invocation (RMI)
Concept:
● RMI is similar to RPC but is specific to Java. It allows objects to invoke methods on an object running in another Java Virtual
Machine (JVM).
Key Points:
● Object-Oriented: Supports the concept of remote objects and allows invoking methods on them.
● Built-in Java: Part of the Java standard library.
● Serialization: Java objects are serialized and deserialized during communication.
● Object-Oriented: Allows remote method calls on objects, integrating well with Java's object-oriented paradigm.
● Built-in Security: Provides built-in mechanisms for handling security.
● Ease of Use: Being a part of the Java standard library, it's easy to set up and use within Java applications.
Cons:
● Communication via message exchange where processes or objects send and receive messages.
Key Points:
● Asynchronous communication: Messages can be sent and received without blocking the sender.
● Loose coupling: Systems can be loosely coupled, as they do not need to know the details of each other.
● Message Queues: Systems like RabbitMQ, Kafka for managing messages.
● A microservice architecture where services communicate via a message broker like RabbitMQ.
Message Passing
Pros:
● Asynchronous Communication: Decouples sender and receiver, allowing for non-blocking communication.
● Scalability: Can handle a large number of messages efficiently, especially with message brokers.
● Fault Tolerance: Messages can be stored and retried in case of failures.
Cons:
● Complexity: Requires managing message queues and handling message delivery guarantees.
● Latency: Messages may experience delays depending on the broker's performance and load.
● State Management: Maintaining the state across distributed components can be challenging.
Shared Memory
Concept:
● Multiple processes share a common memory space and communicate by reading and writing to that memory.
Key Points:
Cons:
● Synchronization Issues: Requires careful synchronization to avoid data races and inconsistencies.
● Limited Scope: Generally limited to processes on the same machine.
● Scalability: Not suitable for large-scale distributed systems across multiple machines.
Publish Subscribe
Concept:
● A messaging pattern where senders (publishers) send messages without knowing the receivers (subscribers).
Key Points:
● Decoupled systems: Publishers and subscribers are decoupled from each other.
● Event-driven: Suitable for event-driven architectures.
● Topics: Messages are categorized into topics, and subscribers receive messages based on their subscriptions.
Cons:
Key Points:
● A chat application where clients communicate with each other using TCP sockets.
Socket Programming
Pros:
● Flexibility: Allows custom protocols and provides fine-grained control over communication.
● Efficiency: Direct communication can be very efficient with low overhead.
● Bidirectional: Supports two-way communication, making it suitable for interactive applications.
Cons:
● Complexity: Requires handling low-level details like connection management, data framing, and error handling.
● Development Time: More time-consuming to develop compared to higher-level abstractions.
● Security: Requires careful handling to avoid security vulnerabilities like buffer overflows and injection attacks.
Web Services (REST)
Concept:
● Web services enable communication over the web using standard protocols like HTTP.
Key Points:
Cons:
● Performance Overhead and Latency: Can be slower due to the use of text-based protocols (XML, JSON) and HTTP.