ByteByteGo's visual breakdowns of API styles are excellent. Supplement with the REST API Design guide at restfulapi.net.
An API is a contract between services. In system design interviews, defining the API is Step 3's first task: what can clients do, what do they send, what do they get back? A clear API prevents scope creep and grounds your architecture.
| API Style | Best For | Avoid When |
|---|---|---|
| REST | Public APIs, browser clients, CRUD operations | Need extreme performance or streaming |
| GraphQL | Mobile clients with limited bandwidth, complex nested data | Simple CRUD, backend-to-backend |
| gRPC | Internal microservice communication, streaming, low latency | Public APIs, browser clients without proxy |
Default to REST for external APIs, gRPC for internal service-to-service communication. Say "I'll use REST for the client-facing API since it's universally supported, and gRPC for internal service communication for the performance benefit."
In interviews, you'll usually sketch 2–4 REST endpoints. Know these conventions cold:
| Verb | Meaning | Idempotent? |
|---|---|---|
GET | Read — no side effects | Yes |
POST | Create — always creates new resource | No |
PUT | Replace entire resource | Yes |
PATCH | Update specific fields | No (usually) |
DELETE | Remove resource | Yes |
Never return all records at once. Two main patterns:
GET /posts?page=3&limit=20
→ skip 60, take 20
Simple to implement.
Problem: if items are added/deleted
during pagination, pages shift —
items are skipped or duplicated.
GET /posts?after=post_id_abc&limit=20
→ posts after this cursor
Stable: items added/deleted don't
shift the cursor position.
Standard for social feeds, timelines.
Used by Twitter, Instagram, GitHub.
An operation is idempotent if performing it multiple times produces the same result as once. Critical for distributed systems where retries are common.
POST /payments { amount: 100 }
→ Network times out, client retries
→ POST /payments { amount: 100 } again
→ Two charges of $100!
POST /payments
Idempotency-Key: uuid-123-abc
{ amount: 100 }
→ Server stores result for this key
→ Retry with same key → same response
→ No double charge!
APIs must be protected from abuse. Rate limiting allows N requests per time window per client (by API key, user ID, or IP). Responses:
429 Too Many Requests — standard rate limit exceeded responseX-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-ResetDeep dive: Lesson 16 — Rate Limiting
APIs change over time. Breaking changes require versioning so old clients aren't broken:
/v1/users → /v2/users — explicit, easy to routeAccept: application/vnd.api+json; version=2/users?version=2URL versioning is the most common in practice. Deprecate old versions gracefully — give clients 6–12 months notice.