RPC
Remote Procedure Call
In short
RPC is a communication style in which a program calls a function that runs on another machine as if it were a local function, hiding the network in between.
What is RPC?
A remote procedure call lets code on one computer run a function on another computer through what looks like an ordinary function call, such as getUser(42). Behind the scenes, the arguments are serialized, sent over the network, and executed on the server, and the result is sent back and returned to the caller. The idea dates back to the late 1970s and early 1980s and still underpins much of how distributed systems and microservices talk to each other.
An RPC system usually starts from an interface definition that lists the available procedures with their parameters and return types. From it, tools generate client stubs, local functions that handle serialization and networking, and server code that receives calls and invokes the real implementation. Popular implementations include gRPC, which uses Protocol Buffers over HTTP/2, JSON-RPC, a lightweight protocol that sends JSON messages, and Apache Thrift. JSON-RPC 2.0, for example, is the message format behind the Language Server Protocol used by code editors and the Model Context Protocol used by AI tools.
RPC is like phoning a colleague and asking them to calculate the quarterly total: you ask for an action by name and wait for the answer, without caring how they do it. The catch is that the network is never truly invisible. A remote call can be slow, time out, or fail halfway through, so good RPC clients set timeouts, retry carefully with exponential backoff, and prefer idempotent operations.
RPC is most often compared with REST. RPC is organized around actions, like createInvoice or sendReminder, while REST is organized around resources, like /invoices/42, that are manipulated with standard HTTP methods. RPC tends to feel natural for internal service-to-service calls with a strict contract, and REST is more common for public web APIs. Note that gRPC is one specific RPC framework, not a synonym for RPC in general.
Key takeaways
- RPC makes a call to code on another machine look like a local function call.
- Client stubs serialize the arguments and send them; the server runs the function and returns the result.
- gRPC, JSON-RPC, and Apache Thrift are common RPC implementations.
- Remote calls can fail or time out, so they need timeouts and careful retries.
- RPC is action-oriented, while REST is resource-oriented.
Example
// A minimal client stub: remote calls look like local ones
async function call(method, params) {
const res = await fetch("https://api.example.com/rpc", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", method, params, id: 1 }),
});
const reply = await res.json(); // {"jsonrpc":"2.0","result":{...},"id":1}
if (reply.error) throw new Error(reply.error.message);
return reply.result;
}
// The caller just names the procedure and passes arguments
const user = await call("getUser", { id: 42 });Readers ask
What is the difference between RPC and REST?
RPC exposes actions you call by name, such as transferMoney, usually through a single endpoint or a generated client. REST exposes resources at URLs, such as /accounts/42, and uses standard HTTP methods and status codes to act on them.
Is gRPC the same as RPC?
No. RPC is the general idea of calling remote functions, and gRPC is one open-source framework that implements it, using Protocol Buffers for messages and HTTP/2 for transport.
Is RPC synchronous?
Conceptually, the caller waits for a result, like a normal function call. In practice, modern RPC libraries expose calls as asynchronous functions or promises so the caller isn't blocked, and some also support streaming and one-way notifications.
See also
- gRPCBackend & APIs, p. 20gRPC is an open-source framework for calling functions on a remote server as if they were local, using Protocol Buffers and HTTP/2 for fast, typed messages.
- REST APIBackend & APIs, p. 38A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- APIBackend & APIs, p. 2An API is a set of rules that lets one piece of software request data or actions from another in a predictable, documented way.
- SerializationBackend & APIs, p. 41Serialization is the process of converting in-memory data structures into a format such as JSON or bytes, so they can be stored or sent over a network.
- MicroservicesSoftware Architecture, p. 27Microservices are an architectural style where an application is split into small, independently deployable services that communicate over a network.
- SOAPBackend & APIs, p. 44SOAP is an XML-based messaging protocol for web services that wraps each request and response in a strict envelope, usually defined by a formal WSDL contract.
Spotted a mistake or something missing on this page?Suggest an edit