API design: REST, RPC and pagination
Shape the contract between systems so it survives growth, retries and version changes.
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
| Choice | You gain | You pay |
|---|---|---|
| REST over HTTP/JSON | Universal tooling, cacheable GETs | Chatty for deep object graphs |
| GraphQL | Clients fetch exactly what they need | Harder caching, query cost control needed |
| gRPC | Typed contracts, efficient binary transport | Awkward from browsers, harder to debug by hand |
Answer these out loud
- 1Design the list endpoint for a timeline that gets new items every second. What is in the cursor?
- 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.
curl https://engineeros-delta.vercel.app/api/v1/topics/api-design