Remote Procedure Call (RPC): Architecture, Working, Steps & Examples

COMPUTER NETWORKS • CHAPTER 33
Remote Procedure Call (RPC): Architecture, Working, Steps & Examples
Suppose your program needs a function called getStudentResult().

If the function exists inside the same program, the call is simple.

But what if that function is running on another computer connected through a network?

Instead of writing all the networking code manually, Remote Procedure Call tries to make the remote function look similar to an ordinary local function call.
Client Calls remote procedure
Stub Packs parameters
Network Carries request and reply
Server Executes procedure
Direct Answer

RPC or Remote Procedure Call is a communication mechanism in which a program calls a procedure running in another process or on another computer as if it were a normal local procedure.

RPC hides much of the low-level network communication through components such as the client stub, RPC runtime, server stub and remote procedure.

Parameters are converted into a transferable form through marshalling, sent across the network, reconstructed through unmarshalling, processed by the server and then returned to the client.

What Is Remote Procedure Call?

Remote Procedure Call (RPC): Architecture, Working, Steps & Examples

RPC stands for:

Remote Procedure Call

RPC is a technique used in distributed systems and network applications.

It allows one program to request the execution of a procedure that exists in another process, often on another computer.

Simple Definition: RPC allows a program to call a function on another computer almost like calling a normal local function.

The word almost is important.

A remote call cannot be completely identical to a local call because the request must travel through a network and network failures can occur.

Why Do We Need RPC?

Without RPC, a programmer may need to manually handle:

  • Creating network messages
  • Opening communication channels
  • Encoding parameters
  • Sending requests
  • Receiving replies
  • Decoding results
  • Handling communication errors

RPC hides much of this low-level work.

Main Goal: Make distributed communication easier for the programmer by making a remote request look similar to a procedure call.

Local Procedure Call vs Remote Procedure Call

Local Procedure Call

Procedure and caller run inside the same machine or process environment.

Caller
Function

Remote Procedure Call

Procedure may run inside another process or on another machine.

Client
Remote Server
Point Local Procedure Call Remote Procedure Call
Location Same local environment Different process or remote machine
Network Required Normally no Often yes
Latency Very low Higher because communication crosses process or network boundaries
Failure Type Mainly local program failures Includes network, server and timeout failures
Parameter Handling Normal memory call mechanism Parameters often require marshalling

RPC Architecture

The easiest way to understand RPC is to follow the complete request path.

RPC Request Path
Client Program Calls remote function
Client Stub Packs arguments
RPC Runtime / Network Sends request
Server Stub Unpacks arguments
Server Procedure Executes operation
RPC Architecture Trick: Client -> Client Stub -> Network -> Server Stub -> Server Procedure

The reply follows the reverse path.

Main Components of RPC

Client The program that wants a remote service.
Client Stub Acts as a local representative of the remote procedure.
RPC Runtime Handles communication between client and server sides.
Network Carries the RPC request and response.
Server Stub Receives the request and reconstructs procedure parameters.
Server Procedure Performs the requested work.

RPC Client

The client is the program that needs a service from another process or machine.

For example:

Student application wants:

getResult(rollNumber)

The client does not directly perform the server's work.

It calls the local client stub.

What Is a Client Stub?

The client stub looks like a normal local function to the client program.

Its main job is to prepare the remote request.

Client Program Calls:

getResult(2201)
Client Stub Converts the call into an RPC request message.

The client stub performs tasks such as:

  • Collecting procedure parameters
  • Marshalling data
  • Adding procedure identification
  • Passing the message to RPC runtime
Client Stub: Local-looking representative of the remote function.

RPC Runtime

RPC runtime provides the actual communication support underneath the stubs.

Depending on the RPC system, it may handle:

  • Transport communication
  • Message transmission
  • Timeouts
  • Retries
  • Addressing
  • Binding support

What Is a Server Stub?

The server stub receives the request message from the RPC runtime.

Its main jobs are:

  • Unmarshal request parameters
  • Call the actual server procedure
  • Collect the return value
  • Marshal the result
  • Send the response back
Client Stub: Pack request.

Server Stub: Unpack request and call server function.

Remote Server Procedure

The actual server procedure performs the requested task.

Example:

getResult(2201)

Server database finds marks and returns:

92

What Is Marshalling?

Procedure parameters cannot always be copied directly across a network.

They need to be converted into a standard transferable representation.

Marshalling: The process of collecting procedure parameters and converting them into a message format suitable for transmission.
Parameters
2201, "MCA"
Marshalling
Pack values
Network Message
Transferable bytes
Server
Reconstruct values

What Can an RPC Request Message Contain?

Example RPC Request Envelope
RPC REQUEST
Procedure
getResult
Parameter
rollNumber = 2201
Request ID
87521

What Is Unmarshalling?

Unmarshalling is the reverse of marshalling.

Unmarshalling: The process of extracting data from the received RPC message and rebuilding the original procedure parameters or return values.
Easy Trick: Marshalling = Pack
Unmarshalling = Unpack

RPC Binding

Before a client can send an RPC request, it must know how to reach the correct RPC server.

This process is called:

Binding
RPC Binding Concept
Client
Needs service named StudentResultService.
Binder / Registry
Provides server address or endpoint information.
Server
Client can now send the RPC request to the correct service.
Binding: Find where the remote service is running.

How Does RPC Work?

RPC working can be understood as a request-and-response process.

CLIENT SIDE
SERVER SIDE
Client Application

Client Stub

RPC Runtime
1. Procedure Call
2. Marshalled Request
3. Remote Execution
4. Marshalled Result
5. Result Returned
RPC Runtime

Server Stub

Server Procedure

RPC Working Steps

1
Client Calls Local Stub The client program calls a function that looks local.
2
Client Stub Marshals Parameters Procedure name and arguments are converted into a request message.
3
RPC Runtime Sends Request The message is transmitted to the remote server.
4
Server Stub Receives Request It unmarshals the incoming parameters.
5
Remote Procedure Executes The real server-side function performs the requested task.
6
Server Stub Marshals Result The return value is packed into a response message.
7
Response Travels Back RPC runtime sends the reply to the client machine.
8
Client Stub Unmarshals Result The return value is reconstructed and passed back to the client program.
RPC Working Trick: Call -> Pack -> Send -> Unpack -> Execute -> Pack Result -> Send Back -> Return

Synchronous RPC

In a synchronous RPC, the client normally waits for the server to complete the requested operation and return a result.

Client Sends request.

Waits for reply.
Server Executes remote procedure.

Returns result.
Synchronous RPC: Call → Wait → Receive Result → Continue

Asynchronous RPC

Some distributed systems support asynchronous remote calls.

In such a design, the client may send a request and continue doing other work instead of blocking until the complete result arrives.

Asynchronous behaviour depends on the RPC framework. Traditional RPC teaching usually begins with synchronous request-response behaviour.

Parameter Passing in RPC

Parameter passing becomes more difficult when client and server are in different address spaces.

A normal memory pointer from one machine is usually meaningless on another machine.

Important: RPC cannot simply send a raw local memory pointer and expect the remote server to access the same memory location.

Instead, RPC systems usually pass:

  • Primitive values
  • Strings
  • Structures
  • Serialized objects
  • References represented through higher-level RPC mechanisms

Data Representation Problem

Client and server may use different:

  • Hardware architectures
  • Byte order
  • Programming languages
  • Data formats

Therefore a standard external data representation may be required.

Purpose of Data Representation: Make sure both sides interpret transmitted values in the same way.

RPC Failure Problems

A remote call can fail in ways that do not exist in a normal local procedure call.

Request Lost Client sends request, but the network drops it.
Reply Lost Server completes the procedure, but the response is lost.
Server Crash Server may fail before, during or after executing the operation.
Client Crash Client may disappear while the server is processing the request.
Network Delay A slow response may look like a lost request.
Duplicate Request Retrying a request may cause the operation to run more than once.
Key RPC Problem: After a timeout, the client may not know whether:

1. The request never reached the server.
2. The server executed it but the reply was lost.
3. The server is simply slow.

RPC Call Semantics

Because network messages can be lost or repeated, RPC systems define different call semantics.

At-Least-Once Retry until a response is received.

Procedure may execute more than once.
At-Most-Once Duplicate requests are detected so the operation is not executed more than once.
Exactly-Once Ideal goal: operation executes exactly once.

Difficult to guarantee perfectly in the presence of failures.

At-Least-Once Semantics

In at-least-once semantics, if the client does not get a response, it may retransmit the request.

This increases the chance that the procedure executes.

But duplicate execution is possible.

At-least-once semantics are safer for operations that can be repeated without causing unwanted side effects.

At-Most-Once Semantics

At-most-once semantics attempt to prevent duplicate procedure execution.

The RPC system can use:

  • Unique request identifiers
  • Duplicate-request detection
  • Stored previous replies
At-Most-Once: Zero or one execution, but not repeated execution.

Why Is Exactly-Once RPC Difficult?

Exactly-once sounds simple:

Execute the remote procedure exactly one time.

But imagine:

  1. Server executes the operation.
  2. Server sends the reply.
  3. Reply is lost.
  4. Client times out.

Now the client does not know whether the operation executed.

This is why practical distributed systems often provide carefully defined at-most-once, at-least-once or application-level transactional guarantees rather than claiming perfect failure-independent exactly-once RPC execution.

Idempotent Operations in RPC

An operation is idempotent if repeating it produces the same intended state as performing it once.

Example: setStatus("ACTIVE") Repeating the same operation can leave the final state unchanged.
Example: transferMoney(1000) Repeating the operation may transfer money more than once.
Idempotent Trick: Repeat it → final intended state stays the same.

RPC Transparency

RPC tries to provide location transparency.

The programmer can call a remote service using a procedure-like interface without manually handling each network message.

Programming Transparency Client code can look similar to a local function call.
Location Transparency The caller may not need to know every low-level network detail.
But Not Perfect Transparency Network delay, partial failure and remote crashes still make RPC different from local calls.
Very Important: A remote call is not truly the same as a local call. RPC only tries to make programming easier by hiding some communication details.

Advantages of RPC

Simple Programming Model Remote services can be called using procedure-like interfaces.
Hides Low-Level Networking Stubs and runtime handle message construction and communication details.
Supports Distributed Applications Client and server components can run on separate machines.
Modular Design Service implementation can be separated from client applications.
Reusable Services Many clients may call the same server-side service.
Language / Platform Support Modern RPC frameworks can support communication across languages and platforms through defined interfaces and data formats.

Limitations of RPC

Network Delay Remote calls are slower than local function calls.
Partial Failure One machine can fail while the other remains running.
Serialization Cost Parameters must be encoded and decoded.
Timeout Complexity A timeout does not always tell whether the server executed the request.
Duplicate Execution Retries can repeat non-idempotent operations unless controlled.
Version Compatibility Client and server interface changes must be managed carefully.

Simple RPC Examples

Example 1 — Student Result Service
Client calls getResult(2201).
Client stub marshals roll number 2201.
Server stub unmarshals 2201.
Server reads result from database.
Result is returned to client.
Example 2 — Banking Balance Service
Client calls getBalance(accountId).
RPC request travels to banking server.
Server returns the account balance.
Example 3 — Cloud Service
Application calls createVirtualMachine(config).
Remote cloud service receives serialized configuration.
Server starts provisioning and returns a response.

Examples of RPC Technologies

RPC ideas appear in technologies such as:

  • Sun / ONC RPC
  • DCE RPC
  • Microsoft RPC
  • gRPC
  • XML-RPC
  • JSON-RPC
These systems do not all work in exactly the same way, but all use the general idea of requesting remote operations through structured messages and defined interfaces.

RPC in OSI and TCP/IP Context

RPC is often studied near Session Layer topics because it deals with communication between distributed application processes.

However, RPC is not simply a mandatory OSI Session Layer protocol.

In modern TCP/IP systems, RPC frameworks are usually implemented at the application or middleware level and use lower-layer transport services such as TCP or HTTP/2.

Exam-Friendly View: RPC provides higher-level process communication.

Transport protocols move RPC messages.

Modern RPC frameworks usually sit above Transport Layer services.

Solved RPC Examples

Example 1: RPC Delay

Suppose:

Client-to-Server Delay = 20 ms
Server Processing = 10 ms
Server-to-Client Delay = 20 ms

Ignoring extra overhead:

RPC Response Time = 20 + 10 + 20
= 50 ms
Answer = approximately 50 ms

Example 2: Marshalling Overhead

Suppose:

Marshalling = 3 ms
Network Round Trip = 30 ms
Server Processing = 8 ms
Unmarshalling = 3 ms
Total = 3 + 30 + 8 + 3
= 44 ms
Answer = 44 ms

Example 3: Retry Problem

A client sends:

transferMoney(1000)

The server executes the transfer, but the reply is lost.

The client retries the RPC.

If duplicate requests are not detected, the money may be transferred twice.

This is why non-idempotent operations need careful request identification and duplicate handling.

Example 4: At-Most-Once

Suppose request ID is:

Request ID = 9001

The server executes request 9001 and stores its result.

If the same request ID arrives again:

The server can return the stored result instead of executing the operation again.

Example 5: Idempotent Operation

Operation:

setPrinterMode("COLOR")

Executing it once:

Printer Mode = COLOR

Executing it again:

Printer Mode = COLOR
Final state is unchanged, so this operation is idempotent.

RPC Remember Tricks

RPC: Call a remote function like a local function.
Client Stub: Pack the request.
Server Stub: Unpack the request.
Marshalling: Pack parameters.
Unmarshalling: Unpack parameters.
Binding: Find the server.
Synchronous RPC: Call and wait.
At-Least-Once: May execute more than once.
At-Most-Once: Never execute more than once.
Idempotent: Repeat operation, same final intended state.

Common RPC Exam Mistakes

1. RPC means Remote Packet Call.

Wrong. RPC stands for Remote Procedure Call.
2. A remote procedure call is exactly the same as a local function call.

Wrong. RPC only tries to provide a similar programming style. Remote calls have network delay and failure problems.
3. Client stub executes the server procedure.

Wrong. Client stub prepares and sends the request. The actual procedure executes on the server side.
4. Marshalling means receiving a reply.

Wrong. Marshalling means packing parameters or results into a transferable representation.
5. Unmarshalling means encryption.

Wrong. Unmarshalling reconstructs original values from received data.
6. Raw local memory pointers can always be sent directly in RPC.

Wrong. A pointer meaningful in one address space may be meaningless on another machine.
7. A timeout always means the server did not execute the procedure.

Wrong. The server may have executed the procedure and the reply may have been lost.
8. At-least-once means exactly one execution.

Wrong. It means the procedure executes one or more times.
9. At-most-once guarantees the procedure always executes.

Wrong. It means the procedure executes zero or one time, not more than once.
10. Every RPC operation is safe to repeat.

Wrong. Non-idempotent operations can produce unwanted duplicate effects.
11. RPC is only a Transport Layer protocol.

Wrong. RPC is a higher-level distributed communication mechanism that uses lower-layer transport services.
12. Binding means marshalling parameters.

Wrong. Binding means locating or associating the client with the required remote service endpoint.

40 Important RPC Questions With Answers

1. What is RPC?
RPC is Remote Procedure Call, a mechanism that allows a program to request execution of a procedure running in another process or on another computer.
2. What is the main goal of RPC?
The main goal is to make remote service invocation look similar to a local procedure call while hiding much of the low-level communication work.
3. What are the main RPC components?
Client, client stub, RPC runtime, network, server stub and server procedure.
4. What is a client stub?
A client stub is a local representative of the remote procedure that prepares the remote request.
5. What is a server stub?
A server stub receives the RPC request, unmarshals parameters, calls the real procedure and prepares the response.
6. What is marshalling?
Marshalling is the process of converting procedure parameters or results into a transferable message representation.
7. What is unmarshalling?
Unmarshalling is the reverse process of rebuilding procedure parameters or results from a received message.
8. What is RPC binding?
Binding is the process of locating or associating a client with the endpoint of the required remote service.
9. What does RPC runtime do?
RPC runtime handles lower-level communication tasks such as message transmission, addressing, timeout and retry support depending on the RPC system.
10. What is the first step in RPC?
The client calls the local client stub for the required remote procedure.
11. What happens after the client calls the stub?
The client stub marshals the parameters and passes the request to the RPC runtime.
12. What happens at the server side after a request arrives?
The server stub unmarshals the request parameters and calls the actual server procedure.
13. How does the server return a result?
The server procedure returns the result to the server stub, which marshals it and sends it back through the RPC runtime.
14. What is synchronous RPC?
In synchronous RPC, the client usually waits for the remote procedure to finish and return a result.
15. What is asynchronous RPC?
In asynchronous RPC, the client may continue other work instead of blocking until the complete remote result is returned.
16. Why is RPC slower than a local procedure call?
RPC includes marshalling, network transmission, remote processing, reply transmission and unmarshalling overhead.
17. Why are pointers difficult in RPC?
Because a memory address valid in one process or machine may not refer to the same data in another address space.
18. Why is data representation important in RPC?
Client and server may use different hardware, byte ordering or programming languages, so they need a common transmitted representation.
19. What is a request ID?
A request ID uniquely identifies an RPC request and can help detect duplicate retransmissions.
20. What can happen if an RPC request is lost?
The client may timeout and retransmit the request depending on the RPC system.
21. What can happen if an RPC reply is lost?
The client may believe the request failed even though the server already executed the procedure.
22. What is at-least-once semantics?
It means the RPC system retries so the procedure executes one or more times.
23. What is the main risk of at-least-once semantics?
The remote procedure may execute multiple times if duplicate requests occur.
24. What is at-most-once semantics?
It means a remote request is executed zero or one time, but never more than once.
25. How can at-most-once execution be supported?
By using unique request IDs, duplicate detection and possibly caching previous replies.
26. Why is exactly-once RPC difficult?
Because after a failure or lost reply the client may not know whether the server already performed the operation.
27. What is an idempotent operation?
An operation is idempotent if repeating it produces the same intended final state as performing it once.
28. Give one idempotent RPC example.
setStatus("ACTIVE") can be idempotent because repeating it leaves the status ACTIVE.
29. Give one non-idempotent RPC example.
transferMoney(1000) may be non-idempotent because repeating it can transfer money multiple times.
30. What is RPC transparency?
RPC transparency means hiding some remote communication details so a remote operation appears similar to a local procedure call.
31. Is RPC completely transparent?
No. Network latency, timeouts and partial failures make remote calls fundamentally different from local calls.
32. Name one advantage of RPC.
It simplifies distributed application programming by hiding much low-level message communication.
33. Name one disadvantage of RPC.
Remote calls can fail because of network problems even when the local application remains running.
34. Is RPC a Transport Layer protocol?
No. RPC is a higher-level communication mechanism that uses transport services underneath.
35. What is ONC RPC?
ONC RPC is a well-known RPC system originally associated with Sun Microsystems and distributed network services.
36. What is gRPC?
gRPC is a modern remote procedure call framework that commonly uses Protocol Buffers for interface and message definitions and HTTP/2 for transport.
37. If one-way delay is 15 ms each side and server processing takes 10 ms, what is the simplified RPC time?
15 + 10 + 15 = 40 ms, ignoring other overhead.
38. If marshalling takes 2 ms, network round trip 30 ms, server processing 5 ms and unmarshalling 2 ms, what is total time?
2 + 30 + 5 + 2 = 39 ms.
39. What does the server stub do with the result?
It marshals the result into a response message and passes it to the RPC runtime for transmission back to the client.
40. Give the easiest RPC memory line.
RPC means call a remote function through stubs: pack parameters, send request, execute remotely, return the result.

20 RPC MCQs With Answers

1. RPC stands for:

A. Remote Packet Control
B. Remote Procedure Call
C. Routing Procedure Call
D. Remote Process Channel

Answer: B
2. Main purpose of RPC is:

A. MAC address learning
B. Calling a remote procedure
C. IP fragmentation
D. Frequency allocation

Answer: B
3. Client stub mainly performs:

A. Routing
B. Marshalling and request preparation
C. Ethernet switching
D. DNS caching only

Answer: B
4. Server stub mainly performs:

A. Unmarshalling and server procedure invocation
B. IP addressing
C. CRC calculation only
D. Routing table update

Answer: A
5. Marshalling means:

A. Packing parameters into a message
B. Routing a packet
C. Closing TCP only
D. Assigning a MAC address

Answer: A
6. Unmarshalling means:

A. Encrypting packets
B. Reconstructing data from received message
C. Changing IP version
D. Increasing TTL

Answer: B
7. RPC binding is used to:

A. Locate the remote service
B. Fragment IP packets
C. Assign port 80
D. Compress Ethernet

Answer: A
8. In synchronous RPC, the client normally:

A. Waits for the reply
B. Never sends a request
C. Changes its IP address
D. Performs routing

Answer: A
9. Which can cause RPC failure?

A. Lost request
B. Lost reply
C. Server crash
D. All of these

Answer: D
10. At-least-once semantics can execute an operation:

A. Zero times only
B. One or more times
C. Exactly zero times
D. Never remotely

Answer: B
11. At-most-once semantics means:

A. Unlimited execution
B. Zero or one execution
C. At least two executions
D. Exactly five executions

Answer: B
12. Which helps detect duplicate RPC requests?

A. Request ID
B. MAC vendor name
C. Subnet class
D. CRC polynomial only

Answer: A
13. Idempotent operation means:

A. Repeated execution gives the same intended final state
B. Operation can run only once
C. Operation uses IPv6 only
D. Operation has no parameters

Answer: A
14. Which is more likely non-idempotent?

A. setStatus("ON")
B. transferMoney(1000)
C. getName()
D. readStatus()

Answer: B
15. RPC usually uses:

A. Lower-layer transport communication
B. No network service
C. Only Physical Layer
D. Only Data Link Layer

Answer: A
16. Which is a modern RPC framework?

A. gRPC
B. ARP
C. CSMA/CD
D. ICMP only

Answer: A
17. Which is NOT normally a benefit of RPC?

A. Simplified distributed programming
B. Hiding low-level networking details
C. Zero network latency
D. Reusable remote services

Answer: C
18. A lost RPC reply creates uncertainty because:

A. Client may not know whether server executed request
B. IP address disappears permanently
C. Ethernet cable changes type
D. TCP port becomes MAC address

Answer: A
19. Exactly-once RPC is difficult mainly because of:

A. Partial failures and lost messages
B. HTML tags
C. Monitor resolution
D. Keyboard layout

Answer: A
20. RPC is best remembered as:

A. Call remote function through messages and stubs
B. Route packets using shortest path
C. Convert MAC to IP
D. Encrypt Wi-Fi frames

Answer: A

Frequently Asked Questions

What is RPC in simple words?

RPC is a mechanism that lets a program call a procedure running in another process or on another computer using a procedure-like interface.

What are the main components of RPC?

The main components are the client, client stub, RPC runtime, network, server stub and server procedure.

What is a client stub?

A client stub is a local representative of the remote procedure that collects parameters and prepares the RPC request.

What is a server stub?

A server stub receives the RPC request, unmarshals parameters, calls the actual procedure and prepares the reply.

What is marshalling?

Marshalling means converting procedure parameters or return values into a message representation suitable for transmission.

What is unmarshalling?

Unmarshalling reconstructs original values from the received RPC message.

What is RPC binding?

RPC binding is the process of locating and associating the client with the required remote service endpoint.

What is synchronous RPC?

In synchronous RPC, the client normally waits until the remote operation finishes and a response is returned.

What is at-most-once RPC?

At-most-once semantics aim to ensure that a request is executed zero or one time, but never more than once.

What is at-least-once RPC?

At-least-once semantics may retry a request until a response is obtained, so the remote operation may execute more than once.

Why is exactly-once RPC difficult?

Because after network or server failure, a client may not know whether a remote operation already executed before the reply was lost.

What is an idempotent operation?

An idempotent operation produces the same intended final state when repeated as when performed once.

Is RPC a Session Layer protocol?

RPC is commonly discussed near higher-level communication and Session Layer concepts, but modern RPC frameworks are generally implemented at the application or middleware level and use lower transport services.

RPC Quick Revision
Full Form: Remote Procedure Call
Main Goal: Call remote service like a function
Client Stub: Prepare request
Server Stub: Unpack and invoke procedure
Marshalling: Pack parameters
Unmarshalling: Unpack parameters
Binding: Find remote server
Synchronous RPC: Client waits for reply
At-Least-Once: One or more executions
At-Most-Once: Zero or one execution
Exactly-Once: Difficult to guarantee perfectly after failures
Idempotent: Safe final state after repeated execution
Main Risk: Partial failure
RPC Path: Client → Stub → Network → Stub → Server

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources