RPC Implementation Mechanism in Distributed System
Last Updated :
16 Aug, 2022
In this article, we will go through the concept of the Remote Procedure Call (RPC) and its working mechanism.
RPC is an effective mechanism for building client-server systems that are distributed. RPC enhances the power and ease of programming of the client/server computing concept. It's a protocol that allows one software to seek a service from another program on another computer in a network without having to know about the network. The software that makes the request is called a client, and the program that provides the service is called a server.
The calling parameters are sent to the remote process during a Remote Procedure Call, and the caller waits for a response from the remote procedure. The flow of activities during an RPC call between two networking systems is depicted in the diagram below.

Semantic Transparency:
- Syntactic transparency: This implies that there should be a similarity between the remote process and a local procedure.
- Semantic transparency: This implies that there should be similarity in the semantics i.e. meaning of a remote process and a local procedure.
Working of RPC:
There are 5 elements used in the working of RPC:
- Client
- Client Stub
- RPC Runtime
- Server Stub
- Server

- Client: The client process initiates RPC. The client makes a standard call, which triggers a correlated procedure in the client stub.
- Client Stub: Stubs are used by RPC to achieve semantic transparency. The client calls the client stub. Client stub does the following tasks:
- The first task performed by client stub is when it receives a request from a client, it packs(marshalls) the parameters and required specifications of remote/target procedure in a message.
- The second task performed by the client stub is upon receiving the result values after execution, it unpacks (unmarshalled) those results and sends them to the Client.
- RPC Runtime: The RPC runtime is in charge of message transmission between client and server via the network. Retransmission, acknowledgement, routing, and encryption are all tasks performed by it. On the client-side, it receives the result values in a message from the server-side, and then it further sends it to the client stub whereas, on the server-side, RPC Runtime got the same message from the server stub when then it forwards to the client machine. It also accepts and forwards client machine call request messages to the server stub.
- Server Stub: Server stub does the following tasks:
- The first task performed by server stub is that it unpacks(unmarshalled) the call request message which is received from the local RPC Runtime and makes a regular call to invoke the required procedure in the server.
- The second task performed by server stub is that when it receives the server's procedure execution result, it packs it into a message and asks the local RPC Runtime to transmit it to the client stub where it is unpacked.
- Server: After receiving a call request from the client machine, the server stub passes it to the server. The execution of the required procedure is made by the server and finally, it returns the result to the server stub so that it can be passed to the client machine using the local RPC Runtime.
RPC process:
- The client, the client stub, and one instance of RPC Runtime are all running on the client machine.
- A client initiates a client stub process by giving parameters as normal. The client stub acquires storage in the address space of the client.
- At this point, the user can access RPC by using a normal Local Procedural Call. The RPC runtime is in charge of message transmission between client and server via the network. Retransmission, acknowledgment, routing, and encryption are all tasks performed by it.
- On the server-side, values are returned to the server stub, after the completion of server operation, which then packs (which is also known as marshaling) the return values into a message. The transport layer receives a message from the server stub.
- The resulting message is transmitted by the transport layer to the client transport layer, which then sends a message back to the client stub.
- The client stub unpacks (which is also known as unmarshalling) the return arguments in the resulting packet, and the execution process returns to the caller at this point.


When the client process requests by calling a local procedure then the procedure will pass the arguments/parameters in request format so that they can be sent in a message to the remote server. The remote server then will execute the local procedure call ( based on the request arrived from the client machine) and after execution finally returns a response to the client in the form of a message. Till this time the client is blocked but as soon as the response comes from the server side it will be able to find the result from the message. In some cases, RPCs can be executed asynchronously also in which the client will not be blocked in waiting for the response.
The parameters can be passed in two ways. The first is to pass by value, whereas the second is to pass by reference. The parameters receiving the address should be pointers when we provide it to a function. In Pass by reference, a function is called using pointers to pass the address of variables. Call by value refers to the method of sending variables' actual values.
The language designers are usually the ones who decide which parameter passing method to utilize. It is sometimes dependent on the data type that is being provided. Integers and other scalar types are always passed by value in C, whereas arrays are always passed by reference.
Similar Reads
Stub Generation in Distributed System A stub is a piece of code that translates parameters sent between the client and server during a remote procedure call in distributed computing. An RPC's main purpose is to allow a local computer (client) to call procedures on another computer remotely (server) because the client and server utilize
3 min read
File Models in Distributed System File Models in Distributed Systems" explores how data organization and access methods impact efficiency across networked nodes. This article examines structured and unstructured models, their performance implications, and the importance of scalability and security in modern distributed architectures
6 min read
Limitations of Distributed Systems Distributed systems are essential for modern computing, providing scalability and resource sharing. However, they face limitations such as complexity in management, performance bottlenecks, consistency issues, and security vulnerabilities. Understanding these challenges is crucial for designing robu
8 min read
Mechanism for Building Distributed File System Building a Distributed File System (DFS) involves intricate mechanisms to manage data across multiple networked nodes. This article explores key strategies for designing scalable, fault-tolerant systems that optimize performance and ensure data integrity in distributed computing environments.Mechani
8 min read
Exception Handling in Distributed Systems Exception handling in distributed systems is crucial for maintaining reliability and resilience. This article explores strategies for managing errors across networked services, addressing challenges like fault tolerance, error detection, and recovery, to ensure seamless and robust system operation.I
11 min read
What is Leader Election in a Distributed System? In distributed systems, leader election is a crucial process for maintaining coordination and consistency. It involves selecting a single node from a group to act as the leader, responsible for managing tasks and decision-making. This process ensures that the system operates efficiently and can reco
9 min read
Failure Models in Distributed System In distributed systems, where multiple interconnected nodes collaborate to achieve a common goal, failures are unavoidable. Understanding failure models is crucial for designing robust and fault-tolerant distributed systems. This article explores various failure models, their types, implications, an
8 min read
Event Ordering in Distributed System In this article, we will look at how we can analyze the ordering of events in a distributed system. As we know a distributed system is a collection of processes that are separated in space and which can communicate with each other only by exchanging messages this could be processed on separate compu
4 min read
Distributed System - Parameter Passing Semantics in RPC A Distributed System is a Network of Machines that can exchange information with each other through Message-passing. It can be very useful as it helps in resource sharing. In this article, we will go through the various Parameter Passing Semantics in RPC in distributed Systems in detail. Parameter P
4 min read
Handling Duplicate Messages in Distributed Systems Duplicate messages in distributed systems can lead to inconsistencies, inefficiencies, and incorrect data processing. To ensure reliability and correctness, effectively handling duplicates is crucial. This article explores the causes, challenges, and techniques for managing duplicate messages in dis
8 min read