API design and service boundaries
Design APIs that survive growth, and draw service boundaries around data ownership rather than nouns.
18 min readAn API is a contract you cannot easily take back
Once a mobile app ships calling your endpoint, that version of the contract lives on phones for years. Design for evolution from day one: add fields, never rename or repurpose them, and treat removal as a multi-month deprecation. Resource-oriented REST (GET /projects/42/tasks) suits public, cacheable CRUD; gRPC suits internal, high-volume service-to-service calls where a typed schema and HTTP/2 multiplexing save real latency; GraphQL suits clients that need to stitch many resources into one screen.
- Version in the path (/v1) or a header, and support at least N-1
- Return stable, documented error codes, not just HTTP statuses
- Make every mutating endpoint accept an idempotency key
Pagination and payload size
Offset pagination (?page=500&size=20) forces the database to read and discard 10 000 rows before returning 20, so deep pages get slower linearly and items shift when rows are inserted. Cursor pagination encodes the last seen sort key (for example created_at plus id) in an opaque token: every page is an index seek, cost stays constant, and results do not skip or repeat. Cap page sizes (100 is common) so one request cannot pull a million rows. Return only what the client needs; a 40 KB response at 5 000 requests per second is 200 MB/s of egress you pay for.
Boundaries follow data ownership
A good service owns a set of data and the rules that keep it valid, and nothing else writes that data. Draw boundaries around business capabilities (billing, inventory, identity), not database tables. A useful test: can this service make its most common decision using only its own data? If placing an order needs synchronous calls to five other services, the boundary is wrong, or some data should be copied in via events. Chatty boundaries turn one user request into a fan-out where latency adds up and availability multiplies down.
Availability multiplies
If a request synchronously depends on five services each at 99.9% availability, the best case is 0.999 to the fifth power, about 99.5%: roughly 3.6 hours of downtime a month instead of 43 minutes. Every synchronous hop you add on the canvas shows up in the Feedback panel as extra latency and a lower ceiling on availability. Prefer fewer, coarser calls, and move work that does not need to block the user behind a queue.
Key takeaways
- Evolve APIs additively and version them; clients live longer than you expect
- Use cursor pagination for anything that can grow past a few thousand rows
- A service should own its data and make its core decisions without synchronous calls to others
- Each synchronous dependency multiplies availability down and adds its latency
Sign in to track lessons and earn badges.