Networking & API DesignIntermediate17 min read3 questions

API Design: REST vs gRPC vs GraphQL

The API is the contract every other decision has to live with. How to choose a protocol, design endpoints that survive five years of change, and get pagination and idempotency right.

Covers: Resource modelling, idempotency, pagination, versioning, error contracts, protocol selection, backwards compatibility

In an interview you will be asked to sketch an API within the first ten minutes. It is a small artefact that reveals a lot: whether you think in resources or in RPCs, whether you have felt the pain of a breaking change, and whether you know what happens when a client retries.

Filter
0/3 mastered
IntermediateapirestgrpcAsked at Meta, Netflix

30-second answer

REST for public APIs and anything cached by HTTP infrastructure - it is universally understood and works with every proxy, CDN and browser. gRPC for internal service-to-service calls where you want a typed contract, binary efficiency, streaming and code generation. GraphQL when many diverse clients need different shapes of the same data and over-fetching is the real problem - typically a mobile app plus a web app against a rich domain. Most large companies use all three: REST at the public edge, gRPC internally, GraphQL as a client-facing aggregation layer.

AdvancedidempotencyapireliabilityAsked at Stripe, Amazon

30-second answer

Make the operation idempotent with a client-generated idempotency key. The client sends a unique key with the request; the server stores the key together with the response in a table with a uniqueness constraint before doing the work. A retry with the same key returns the stored response instead of executing again. The critical details are that the key must be recorded in the same transaction as the effect, that concurrent duplicates must be serialised by the unique constraint rather than a read-then-write check, and that in-flight duplicates should get a 409 rather than a second execution.

IntermediateapipaginationversioningAsked at Stripe, Slack

30-second answer

Use cursor-based pagination, not offset. `OFFSET 100000` makes the database scan and discard 100,000 rows, so page 10,000 is catastrophically slow, and rows inserted while the user pages cause items to be skipped or duplicated. A cursor encodes the last seen sort key and becomes a `WHERE (created_at, id) < (?, ?)` predicate that uses the index directly - constant time regardless of depth, and stable under concurrent inserts. For versioning, prefer additive, backwards-compatible changes; when you must break, version in the URL path for public APIs and run both versions concurrently with a published deprecation window.

Showing 3 of 3 questions for api-design-rest-grpc-graphql.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.Which HTTP method is NOT inherently idempotent?

Question 2

2.Why is `LIMIT 20 OFFSET 100000` slow even with an index on the sort column?

Question 3

3.Two concurrent requests arrive with the same idempotency key. What is the correct behaviour for the second?

Question 4

4.Which API change is safely backwards compatible?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Design the API for a booking service

Write the complete HTTP contract for a service that lets users search, hold and confirm seat bookings. Contracts, not code.

Requirements

  • Define 5–6 endpoints with methods, paths, request and response shapes.
  • Make seat confirmation safely retryable, and write out the idempotency-key flow including the concurrent-duplicate case.
  • Paginate search results with a cursor, and specify the sort key and tie-breaker.
  • Define a consistent error envelope with machine-readable codes and appropriate status codes.
  • Describe how you would add a 'seat preferences' feature six months later without a version bump.

Stretch goals

  • Specify rate limits per endpoint and the headers you return when a client is throttled.
  • Write the equivalent contract as a `.proto` file and note what changes.