API design in system design interviews: REST vs gRPC
REST exposes resources over plain HTTP, usually with JSON, so any client from a browser to a shell script can call it; gRPC defines typed methods in a Protocol Buffers file, sends compact binary messages over HTTP/2 and generates client code, which suits calls between your own services. In a system design interview the usual answer is REST (or GraphQL) at the public edge and gRPC between internal services, justified by who the clients are rather than by speed alone.
By Evin JohnPublished 7 min read
1. What the API step is for
After requirements and estimates, most interview frameworks, including the 45-minute structure we use, ask you to sketch the API: the handful of calls the product needs, with their inputs and outputs. It anchors everything that follows, because the data model must answer those calls and the architecture must serve them at the estimated rate. The protocol choice is one line of that sketch. It deserves a sentence of justification, not ten minutes, unless the interviewer steers there.
2. Why interviewers ask "REST or gRPC?"
It is a quick test of whether you choose tools for reasons. Weak answers say gRPC "because it is faster" or REST "because everyone uses it". Strong answers tie the choice to the client (a browser, a partner, another team's service), the traffic shape (request and response, or a long-lived stream), and operational facts such as caching, debugging and load balancing. It also opens the door to follow-ups on versioning and error handling, which matter more than the protocol.
3. REST in brief
REST, from Roy Fielding's 2000 dissertation, models the API as resources identified by URLs and manipulated with HTTP methods. In practice that means nouns in paths, methods for verbs, status codes for outcomes and JSON bodies.
POST /v1/photos create; returns 201 and the new photo
GET /v1/photos/{photo_id} read one; 200 or 404
GET /v1/users/{user_id}/photos?limit=20&page_token=... list, paginated
PATCH /v1/photos/{photo_id} change the caption; 200
DELETE /v1/photos/{photo_id} 204; repeating it is harmless
POST /v1/photos/{photo_id}/likes like; 201 (or 200 if already liked)- Strengths: works from any HTTP client, readable when debugging, GET responses can be cached by browsers and CDNs using standard headers, and every gateway, proxy and monitoring tool understands it.
- Weaknesses: no enforced schema unless you add one (OpenAPI is the common choice), text payloads are larger than binary ones, and clients often need several round trips or get more fields than they use.
Questions on resource naming, status codes and HTTP semantics are covered in more depth in REST API interview questions.
4. gRPC in brief
gRPC, which Google open-sourced in 2015, starts from a contract file. You declare services, methods and message types in Protocol Buffers, and a compiler generates client and server code in each supported language. Calls look like local function calls. Messages are encoded in protobuf's binary format and sent over HTTP/2, which multiplexes many concurrent calls on one connection.
syntax = "proto3";
service PhotoService {
rpc CreatePhoto(CreatePhotoRequest) returns (Photo);
rpc GetPhoto(GetPhotoRequest) returns (Photo);
rpc ListUserPhotos(ListUserPhotosRequest) returns (ListUserPhotosResponse);
rpc WatchLikes(WatchLikesRequest) returns (stream LikeEvent); // server streaming
}
message Photo {
string photo_id = 1;
string owner_id = 2;
string caption = 3;
int64 created_at_ms = 4;
}The numbers after each field are what goes on the wire, not the names. That is why protobuf messages are small. Encoding a message with field 1 set to 150 and field 2 set to "Ada" by hand gives 8 bytes, 08 96 01 12 03 41 64 61, while the equivalent compact JSON, {"user_id":150,"name":"Ada"}, is 28 bytes. Real savings depend on the data: long strings shrink far less than numbers and field names.
| Style | Shape | Example use |
|---|---|---|
| Unary | One request, one response | Get a user, place an order |
| Server streaming | One request, a stream of responses | Live like counts, tailing a log, download in chunks |
| Client streaming | A stream of requests, one response | Uploading sensor readings, then a summary |
| Bidirectional streaming | Both sides stream independently | Chat relays between services, live transcription |
- Deadlines are built in. A caller sets how long it will wait, and the deadline travels with the call to downstream services, so a slow chain gives up together instead of piling up work.
- Browsers are the gap. Browsers do not expose the HTTP/2 control gRPC needs, so web clients typically use gRPC-Web through a proxy or a REST or JSON gateway in front of the gRPC services.
- Load balancing needs care. Long-lived HTTP/2 connections carry many calls, so a load balancer that balances connections rather than requests can pin most traffic to a few servers. Use a balancer that works per request, or client-side balancing.
5. Where GraphQL fits
GraphQL gives clients a typed schema and lets each query ask for exactly the fields it needs, often across several resources in one request. It suits products with many client screens that each want a different slice of data, typically behind a single gateway that calls REST or gRPC services underneath. Costs: HTTP caching is harder because most queries are POSTs to one URL, and a single query can be expensive enough that servers need depth or cost limits. See GraphQL interview questions for that side.
6. Side by side
| REST | gRPC | GraphQL | |
|---|---|---|---|
| Contract | Optional (OpenAPI) | Required (.proto), code generated | Required (schema) |
| Payload | Usually JSON text | Protobuf binary | JSON text |
| Transport | HTTP/1.1 or newer | HTTP/2 | Usually HTTP POST |
| Streaming | Not native; use SSE or WebSockets | Four styles built in | Subscriptions, usually over WebSockets |
| Browser use | Native | Through gRPC-Web or a gateway | Native |
| HTTP caching | Strong for GET | Not with standard HTTP caches | Weak; needs client or persisted-query caching |
| Debugging by hand | Easy (curl, browser) | Needs tools that know the schema | Easy with an explorer |
| Typical home | Public and partner APIs | Internal service-to-service calls | Client-facing aggregation layer |
7. Decisions that matter more than the protocol
- Pagination on every list call: a limit plus an opaque page token. See pagination.
- Idempotency for creates and payments: a client-supplied key, so retries are safe. See idempotency.
- Errors with a stable machine-readable code and a human message. REST maps them to status codes (400, 404, 409, 429, 503); gRPC has its own codes such as NOT_FOUND, ALREADY_EXISTS, RESOURCE_EXHAUSTED and UNAVAILABLE.
- Authentication and authorization on every call: tokens at the edge, service identity (often mutual TLS) inside.
- Rate limits per client or key, signaled with 429 or RESOURCE_EXHAUSTED. See the rate limiter design.
- Versioning: a /v1 path or header for REST; for protobuf, add new fields with new numbers, never reuse or renumber a field, and treat removed numbers as reserved.
8. Choosing in a design
| Boundary | Usual choice | Reason to say |
|---|---|---|
| Mobile or web app to backend | REST, or GraphQL for many varied screens | Native in browsers, cacheable, easy to evolve with clients you do not control |
| Third-party developers | REST with an OpenAPI description | Lowest barrier to entry; any language and tool works |
| Service to service inside the company | gRPC | Typed contracts across languages, smaller payloads, deadlines, streaming |
| Server pushes to a browser | WebSockets or server-sent events | Neither REST nor plain gRPC pushes to browsers natively; see WebSockets vs long polling |
| Bulk or asynchronous work | A message queue, not a synchronous API | The caller should not wait for work measured in minutes |
9. Interview questions on API design
| Question | What to cover |
|---|---|
| When would you choose gRPC over REST? | Internal, high-volume, multi-language calls or streaming; schema and deadlines matter |
| Why not gRPC for the public API? | Browser support needs a proxy, harder to debug, partners expect HTTP and JSON |
| How do you version an API? | Additive changes first; /v2 or new methods only for breaking changes; protobuf field-number rules |
| Which HTTP status for a duplicate create? | 409 Conflict, or 200 with the existing resource if the create is idempotent by key |
| How do you design errors? | Stable codes, messages, a retryable flag, and a request ID for support |
| What makes gRPC efficient? | Binary encoding, HTTP/2 multiplexing on long-lived connections, generated code |
| How do you load balance gRPC? | Per-request (layer 7) or client-side balancing, because connections are long-lived |
| REST or GraphQL for a mobile app with many screens? | GraphQL can cut round trips; REST is simpler to cache and secure; pick by client diversity |
10. Mistakes to avoid
- Choosing on speed alone. Network and database time usually dwarf serialization; give the client-based reason first.
- Verbs in REST paths (/getPhoto, /createUser) instead of methods on resources.
- Lists with no limit or token, and creates with no idempotency story.
- Breaking protobuf compatibility by renumbering or reusing field numbers.
- Spending the API step on syntax. Five calls with inputs and outputs are enough; move on.
11. How to talk about it in the interview
- List the calls first, protocol second.
- Name the protocol per boundary with one reason each: client type, traffic shape, tooling.
- Add pagination, idempotency and errors to the sketch without being asked.
- If you pick gRPC, mention deadlines and load balancing; if REST, mention caching.
Fictional example
- Interviewer
- What do the APIs look like, and what protocol do you use?
- Candidate
- The customer and courier apps call a REST API at the gateway: POST /v1/orders with an idempotency key, GET /v1/orders/{id}, and a paginated GET for order history. REST because it works with every client and the menu reads can be cached at the CDN.
- Candidate
- Behind the gateway, the order, payment and dispatch services talk over gRPC. They are written in different languages, the generated clients keep the contracts in sync, and every call carries a deadline so a slow payment check cannot hold up dispatch.
- Interviewer
- How does the app learn the courier's position?
- Candidate
- A WebSocket from the app to a location gateway, which subscribes to the dispatch service's location stream internally. That is the one place a push channel earns its cost.
Practicing the API step with Natively
The API step is short, which is why rambling in it costs so much. Time yourself in a mock interview while Natively transcribes the session on your computer, then check how long the API part took and whether you justified each protocol. During the mock you can request a suggested answer or likely follow-up questions with a shortcut, and ask it to draw the service boundaries as a diagram. A screenshot of an API spec or a problem statement can be read and explained too.
Questions people ask
What is the difference between REST and gRPC?
REST models an API as resources at URLs, used with HTTP methods and usually JSON bodies, so any HTTP client can call it. gRPC defines typed methods in a Protocol Buffers file, generates client and server code, and sends binary messages over HTTP/2 with built-in streaming and deadlines. REST is easier for public and browser clients; gRPC suits internal service-to-service calls.
Is gRPC faster than REST?
Often per call, because protobuf messages are smaller than JSON and HTTP/2 reuses one connection for many calls. In most systems, network and database time matter more than encoding, so choose by client type, contracts and streaming needs rather than raw speed.
Can browsers call gRPC services directly?
Not with standard gRPC, because browsers do not give web pages the low-level HTTP/2 control it needs. Web apps typically use gRPC-Web through a proxy, or call a REST or GraphQL gateway that talks gRPC to the services behind it.
What should the API section of a system design interview include?
The few calls the product needs with their inputs and outputs, pagination on list calls, idempotency for creates, an error model, authentication and how you would version the API. Add the protocol choice per boundary with one reason each, and keep the whole step to a few minutes.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
