Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

What Is an API
HLD

What Is an API

Contracts between software — why API design is system design's most durable artifact and how to think about surface area.

The Contract Definition

An API is a promise about behavior: given these inputs, in this state, this output follows. Everything else is implementation — free to change. The promise is the product boundary; the code behind it is negotiable.

 CLIENT                        CONTRACT (the API)              SERVER
 needs a stable thing ◄─────── resources + verbs + errors ───► free to refactor,
 to build against             + versioning rules               reshard, rewrite
 
 contract changes = coordinated migration across every consumer
 implementation change = invisible

This asymmetry drives everything in API design: contracts are expensive, implementations are cheap. Design effort goes into making the contract right.

APIs at Every Altitude

LayerExampleContract shape
System-to-systemRideShare ↔ payment PSPREST/gRPC over network
Service-to-servicetrip service ↔ location servicegRPC, events
LibrarySDK, framework classfunction signatures
Product surfacepublic developer platformversioned REST + webhooks

Same discipline everywhere: explicit inputs/outputs, documented failure modes, evolution policy.

What Makes an API Good

PropertyTest
Hard to misuseWrong usage fails loudly at first call, not in production
ConsistentSame concepts named/shaped the same way across endpoints
Complete error storyEvery failure has a defined representation
EvolvableRoom to add without breaking (pagination, extra fields)
ObservableCallers can tell what happened (ids echoed, status precise)

Consistency deserves emphasis: an API is a language. Each endpoint teaching new grammar taxes every consumer; reusing established patterns (id, created_at, cursor tokens) makes the hundredth endpoint free.

Surface Area Is Liability

Every exposed field, parameter, and endpoint is a permanent maintenance obligation:

 exposing "internal_notes" on GET /users
 → some partner will scrape it within weeks
 → removing it now breaks them
 → you own that field forever

 rule: expose the minimum that enables the use case;
       adding later is cheap, removing is a deprecation project

Interview Framing

System design interviews increasingly include an API-design beat (“define the endpoints”). Strong candidates sketch 4–6 core endpoints with method, path, key request/response fields, and one error case each — then stop. Exhaustive CRUD enumeration wastes clock; the signal is shape judgment: which resources exist, what the identifiers are, where lists paginate.

My Private Notes

Notes are auto-saved locally to this device.