System DesignFoundation14 min

API design: REST, RPC and pagination

Shape the contract between systems so it survives growth, retries and version changes.

See it on the map

An API is the part of your system you cannot easily change, because other people's code depends on it. Model resources as nouns, make operations predictable, and return errors that a program can act on, not just a human.

Pagination is where many APIs quietly break. Offset pagination is simple but skips or repeats rows when data changes between pages and gets slow on deep offsets. Cursor pagination, where the client passes back an opaque token for the last item seen, stays stable and fast.

Plan for evolution from day one: additive changes only inside a version, clear deprecation windows, and fields that clients are told to ignore when unknown.

Key points

  • Prefer cursor pagination for anything that grows or changes while being read.
  • Use stable, machine-readable error codes, not only messages.
  • Additive changes are safe. Renames and removals need a new version.
  • Choose RPC-style endpoints when the operation is an action, not a resource.

Trade-offs

ChoiceYou gainYou pay
REST over HTTP/JSONUniversal tooling, cacheable GETsChatty for deep object graphs
GraphQLClients fetch exactly what they needHarder caching, query cost control needed
gRPCTyped contracts, efficient binary transportAwkward from browsers, harder to debug by hand

Answer these out loud

  1. 1Design the list endpoint for a timeline that gets new items every second. What is in the cursor?
  2. 2A client sends the same create request twice after a timeout. What should the API do?

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/api-design

This unlocks