need to understand how remote calls work RPC (Concept)
need to understand how remote calls work RPC (Concept)
Understanding How Remote Procedure Calls (RPC) Work (Concept)
Remote Procedure Call (RPC) is a concept that allows a program to execute a function or method on a remote server as if it were a local function call.
How RPC Works (Conceptually)
Client Calls a Function
- A client program calls a function (
getUserDetails()
) that is actually located on a remote server.
Request Serialization
- The function call's parameters (data) are converted into a format that can be transmitted over a network (e.g., JSON, Protocol Buffers, XML, Binary).
Network Transmission
- The serialized data is sent over a network (via HTTP, TCP, UDP, WebSockets, etc.).
Server Receives the Request
- The server's RPC system deserializes the request and calls the actual function on the server.
Function Execution & Response
- The server executes the function (
getUserDetails()
) and sends the response back to the client.
Client Receives the Response
- The client deserializes the response and continues execution as if the function ran locally.
RPC Conceptual Flow:
Client βββ> (Serialize Data) βββ> Network βββ> Server
Server βββ> (Execute Function) βββ> Return Response βββ> Client
Example of a Basic RPC Concept
Scenario: A client wants to retrieve user details from a remote server.
Local Function Call (If It Were Local)
def get_user_details(user_id):
return {"id": user_id, "name": "Alice"}
response = get_user_details(123)
print(response) # Output: {'id': 123, 'name': 'Alice'}
Here, the function executes locally inside the same program.
How It Works in RPC (Conceptual View)
Client Call:
Instead of running locally, the client calls the function remotely.
Client Calls: getUserDetails(123)
β
Request is Serialized (JSON, ProtoBuf, etc.)
β
Request is Sent Over the Network
β
Server Receives and Deserializes Request
β
Server Executes: getUserDetails(123)
β
Server Returns Response
β
Client Receives and Deserializes Response
β
Client Continues Execution
From the clientβs perspective, it looks like a normal function call, but it's actually running on a remote server.
RPC vs. Normal Function Calls
| Feature | Local Function Call | Remote Procedure Call (RPC) |
|---------|---------------------|----------------------------|
| Execution Location | Runs on the same machine | Runs on a remote server |
| Data Passing | Direct memory access | Data is serialized and sent over the network |
| Performance | Fast (no network delay) | Slower (network latency) |
| Complexity | Simple | Requires handling network failures, serialization, security |
| Use Case | Local programs | Microservices, Cloud APIs, Distributed Systems |
Real-World Use Cases of RPC
Microservices Communication β Services talk to each other in cloud-native applications.
Database Requests β Clients call database functions remotely.
Remote System Administration β Commands are executed on remote servers.
Game Servers & Multiplayer Apps β Actions from one player affect other players over a network.
Final Thoughts
- RPC is just a concept β A method of calling remote functions.
- RPC Frameworks (gRPC, Thrift, JSON-RPC) help implement RPC easily.
- Used in Microservices, Cloud, and High-Speed Applications.
Would you like a real-world RPC example with Python using gRPC or Thrift?