A Remote Procedure Call (RPC) is a communication protocol that enables a program to request a service or execute a procedure on a remote server as though it were a local function call.

- The client invokes a function on the server located in a different address space.
- The RPC framework handles the details of network communication, serialization, and response management.
- This makes remote communication transparent to developers, promoting cleaner and more modular distributed applications.
Importance of RPC in Distributed Systems
Simplified Communication
- Abstraction of complexity: Developers call remote services as if they were local methods.
- Consistent interface: Uniform way of invoking services across the system.
Enhanced Modularity and Reusability
- Decoupling: System components interact without being tightly coupled.
- Reusability: Remote services can be reused across multiple applications.
Facilitates Distributed Computing
- Inter-Process Communication (IPC): Enables different processes on different machines to collaborate.
- Resource Sharing: Allows sharing of resources like databases, computing power, or specialized services.
RPC Architecture in Distributed Systems
RPC follows a client-server model, where the client requests execution of a remote procedure and the server responds.
1. Client and Server Components
- Client: Initiates the request using a local stub.
- Server: Hosts the actual implementation of the remote procedure.
2. Stubs
- Client Stub: Packs (marshals) arguments, sends request, and receives results.
- Server Stub: Unpacks (unmarshals) arguments, executes the procedure, and sends results back.
3. Marshalling and Unmarshalling
- Marshalling: Converts data/arguments into transmittable byte streams.
- Unmarshalling: Converts byte streams back into usable data.
4. Communication Layer
- Uses transport protocols (TCP/UDP).
- Manages message routing, buffering, and error handling.
5. RPC Framework
- IDL (Interface Definition Language): Defines procedures, parameters, and return types independent of programming language.
- RPC Protocol: Specifies communication rules, request-response format, and error handling.
6. Error Handling and Fault Tolerance
- Timeouts and Retries: To handle failures and delays.
- Exception Handling: Reports errors to clients.
7. Security
- Authentication/Authorization: Ensures only valid clients can access services.
- Encryption: Protects data during transmission (e.g., SSL/TLS).
Types of RPC
1. Synchronous RPC
- Client waits for server response.
- Simple design but blocking in nature.
- Used when immediate response is required.
2. Asynchronous RPC
- Client sends request and continues execution without waiting.
- More complex but improves responsiveness.
- Used in concurrent applications.
3. One-Way RPC
- Client sends request without expecting any response.
- "Fire-and-forget" style.
- Used in logging or notification services.
4. Callback RPC
- Server invokes a client-provided callback after processing.
- Useful for long-running operations.
5. Batch RPC
- Multiple requests are bundled into one batch.
- Reduces network round trips and overhead.