Remote Procedure Call (RPC) Protocol in Distributed System

โšก Smart Summary

Remote Procedure Call (RPC) is an interprocess communication protocol that lets a program execute a procedure in another address space or machine, hiding network details behind an ordinary local function call in distributed client-server systems.

  • ๐Ÿ“ž Definition: RPC lets a client invoke a procedure on a remote server as if it were a local call.
  • ๐Ÿ—‚๏ธ Types: Callback, Broadcast, and Batch-mode RPC differ in how requests are routed and queued.
  • ๐Ÿ—๏ธ Architecture: Five parts cooperate on each call: client, client stub, RPC runtime, server stub, and server.
  • ๐Ÿ”„ How It Works: Stubs marshal parameters into a message and unmarshal the result returned to the caller.
  • โš–๏ธ Trade-offs: RPC simplifies distributed code but adds network overhead and failure points versus local calls.
  • ๐Ÿค– AI Angle: gRPC serves machine learning models between microservices, and Copilot speeds up writing RPC stubs.

Remote Procedure Call (RPC) in Distributed System

What is RPC?

Remote Procedure Call (RPC) is an interprocess communication technique used for client-server applications. The full form of RPC is Remote Procedure Call. RPC mechanisms are used when a computer program causes a procedure or subroutine to execute in a different address space, coded as a normal procedure call without the programmer explicitly coding the details for the remote interaction.

This procedure call also manages low-level transport protocols, such as UDP and TCP/IP, to carry the message data between programs.

Types of RPC

Three types of RPC are:

  • Callback RPC
  • Broadcast RPC
  • Batch-mode RPC

Callback RPC

This type of RPC enables a peer-to-peer (P2P) paradigm between participating processes. It helps a process to act as both a client and a server.

Functions of Callback RPC:

  • Handles remotely processed, interactive application problems.
  • Provides the server with the client’s handle.
  • Callback makes the client process wait.
  • Manages callback deadlocks.
  • It facilitates a peer-to-peer paradigm among participating processes.

Broadcast RPC

Broadcast RPC is a client’s request that is broadcast on the network and processed by all servers that have the method for processing that request.

Functions of Broadcast RPC:

  • Allows you to specify that the client’s request message has to be broadcast.
  • You can declare broadcast ports.
  • It helps to reduce the load on the physical network.

Batch-mode RPC

Batch-mode RPC helps to queue separate RPC requests in a transmission buffer on the client side, and then send them over a network in one batch to the server.

Functions of Batch-mode RPC:

  • It minimizes the overhead involved in sending a request, as it sends requests over the network in one batch to the server.
  • This type of RPC protocol is only efficient for applications that need lower call rates.
  • It needs a reliable transmission protocol.

RPC Architecture

RPC architecture has mainly five components of the program:

  1. Client
  2. Client Stub
  3. RPC Runtime
  4. Server Stub
  5. Server

RPC Architecture

RPC Architecture

How RPC Works?

The following steps take place during the RPC process:

Step 1) The client, the client stub, and one instance of the RPC runtime execute on the client machine.

Step 2) The client starts a client stub process by passing parameters in the usual way. The client stub is stored within the client’s own address space. It also asks the local RPC Runtime to send the request to the server stub.

Step 3) In this stage, the user accesses RPC by making a regular local procedure call. The RPC Runtime manages the transmission of messages between the client and server across the network. It also performs the job of retransmission, acknowledgment, routing, and encryption.

Step 4) After completing the server procedure, execution returns to the server stub, which packs (marshals) the return values into a message. The server stub then sends the message back to the transport layer.

Step 5) In this step, the transport layer sends the result message back to the client transport layer, which returns the message to the client stub.

Step 6) In this stage, the client stub demarshals (unpacks) the return parameters in the resulting packet, and execution returns to the caller.

Characteristics of RPC

Here are the essential characteristics of RPC:

  • The called procedure is in another process, which is likely to reside on another machine.
  • The processes do not share address space.
  • Parameters are passed only by values.
  • RPC executes within the environment of the server process.
  • It does not offer access to the calling procedure’s environment.

Features of RPC

Here are the important features of RPC:

  • Simple call syntax.
  • Offers known semantics.
  • Provides a well-defined interface.
  • It can communicate between processes on the same or different machines.

Advantages of RPC

Here are the pros/benefits of RPC:

  • RPC helps clients communicate with servers through the conventional use of procedure calls in high-level languages.
  • RPC is modeled on the local procedure call, but the called procedure is most likely executed in a different process and usually on a different computer.
  • RPC supports process-oriented and thread-oriented models.
  • RPC makes the internal message-passing mechanism hidden from the user.
  • It commits many of the protocol layers to improve performance.
  • RPC provides abstraction; for example, the message-passing nature of network communication remains hidden from the user.
  • RPC can be used in both distributed and local environments.
  • The effort needed to re-write and re-develop the code is minimal.

Disadvantages of RPC

Here are the cons/drawbacks of using RPC:

  • Remote Procedure Call passes parameters by values only; pointer (reference) values are not allowed.
  • Remote procedure call (and return) time โ€” the overhead โ€” is significantly higher than for a local procedure.
  • This mechanism is highly vulnerable to failure, as it involves a communication system, another machine, and another process.
  • The RPC concept can be implemented in different ways, so there is no single standard.
  • It does not offer flexibility for hardware architecture, as it is mostly interaction-based.
  • The cost of the process increases because of the remote procedure call.

FAQs

RPC exposes actions as remote procedures, while REST exposes data as resources accessed over HTTP verbs. RPC feels like calling a local function; REST centers on resources and state.

gRPC is Google’s modern, high-performance RPC framework. It uses HTTP/2 and Protocol Buffers, and supports bidirectional streaming, making it popular for microservice communication.

RPC can be both. A synchronous call blocks until the server returns a result, while an asynchronous call returns immediately and handles the response later. Frameworks like gRPC support both styles.

RPC is a form of IPC that works across separate machines. While many IPC methods share memory on one host, RPC exchanges messages over a network so processes on different computers can cooperate.

Common RPC implementations include gRPC, Apache Thrift, XML-RPC, JSON-RPC, and Java RMI. They differ in data format and transport but all let a client call a procedure on a remote server.

RPC is not secure by default; security depends on the transport. Implementations add TLS encryption, authentication tokens, and access controls to protect calls.

Machine learning platforms use RPC, especially gRPC, to serve model predictions between microservices. A client sends features and receives an inference result, keeping AI systems fast and loosely coupled.

Yes. GitHub Copilot can scaffold .proto service definitions, client stubs, and server handlers for gRPC. Developers should still review generated interfaces, error handling, and versioning before deploying to production.

Summarize this post with: