RPC
Understand Remote Procedure Calls (RPC), gRPC architecture, Protocol Buffers, HTTP/2 transport, client-server stubs, and how RPC compares to REST.
Lesson goal
By the end of this lesson, you will understand what RPC and gRPC are, how Protocol Buffers define type-safe API contracts, how remote operations work under the hood, and how RPC compares with REST.
When applications communicate across a network, they need a structured way to exchange messages. While REST models communication around manipulating resources, RPC (Remote Procedure Call) introduces one of the most intuitive models in computing: calling a function that runs on another machine.
What is RPC?
RPC (Remote Procedure Call) is a communication paradigm that allows a program to execute a function on a remote computer as if it were a local function call:
Call a procedure (function) that physically executes on another server.
Instead of constructing HTTP request URLs, query parameters, and headers manually, developers write standard function calls.
// Local function call (executes in the local memory space)
getUser(42)
// Remote Procedure Call (looks identical, but executes across the network)
const user = await getUser(42)Behind the scenes, the client runtime transforms the function invocation into a network message:
The client transmits the target function name and serialized parameters over the network. The server receives the payload, executes the function, and returns the result.
Core idea
RPC abstracts network communication so that remote operations look and feel like local function calls.
Simple RPC Example
Imagine a remote microservice that exposes a simple math function:
add(a: number, b: number): numberThe client invokes it like any standard asynchronous function:
const result = await add(10, 20)
console.log(result) // 30Under the hood, the client and server exchange a structured request-response message:
The client developer does not need to know what database, operating system, or internal logic the server uses to produce the result.
What is gRPC?
gRPC is an open-source, high-performance universal RPC framework originally created by Google in 2015. It evolved from Stubby, Google's internal RPC system designed to connect tens of thousands of microservices with ultra-low latency.
What does the 'g' stand for?
While gRPC stands for Google Remote Procedure Call, Google officially assigns a playful codename to the letter "g" for each release version (e.g., v1.0 gRPC, v1.1 good, v1.2 green, v1.4 geeky, v1.10 glorious).
Instead of requiring teams to build custom networking logic, gRPC provides a standardized framework that handles:
- Binary Serialization: Compact, high-speed encoding using Protocol Buffers.
- Modern Transport: Multiplexed streaming over HTTP/2.
- Automated Code Generation: Type-safe client stubs and server boilerplate across multiple programming languages.
RPC vs. gRPC
It is important to distinguish the general computing concept from the specific framework:
- RPC is the architectural concept (calling remote functions).
- gRPC is a modern, production-grade implementation of that concept created by Google.
RPC vs. REST
The fundamental difference between REST and RPC lies in the mental model used to design the API:
REST (Resource-Oriented)
APIs are modeled around nouns (resources) manipulated through standard HTTP verbs:
GET /users/42 # Retrieve user
POST /users # Create user
DELETE /users/42 # Delete userRPC (Operation-Oriented)
APIs are modeled around verbs (procedures / actions):
getUser(42) // Retrieve user
createUser({ ... }) // Create user
deleteUser(42) // Delete userComparison Table
| Feature | REST | RPC (gRPC) |
|---|---|---|
| Core Abstraction | Resources ("What entity am I modifying?") | Operations ("What function am I invoking?") |
| Transport | HTTP/1.1 or HTTP/2 | HTTP/2 (Multiplexed streams) |
| Payload Format | JSON, XML (Human-readable text) | Protocol Buffers (Compact binary) |
| Contract / Schema | Optional (OpenAPI / Swagger) | Strict & Required (.proto files) |
| Streaming | Limited (Server-Sent Events, WebSockets) | Native Unary, Server, Client, & Bidirectional Streaming |
| Best Use Cases | Public APIs, web apps, standard CRUD, HTTP/CDN caching | Internal microservices, low latency, high throughput |
Choosing the right model
Neither paradigm is universally superior. REST excels for external public APIs and web clients benefiting from HTTP caching, while gRPC is the industry standard for high-performance internal microservices.
Under the Hood: The Network Lifecycle
Even though RPC syntax looks identical to a local function call, it is still a network transaction.
When you execute an RPC call, the framework coordinates a multi-step lifecycle:
The RPC framework hides the serialization, transport, and deserialization boilerplate so you can focus on application logic.
Key Takeaways
- RPC (Remote Procedure Call): An architectural paradigm that makes invoking a function on a remote server feel like calling a local function.
- gRPC: A high-performance, open-source RPC framework created by Google, built on HTTP/2 and Protocol Buffers.
- Protocol Buffers: A language-neutral, type-safe IDL and binary serialization format used to define service interfaces and data schemas.
- REST vs. RPC: REST is resource-oriented (nouns), while RPC is operation-oriented (verbs).
- Microservices Powerhouse: gRPC is widely adopted for internal microservices due to its compact binary payloads, HTTP/2 multiplexing, and cross-language code generation.
RPC makes remote communication feel like calling a function, while gRPC provides the modern protocol, serialization, and tooling to make that communication fast, reliable, and scalable.