← Back to the map

Unit 1 · Lesson 5

REST vs RPC (gRPC) vs GraphQL

Your mobile app needs a user's name and their last three orders. One API makes it do four calls. Another gives it back in one. A third does it faster between servers. Same data, three styles.

By the end you can

Watch

Prefer reading? The same lesson is written out below.

An API is the menu a service offers to its callers. There are three common ways to write that menu.

REST + JSONGraphQLgRPCWeb appMobile appPublic APIOrders service
A web app calls a public API with REST over HTTP and JSON. A mobile app asks the API for exactly the fields it needs with GraphQL. Inside the company, the API calls an orders service with gRPC.

REST: things and verbs

REST treats everything as a resource with a URL, and uses HTTP methods as the verbs:

GET    /users/42            read user 42
GET    /users/42/orders     read their orders
POST   /users/42/orders     create an order
DELETE /orders/7            delete order 7

It's simple, works with any HTTP client, and plays well with HTTP caching. The catch is that the server decides the shape of each response. A screen that needs bits of several resources may need several calls (under-fetching), or get much more data than it needs (over-fetching).

RPC: call a function

RPC (remote procedure call) makes a network call look like calling a function: getUser(42), placeOrder(cart). gRPC is the popular modern version:

It's a favourite between services inside a company, where speed matters and both sides share the schema. It's less handy for browsers, which can't speak it directly without a proxy.

GraphQL: ask for exactly what you need

GraphQL gives clients one endpoint and a query language. The client describes the shape it wants:

{ user(id: 42) { name  orders(last: 3) { total } } }

and gets exactly that, in one round trip. Great for apps with many different screens, especially mobile on slow networks. The costs: the server is more complex, one innocent-looking query can ask for a huge amount of work (so you need limits), and plain HTTP caching works less well because everything goes through one URL.

Choosing

SituationGood fit
Public API, simple resources, many kinds of callersREST
Service-to-service calls, high volume, low latencygRPC
Many client screens needing different slices of dataGraphQL

Many companies use all three: REST or GraphQL at the edge, gRPC inside.

Key idea: REST is resources plus HTTP verbs; simple and cache-friendly. gRPC is fast, typed function calls, best between services. GraphQL lets the client ask for exactly the data it needs, at the cost of server complexity.

Check yourself

In REST, what does `DELETE /orders/7` mean?

Your new flashcards

Practice them now. With a free account they come back in your daily review.

Card 1 of 4