Skip to the page

Building blocks of a client architecture · senior

API design for the frontend

Design the client–server contract with example payloads, cursor pagination for live lists, one error shape and idempotency keys for writes. Choose REST, GraphQL or a BFF by what each screen needs in one round trip.

The notes

What you must know

  • Always write one endpoint and one payload: GET /v1/feed?cursor=abc&limit=20 → { items: [...], nextCursor: 'def' | null }.
  • Offset vs cursor: offset allows 'jump to page 7' but shifts when items are inserted (duplicates and gaps) and gets slow at large offsets; an opaque cursor (sort key + id) is stable for live feeds but gives no total count by default.
  • REST: resource URLs, HTTP caching works (GET + Cache-Control/ETag). GraphQL: the client picks fields, one request per screen, typed schema; costs: harder HTTP caching (use persisted queries), server N+1, query cost limits.
  • BFF (backend for frontend): a thin server per client type that aggregates services, shapes payloads, keeps secrets and cuts request waterfalls; Next.js route handlers or server components often play this role.
  • Errors: one shape { error: { code, message, details, retryable } } and correct status codes (400, 401, 403, 404, 409, 422, 429 with Retry-After, 5xx).
  • Writes: POST is not idempotent; send an Idempotency-Key header so a retry after a timeout doesn't create two orders. PUT and DELETE are idempotent by definition.
  • Evolve without breaking: add fields, never change their meaning; version or deprecate. Mobile apps stay installed for months.
  • Real-time, batching and uploads are API decisions too: a batch endpoint for many small reads, SSE/WebSocket for pushes, and pre-signed URLs so big files go straight to storage (chunked/resumable for large videos) instead of through your app server.

The red pen

Common traps: mistake → fix

  • Mistake: GraphQL is always faster

    Fix: it moves complexity to the server and the cache.

  • Mistake: Offset pagination is fine for a live feed

    Fix: new items at the top duplicate items across pages.

  • Mistake: Return 200 with { success: false }

    Fix: breaks retries, monitoring and caching.

  • Mistake: The client can compute prices and totals

    Fix: the server decides; the client only displays.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design the API for this screen. Show one request and response.
  2. Offset or cursor? What breaks with offset?
  3. The user taps 'Place order' and the network times out. What happens when they tap again?
  4. REST, GraphQL or a BFF here?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview