Open In App

Remote Procedure Calls in Network Abstractions | System Design

Last Updated : 01 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Remote Procedure Call (RPC) is a technique used for making a call to a function or method that resides on a remote server as if it were a local function call. RPC is commonly used in distributed systems where different components of an application run on different computers or servers and communicate with each other over a network. This article explains the basics of RPC, it’s working, and its applications.

RPC stands for Remote Procedure Call, which is a technique for making a call to a function or method that resides on a remote server as if it were a local function call. It is a mechanism for communicating with a server and requesting it to execute a specific method, with the results of the method execution returned to the client.

Why use RPC?

RPC is used in distributed systems where different components of an application run on different computers or servers and communicate with each other over a network. RPC provides a way for these components to interact with each other in a simple and efficient way, abstracting away the complexity of low-level network protocols. RPC makes it possible to develop applications in which different components can be developed independently and then combined together into a working system.

A Typical RPC

Elements of RPC Mechanism:

  1. Client : Client is a user process that initiates a remote call of a procedure (or a method or a function).In other words, it is the program or application that makes the request to a remote server.
  2. Client Stub: Client stub is a code module that resides on client side and acts as a proxy for remote procedures. It marshals the arguments of the procedure call into a format that can be transmitted over the network to the server.
  3. RPC Runtime: The RPC runtime is a software layer that manages the communication between the client and the server. It provides the infrastructure for handling remote procedure calls, including message serialization and deserialization, transport protocol management, and error handling.
  4. Server Stub: The server stub is a code module that resides on the server side and receives the request from the client stub. It unmarshals the arguments, calls the actual procedure, and marshals the return value into a format that can be transmitted back to the client.
  5. Server: The server is the program or application that receives the remote procedure call and executes the requested procedure. It processes the request, generates the response, and sends it back to the client.

How does RPC work?

RPC works by defining a contract between the client and server, specifying the methods that can be called on the server, and then the parameters and return values of those methods. The client then invokes the remote method by sending a message to the server over network. This message includes the name of the method to be invoked, along with any parameters that need to be passed to the method in doing so.

RPC (Remote Procedure Call) is a technique that enables a client program to call a remote server program as if it were a local procedure. The process of making a remote procedure call involves the following steps:

RPC Execution

Below entire process happens behind the scenes, and the client program doesn’t need to worry about the network details or the low-level implementation details of the remote procedure. The RPC system takes care of all of these details, making it much easier for developers to build distributed systems. It is as follows: 

  1. The client procedure initiates the remote procedure call by calling the client stub in the normal way.
  2. The client stub builds a message that contains the procedure name and its parameters and then calls the local operating system (OS).
  3. The client’s OS sends the message over the network to the remote OS.
  4. The remote OS receives the message and passes it to the server stub.
  5. The server stub unpacks the parameters from the message and then calls the actual server procedure.
  6. The server processes the request and returns the result to the server stub.
  7. The server stub packs the result into a message and then calls the local OS.
  8. The server’s OS sends the message over the network to the client’s OS.
  9. The client’s OS receives the message and then gives it to the client stub.
  10. The client stub unpacks the result from the message and then returns it to the client procedure.

RPC offers several benefits, including the ability to build applications that are scalable, flexible, and reliable. By abstracting away the complexity of low-level network protocols, RPC allows developers to focus on the business logic of their applications rather than the details of network communication.

RPC implementations typically use a middleware layer that handles low-level details of network communication, serialization and deserialization of data, and other protocol-specific concerns. This middleware layer provides a higher-level interface for developers to build distributed applications, making it easier to write code that invokes remote methods and handles the corresponding responses.

RPC implementations can use various protocols to transmit data between the client and server, including HTTP, TCP, and UDP. The choice of protocol depends on the specific needs of the application, such as the use case, the level of reliability, and the speed required.

RPC calls can be synchronous or asynchronous. In a synchronous call, the client waits for the server to process the request and return the response before proceeding with further operations. In an asynchronous call, the client sends the request to the server and continues with other operations, without waiting for the server to respond. The server sends the response back to the client when it is ready.

Examples of RPC

Here are a few examples of how RPC can be used in practice:

Example 1: Financial Transactions: Suppose you are building a financial application that needs to execute transactions on a remote server. You might implement an RPC-based interface that allows the client to invoke a “transfer_funds” method on the server, passing in the amount to be transferred and the account details of the sender and recipient.

Example 2: Image Processing: Suppose you are building an application that needs to process images on a remote server. You might implement an RPC-based interface that allows the client to invoke an “apply_filter” method on the server, passing in the image data and the name of the filter to be applied.

Advantages of RPC

  • Abstraction: RPC abstracts away the details of network communication and low-level protocols, making it easier for developers to build distributed applications.
  • Efficiency: RPC can be more efficient than other communication methods, such as HTTP because it uses a more lightweight protocol and can transmit data more quickly.
  • Scalability: RPC is scalable because it allows different components of an application to run on different machines or servers, enabling horizontal scaling.
  • Flexibility: RPC can be used with different languages and platforms, making it a versatile technology for building distributed systems.
  • Interoperability: RPC allows different components of an application to communicate with each other regardless of the programming language or platform used.

Disadvantages of RPC

While RPC has many advantages, it also has some disadvantages:

  • Complexity: RPC can be complex to set up and configure, especially when using different languages and platforms.
  • Tight Coupling: RPC can lead to tight coupling between components of an application, making it harder to change or replace individual components without affecting other parts of the system.
  • Security: RPC calls can be vulnerable to security threats, such as man-in-the-middle attacks if proper security measures are not implemented.

Conclusion: Remote Procedure Calls (RPC) is a technique for calling methods or functions on a remote server as if they were local function calls. RPC abstracts away the complexity of low-level network protocols, making it easier to build distributed applications. RPC implementations can use various protocols to transmit data between the client and server, and can be synchronous or asynchronous. RPC provides several advantages, including abstraction, efficiency, scalability, flexibility, and interoperability, but also has some disadvantages, including complexity, tight coupling, and security concerns.

Overall, RPC is a powerful technology for building distributed systems, but like any technology, it should be used judiciously and with an understanding of its strengths and weaknesses. With the right design and implementation, RPC can be an effective way to build applications that are scalable, flexible, and reliable.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads