← back

What is RPC and How is it Different from an API?

nov 7, 2026 · 6 min read · networking, backend, engineering

You've heard of APIs. Everyone has. But if you've spent any time in backend or systems work, you've also run into the term "RPC" usually right next to something like gRPC or tRPC and it's not always clear what it actually means or how it's different.

Here's the short version: all RPCs are a kind of API, but not all APIs are RPC. The difference is in how you think about what you're calling.


What is RPC?

RPC stands for Remote Procedure Call.

A "procedure call" is just a function call. When you write calculateTotal(cart) in your code, that's a procedure call. The function lives in memory, your program jumps to it, runs it, and comes back with the result.

RPC takes that idea and extends it across a network. You call a function that looks like it's local same syntax, same feel but it actually runs on another machine. The network part is hidden from you.

Your Code                     Remote Server
─────────────────────────────────────────────
getUserById(42)   ──────────► runs the function
                 ◄──────────  returns the User

Your code doesn't know it crossed a network. It just called a function and got a result back.


How does it actually work?

There's a small piece of machinery involved called a stub (sometimes called a proxy). You don't write it it's generated for you.

Here's what happens under the hood when you call getUserById(42):

  1. Your call hits a client stub a local stand-in for the remote function
  2. The stub serializes your arguments (packs them into bytes)
  3. Those bytes travel over the network to the server
  4. A server stub unpacks them and calls the real function
  5. The result gets serialized and sent back
  6. Your client stub unpacks it and returns it to you
Client                          Server
──────────────────────────────────────────────────────
getUserById(42)
  → client stub
    → serialize: { id: 42 }
      → network ──────────────► server stub
                                  → deserialize
                                    → getUserById(42) runs
                                  ← serialize result
              ◄─────────────── network
  ← client stub returns User
← you get the User

From your side, it looked like a normal function call.


So what is an API then?

An API (Application Programming Interface) is a broader concept. It's any defined interface that lets one piece of software talk to another. RPC is one style of API. REST is another. GraphQL is another.

The difference comes down to how you model the interaction:

| Style | You think in terms of... | Example | |-------|--------------------------|---------| | REST | Resources | GET /users/42 | | RPC | Actions / functions | getUser(42) | | GraphQL | Data shapes | { user(id: 42) { name } } |

With REST, you're interacting with nouns /users, /orders, /products. The HTTP verb (GET, POST, PUT, DELETE) describes what you're doing to the resource.

With RPC, you're calling verbs getUser, createOrder, deleteProduct. The focus is on the action, not the resource.

Neither is wrong. They're different mental models for the same underlying problem: one machine needs to get something done on another machine.


A concrete example

Say you're building a system where a frontend needs to fetch a user's profile.

REST style:

GET /users/42

The URL names a resource. The method (GET) names the operation. The server maps that combination to a handler.

RPC style:

getUser({ id: 42 })

You're calling a function. The function name carries the intent. There's no URL structure to design or learn.

Both get you the same user. The difference is in how the calling code is written and how the server contract is defined.


gRPC the most common RPC framework today

The most widely used RPC system today is gRPC, built by Google. It uses two technologies that make it fast:

Protocol Buffers (Protobuf) a compact binary format for serializing data. Much smaller than JSON. Faster to encode and decode.

HTTP/2 supports multiple requests over one connection simultaneously, and streaming (sending data as a continuous flow instead of one big response).

You define your service in a .proto file:

service UserService {
  rpc GetUser (UserRequest) returns (User);
}

message UserRequest {
  int32 id = 1;
}

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
}

From this file, gRPC generates client and server code in whatever language you need. The generated client has a getUser() method. You call it. The framework handles the rest.


RPC vs REST when to use which

Use REST when:

  • You're building a public API
  • Your clients are web browsers
  • You want maximum compatibility with tools, caches, and proxies
  • The resource model fits naturally (things like /posts, /comments)

Use RPC (gRPC) when:

  • You're connecting internal services to each other (microservices)
  • You need high throughput and low latency
  • You want streaming (real-time updates, large data transfers)
  • You want strict, generated contracts between services

One thing worth knowing: browsers can't directly call gRPC services. The low-level HTTP/2 primitives gRPC relies on aren't exposed to browser JavaScript. If your client is a browser, you need a proxy layer (like gRPC-Web) or you use something else.


tRPC RPC for TypeScript

If you're in a TypeScript project and your backend and frontend are in the same repo, there's a newer option worth knowing about: tRPC.

tRPC skips the .proto files and code generation entirely. You define functions on the server in TypeScript, and the client gets full type safety automatically just by importing the type of your router. No separate schema language. No codegen step.

It's not as fast as gRPC and it only works within TypeScript, but for a full-stack TypeScript app it's dramatically simpler.


The one-line summary

An API is the general concept of a contract between two pieces of software. RPC is a style of API where you call remote functions as if they were local ones. REST is a different style where you interact with resources over HTTP. gRPC is a modern, fast implementation of RPC built by Google.

Which you use depends on who your clients are, how much performance you need, and how much complexity you're willing to carry.

← all posts