Interview Q&A · 30 questions · 7 answered publicly
API Design Interview Questions
Ordered by how often they're asked. Sign in free to see every answer, rate your confidence and run timed mock interviews.
-
Most asked What makes an API RESTful, and what are good REST design practices?
Summary
REST models the API as resources identified by URLs, manipulated with standard HTTP methods, using stateless requests and standard status codes and representations. Good practice: noun-based plural resources, correct methods and status codes, consistent JSON, pagination, filtering, versioning and clear errors.
Longer Answer
Examples:
GET /orders?status=paid,POST /orders(201 + Location),GET /orders/42,PATCH /orders/42,DELETE /orders/42(204), sub-resourcesGET /orders/42/items. Use actions sparingly when they don't fit CRUD (POST /orders/42/cancel). Keep naming consistent (snake_case or camelCase), use ISO 8601 dates and UTC, and document with OpenAPI.Key Points
- Resources + HTTP methods
- Correct status codes
- Consistent naming and formats
- Pagination, filtering, versioning
- OpenAPI documentation
-
Most asked Which HTTP methods are safe and idempotent, and why does it matter?
Summary
Safe methods (GET, HEAD, OPTIONS) don't change state; idempotent methods (GET, HEAD, PUT, DELETE, OPTIONS) have the same effect whether called once or many times. POST and PATCH are not idempotent by default.
Longer Answer
Idempotency lets clients, proxies and SDKs retry safely after timeouts. Caches and crawlers assume GET is safe, so never change state on GET. Make POST retry-safe with idempotency keys.
Key Points
- Safe: no state change
- Idempotent: repeatable
- POST/PATCH need idempotency keys
- Never mutate on GET
Comparison / Tradeoffs
Method Safe Idempotent GET Yes Yes PUT No Yes DELETE No Yes POST No No PATCH No No (usually) -
Most asked Which HTTP status codes should an API use, and when?
Summary
200 OK, 201 Created (with Location), 202 Accepted (async processing), 204 No Content; 400 Bad Request (malformed), 401 Unauthenticated, 403 Forbidden, 404 Not Found, 409 Conflict, 412 Precondition Failed, 422 Unprocessable Content (validation), 429 Too Many Requests; 500 Internal Error, 502/503/504 for upstream and availability problems.
Longer Answer
Be consistent and don't return 200 with an error body. Pair 4xx/5xx with a structured error body (RFC 9457 Problem Details), and include
Retry-Afterfor 429/503.Key Points
- 2xx success variants
- 4xx client errors
- 5xx server/upstream errors
- No 200-with-error
- Retry-After for 429/503
-
Most asked Compare offset pagination and cursor (keyset) pagination.
Summary
Offset pagination (
?page=3&size=20→OFFSET 40 LIMIT 20) is simple and allows jumping to pages, but gets slow on deep pages and can skip or duplicate items when data changes. Cursor pagination returns an opaque cursor encoding the last seen sort key (WHERE (created_at, id) < (...) LIMIT 20), which is fast and stable but only supports next/previous.Longer Answer
Use cursors for feeds, large tables and APIs consumed by machines; offsets for small admin lists that need page numbers. Always cap page size, use a deterministic sort with a unique tiebreaker, and return
next_cursor(or Link headers).Code Example
-- keyset pagination: next page after (created_at, id) of the last item SELECT id, title, created_at FROM posts WHERE (created_at, id) < ($1, $2) ORDER BY created_at DESC, id DESC LIMIT 20;Key Points
- Offset: simple, slow when deep, unstable
- Cursor: fast, stable, sequential
- Deterministic sort + tiebreaker
- Cap page sizes
-
Most asked How should you version an API?
Summary
Common approaches are URL path versioning (
/v1/orders), header/media-type versioning (Accept: application/vnd.acme.v2+json) and date-based versions (Stripe'sStripe-Version: 2024-06-20). Whatever you choose, avoid breaking changes within a version, add fields compatibly, and deprecate with notice.Longer Answer
Additive changes (new optional fields, new endpoints) don't need a new version; renames, removals, type changes and semantic changes do. Publish deprecation timelines with
Deprecation/Sunsetheaders, monitor usage of old versions, and provide migration guides.Key Points
- Path, header or date versions
- Additive changes are safe
- Breaking changes need versions
- Deprecation + Sunset headers
-
Most asked How do idempotency keys work for POST requests?
Summary
The client sends a unique
Idempotency-Keyheader per logical operation; the server stores the key with a hash of the request and the resulting response, and if the same key arrives again it returns the stored response instead of performing the operation twice.Longer Answer
Handle concurrent duplicates (lock or 'in progress' state returning 409), reject reuse of a key with a different payload, scope keys per client, and expire them after a retention window (e.g., 24h). Essential for payments and order creation.
Key Points
- Client-generated key per operation
- Store request hash + response
- Handle in-flight duplicates
- Expire keys
-
Most asked When would you choose GraphQL over REST, or gRPC over both?
Summary
GraphQL suits client-driven data needs (many screens/clients needing different shapes, avoiding over/under-fetching) with a typed schema; REST suits resource-oriented public APIs with HTTP caching and simplicity; gRPC suits low-latency internal service-to-service calls with strict contracts and streaming.
Longer Answer
GraphQL trade-offs: caching complexity, N+1 resolvers, query cost control. gRPC trade-offs: browser support needs gRPC-Web/Connect, binary payloads are harder to debug. Many architectures use REST/GraphQL externally and gRPC internally.
Key Points
- GraphQL: flexible client queries
- REST: simple, cacheable, public
- gRPC: fast internal contracts
- Mix by audience
Comparison / Tradeoffs
REST GraphQL gRPC Contract OpenAPI Schema (SDL) Protobuf Caching HTTP-native Harder Custom Best for Public APIs Diverse clients Internal RPC - How should APIs format error responses?
- How do you design reliable webhooks?
- How should APIs support filtering, sorting and field selection?
- Why use OpenAPI (and contract-first design)?
- What counts as a breaking change in an API?
- How should an API communicate rate limits to clients?
- How do you design APIs for long-running operations?
- How do APIs prevent lost updates from concurrent edits?
- What is HATEOAS and is it used in practice?
- How do you design bulk or batch endpoints?
- What naming conventions make APIs easier to use?
- What security practices apply to API design?
- What does an API gateway do, and when do you need one?
- How should APIs represent dates, times and money?
- What makes a great developer experience for a public API?
- PUT vs PATCH: how do you implement updates?
- How do you design event-driven APIs (events between services)?
- How should APIs handle large file uploads and downloads?
- What should a health or status endpoint return?
- How can APIs leverage HTTP caching?
- How do you deprecate an API endpoint responsibly?
- What consistency guarantees should an API document?
- How do APIs handle localization?