SDE & MLE Prep

API Design

  • REST (resources + HTTP verbs, JSON): the default for public APIs; cacheable GETs. gRPC (Protobuf over HTTP/2): typed, fast, streaming — great between internal services. GraphQL: the client picks fields from one endpoint — avoids over/under-fetching for rich UIs; harder caching and rate limiting (needs query-cost analysis).
  • Idempotency: GET/PUT/DELETE are idempotent by definition; make POSTs safe to retry with an Idempotency-Key header.
  • Pagination: offset/limit is simple but slow and unstable for deep pages on changing data; cursor (keyset) pagination — ?after=<last_id> with WHERE id < :cursor ORDER BY id DESC LIMIT 20 — is stable and O(page size).
  • Versioning (/v1/… or a header), a consistent error format with machine-readable codes, 429 + Retry-After for rate limits, 202 Accepted + job id for long-running work.
  • Authenticate every call (OAuth 2 bearer tokens / API keys), authorize per resource, limit request sizes.
  • In interviews, define 3–5 endpoints with their key parameters — enough to anchor the data model, not a full spec.