0%
API Design Interviews: REST, gRPC, GraphQL, Pagination, Idempotency, Versioning and Webhooks
REST, gRPC and GraphQL
Step three of the framework is choosing the style and protocol. By the time you reach it, you know who the consumers are and what the resources look like, and the remaining question is what shape the conversation between them takes. There are three main families you will be expected to know: REST over HTTP with JSON, gRPC with protocol buffers, and GraphQL. This lesson covers how each one works, where each one hurts, and how to choose between them in a sentence or two during the round. It starts with REST, because it is the default for most public APIs and because its semantics come up in every other part of the course.
REST is a style rather than a protocol. In practice, when interviewers say REST they mean resources addressed by URLs, standard HTTP methods for operations on them, status codes that describe the outcome, headers that carry metadata such as caching and content type, and usually JSON bodies. The power of REST is not in any one of those parts. It is that every piece of infrastructure between the client and your server, including browsers, proxies, CDNs, load balancers, API gateways and client libraries, already understands them. If you follow the semantics, all of that machinery works for you. If you break them, it quietly works against you.
Methods and what they promise
Each HTTP method makes a promise. GET retrieves a representation and must not change state. HEAD is a GET without the body. POST asks the server to process the enclosed data, most often to create a new resource under a collection, and promises nothing about repeats. PUT replaces the resource at a known URL with the enclosed representation. PATCH applies a partial change. DELETE removes the resource. OPTIONS describes what is allowed, and browsers use it for cross origin checks.
Two properties summarise the promises. A method is safe if calling it does not change server state from the client's point of view. GET, HEAD and OPTIONS are safe. A method is idempotent if calling it once or ten times with the same input leaves the server in the same state. The safe methods are idempotent, and so are PUT and DELETE. POST is neither safe nor idempotent. PATCH is not guaranteed to be idempotent; a patch that sets a field is, but a patch that appends to a list or increments a counter is not.
These properties are not academic. A browser may prefetch GET links. A proxy may retry an idempotent request after a dropped connection. A mobile HTTP library may automatically retry a GET or a PUT on timeout but will usually refuse to retry a POST. If you implement a GET that changes state, a link prefetcher can delete data. If you implement creation with PUT on a client chosen id, the client can safely retry; if you use POST, you need another mechanism, usually an idempotency key, which lesson five covers in depth.
Status codes as a contract
Status codes tell the client what kind of thing happened, and the class matters more than the exact number. Codes in the 200 range mean success. 200 OK returns a result, 201 Created says a new resource exists and usually comes with a Location header, 202 Accepted says the work was queued and will finish later, and 204 No Content says it worked and there is nothing to return. Codes in the 300 range redirect or, in the case of 304 Not Modified, tell the client that its cached copy is still good. Codes in the 400 range mean the client must change something: 400 for a malformed request, 401 for missing or bad credentials, 403 for credentials that are valid but not allowed, 404 for a resource that does not exist, 409 for a conflict with current state, 422 for a well formed request that fails validation, and 429 for too many requests. Codes in the 500 range mean the server failed: 500 for an unexpected error, 502 and 504 for a failing upstream, and 503 for a temporarily unavailable service.
The most important property of this scheme is what it tells a client to do next. A 2xx means use the result. A 4xx means retrying the same request will fail again, so fix it or give up, with 429 and sometimes 409 as exceptions that may succeed later. A 5xx means the request may be fine and a retry with backoff could work, as long as the operation is safe to repeat. A design that returns 200 with an error flag in the body, or 500 for a validation failure, breaks this and forces every client to parse bodies to decide what happened. Lesson six covers error bodies and code choice in detail; here the point is that REST gives you a shared vocabulary and you should use it.
Caching and conditional requests
HTTP has a caching model that REST APIs can lean on. A response can carry Cache-Control to say how long it may be reused and by whom, and an ETag or Last-Modified validator that identifies the version. A client that already has a copy sends If-None-Match with the ETag, and the server replies 304 Not Modified with no body if nothing changed. For read heavy public data, such as a product catalogue or a list of available regions, this saves bandwidth and server work and lets a CDN serve most traffic. The same validators also support safe updates: a client sends If-Match with the ETag it read, and the server rejects the write with 412 Precondition Failed if someone else changed the resource first. Lesson five returns to this for concurrency control.
Caching only works if GET is genuinely safe and if URLs identify resources consistently. That is another reason the semantics matter: a design that tunnels reads through POST, as some RPC over HTTP designs do, loses HTTP caching entirely.
Representations, content types and links
A REST resource can have more than one representation. The Content-Type header says what the body is, and Accept lets the client ask for a format. In interviews JSON is almost always the answer, and saying so is enough. What deserves a sentence is how you represent things inside the JSON: timestamps as ISO 8601 strings in UTC, money as an integer amount in minor units plus a currency code, identifiers as opaque strings, and enums as lowercase strings that clients are told may gain new values.
Pure REST also includes the idea that responses contain links to related resources and next actions, so clients navigate rather than build URLs. Few production APIs follow that strictly, and interviewers rarely expect it. A practical middle ground is to include URLs where they are genuinely useful, such as a next page link, a Location header on create or a download URL on a file, and to say that clients may still build URLs from documented patterns. Mentioning that you know the idea and are choosing a pragmatic level of it is a better signal than either ignoring it or insisting on it.
Where REST is weak
REST has real costs. A screen that needs a user, their last ten orders and the shipping status of each may need several round trips, which hurts on mobile networks. Fixed responses tend to over fetch, sending fields a client does not need, or under fetch, forcing extra calls. Operations that do not map cleanly to a resource, such as resending a verification email or merging two accounts, need custom actions that some reviewers consider impure. JSON is verbose and untyped on the wire, so clients rely on documentation or a schema such as OpenAPI to know the shape. And there is no built in streaming beyond long polling, server sent events or a separate WebSocket channel, which lesson nine covers. None of these costs rule REST out, and for public APIs its reach usually outweighs them. They are, however, exactly what gRPC and GraphQL were built to address, which is why the next two sections exist.
What the interviewer checks in a REST design
When you choose REST, interviewers tend to probe the same few points. Does every state change avoid GET? Does creation return 201 with a Location header? Is the retry story for POST stated? Do failures use the right status class? Are timestamps, money and ids represented consistently? A design that gets these right in passing earns quiet credit on every endpoint, and frees the rest of the round for harder questions.
Browsers prefetch, crawlers follow links and proxies retry GET freely. A GET that deletes, sends or charges anything will eventually be triggered by something that is not a user. Put every state change behind POST, PUT, PATCH or DELETE.