Open In App

Remote Procedure Call (RPC) in Operating System

Last Updated : 21 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Remote Procedure Call (RPC) is a way for a program to run a function on another computer in a network as if it were local. The client sends the request (with arguments) to the server, the server executes the function, and the result is sent back. RPC hides the details of networking, so developers can think in terms of normal function calls instead of complex network operations.

Working of a RPC

RPC working

How RPC Works (Step by Step)

  1. Client Calls Stub: The client calls a local procedure (stub) as if it were normal.
  2. Marshalling: The stub packs (marshals) all input parameters into a message.
  3. Send to Server: The message is sent across the network to the server.
  4. Server Stub: The server stub unpacks the message and calls the actual server procedure.
  5. Execution & Return: The server runs the procedure and returns the result to the stub.
  6. Back to Client: The server stub sends the result back, and the client stub unpacks it.

How to Make a Remote Procedure Call?

Working of RPC

The calling environment is suspended, procedure parameters are transferred across the network to the environment where the procedure is to execute, and the procedure is executed there. When the procedure finishes and produces its results, its results are transferred back to the calling environment, where execution resumes as if returning from a regular procedure call. 

Note : RPC is especially well suited for client-server (e.g. query-response) interaction in which the flow of control alternates between the caller and callee. Conceptually, the client and server do not both execute at the same time. Instead, the thread of execution jumps from the caller to the callee and then back again.

Types of RPC

  • Callback RPC: Both client and server can act as each other. The server can call back the client, useful in interactive applications. Handles deadlocks and supports peer-to-peer communication.
  • Broadcast RPC: The client’s request is broadcast to all servers. Special broadcast ports are used. Useful when multiple servers can handle the request.
  • Batch-mode RPC: Groups multiple client requests and sends them together to the server, reducing network overhead. Best for applications with infrequent calls.

What Does RPC do?

  • RPC (Remote Procedure Call) lets a program use code on another computer as if it were local.
  • A stub acts as a placeholder for the remote code in the client program.
  • When the program calls the remote code, the stub sends the request to a local helper.
  • The helper finds the remote server and sends the request over the network.
  • The server runs the code and sends the result back through its own helpers.
  • The client receives the result, making it look like the code ran locally.

Issues of the RPC

RPC Runtime: A library that manages the communication in RPC. It handles binding, sending/receiving data, choosing the protocol, and dealing with errors.

Stub: A helper code that hides the complexity from the programmer. On the client side, it converts function calls into messages (marshalling/unmarshalling) and works with the runtime to connect to the server.

On the server side, the stub provides a similar interface between the run-time system and the local manager procedures that are executed by the server.

Binding: The most flexible solution is to use dynamic binding and find the server at run time when the RPC is first made. The first time the client stub is invoked, it contacts a name server to determine the transport address at which the server resides. Binding consists of two parts

  • Naming: A Server having a service to offer exports an interface for it. Exporting an interface registers it with the system so that clients can use it.
  • Locating: A Client must import an (exported) interface before communication can begin.

The call semantics associated with RPC

  • Retry Request Message: Whether to retry sending a request message when a server has failed or the receiver didn't receive the message.
  • Duplicate Filtering: Remove the duplicate server requests.
  • Retransmission of Results: To resend lost messages without re-executing the operations at the server side.

Advantages

  • Easy Communication: RPC lets clients talk to servers using normal procedure calls in high-level programming languages. This makes it simple for programmers to work with.
  • Hidden Complexity: RPC hides the details of how messages are sent between computers. This means programmers don't need to worry about the underlying network communication.
  • Flexibility: RPC can be used in both local and distributed environments. This makes it versatile for different types of applications.

Disadvantages

  • Limited Parameter Passing: RPC can only pass parameters by value. It can't pass pointers, which limits what can be sent between computers.
  • Slower Than Local Calls: Remote procedure calls take longer than local procedure calls because they involve network communication.
  • Vulnerable to Failures: RPC depends on network connections, other machines, and separate processes. This makes it more likely to fail than local procedure calls.

RPC vs REST

RPC and REST are two ways to make computer programs talk to each other over the internet. They're different, but both are useful. RPC is good for some things, and REST is good for others. Some companies need RPC, while others prefer REST. Sometimes, developers use both RPC and REST in the same project, but not in the same part of the program. RPC is an old idea, but new versions like gRPC and DRPC are making it popular again. Developers are still using and improving these new types of RPC.

It's hard to say which one is better - RPC or REST. They're both good when used the right way. The best choice depends on what you're trying to do with your program.


Article Tags :
Practice Tags :

Explore