Skip to content

RPC Introduction — Remote Procedure Call Pattern Explained

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about RPC Introduction. We cover key concepts, practical examples, and best practices to help you master this topic.

RPC (Remote Procedure Call) is an API pattern where a client executes a procedure on a remote server as if it were a local function call, with the network communication handled transparently by the RPC framework.

What You'll Learn

  • How RPC differs from REST's resource-oriented model
  • XML-RPC, JSON-RPC, and gRPC implementations
  • When to use RPC vs REST vs Graphql

Why It Matters

gRPC, a modern RPC framework, is increasingly popular for Microservices due to its performance advantages. Understanding RPC helps you choose the right architecture for internal services.

flowchart LR
    A["Client\nadd(2, 3)"] --> B["RPC Framework"]
    B --> C["Serialization"]
    C --> D["Network Transport"]
    D --> E["Server\nfunction add(a,b) { return a + b; }"]
    E --> F["Response: 5"]
    style B fill:#dbeafe,stroke:#2563eb

Code Examples

# JSON-RPC 2.0
import requests

payload = {
    "jsonrpc": "2.0",
    "method": "subtract",
    "params": {"a": 10, "b": 5},
    "id": 1
}
response = requests.post("https://api.example.com/rpc", json=payload)
print(response.json())

Expected output:

{'jsonrpc': '2.0', 'result': 5, 'id': 1}
// JSON-RPC with Node.js
const payload = {
  jsonrpc: '2.0',
  method: 'getUser',
  params: { id: 123 },
  id: 2
};

fetch('https://api.example.com/rpc', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify(payload)
})
.then(res => res.json())
.then(console.log);
# XML-RPC call
curl -X POST https://api.example.com/xmlrpc \
  -H "Content-Type: text/xml" \
  -d '<?xml version="1.0"?>
<methodCall>
  <methodName>examples.getStateName</methodName>
  <params><param><value><int>41</int></value></param></params>
</methodCall>'

Common Mistakes

1. Using RPC for Public APIs

RPC style (verbs in endpoints) confuses REST-experienced developers.

2. Ignoring Error Codes

RPC frameworks include error codes. Always check error in responses.

3. Tight Coupling

RPC's function-call abstraction can hide network failures from developers.

4. Not Handling Network Failures

RPC looks local but is remote. Timeouts, retries, and circuit breakers are essential.

5. Choosing XML-RPC When JSON-RPC Suffices

XML-RPC is verbose. JSON-RPC is simpler and more performant.

Practice Questions

  1. What does RPC stand for and what does it do?
  2. How does JSON-RPC structure its requests?
  3. What is gRPC and why is it fast?
  4. How does RPC differ from REST in philosophy?
  5. When would you choose gRPC over REST?

Answers:

  1. Remote Procedure Call — executes function-like operations on remote servers.
  2. With jsonrpc, method, params, and id fields.
  3. gRPC uses HTTP/2, protobuf encoding, and supports streaming.
  4. RPC is action-oriented (verbs like getUser), REST is resource-oriented (nouns like /users).
  5. For high-performance internal microservices with strict typing requirements.

Challenge: Build a JSON-RPC 2.0 client and server in Python. The server should expose add, subtract, and getUser methods.

FAQ

Is JSON-RPC different from REST?

: Yes. JSON-RPC uses a fixed endpoint with method names in the body; REST uses different URIs for different resources.

What is the main advantage of gRPC over JSON-RPC?

: gRPC uses binary Serialization (protobuf) and HTTP/2, making it much faster than text-based JSON-RPC.

Can gRPC be used from a browser?

: Not directly. Use gRPC-Web or a proxy for browser clients.

What's Next

Learn about REST APIs (resource-oriented) or XML-RPC vs JSON-RPC for a deeper protocol comparison.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro