API Design Senior cheat sheet: interview answers

Every question of this level with its correct answer and explanation, on one page for a quick review before the interview.

  1. 1. How do you choose between REST, GraphQL and gRPC for a new system?

    Correct answer: By consumers and constraints, not by fashion

    Many systems mix them: gRPC between services, a GraphQL or REST BFF for clients, and REST for public partners.

  2. 2. What is an 'API as a product' mindset?

    Correct answer: Treating the API's consumers as customers

    Internal APIs benefit too: other teams are customers whose productivity depends on your design.

  3. 3. Why establish API governance (style guide, reviews, linting) in an organization with many teams?

    Correct answer: So all APIs feel like one consistent platform

    Automate what you can (Spectral rules, breaking-change checks) and keep human review for modeling decisions.

  4. 4. How do Hyrum's Law and 'be conservative in what you send' interact in API evolution?

    Correct answer: Expose little and document guarantees explicitly

    Even error message text, default sort orders or response timing can become something clients rely on.

  5. 5. How does date-based API versioning (like Stripe's) work?

    Correct answer: Each account is pinned to the version it started with

    It allows frequent small changes without breaking existing integrations, at the cost of maintaining transformations for old versions.

  6. 6. What's the main cost of supporting many API versions at once?

    Correct answer: Each version multiplies testing and code paths

    Publish support windows (e.g. 12 months after deprecation) and measure who still uses old versions.

  7. 7. How can you remove a widely used field safely?

    Correct answer: Deprecate it, measure usage, then remove it

    Usage telemetry per field and per client is what makes confident removals possible.

  8. 8. Why is changing default behavior (e.g. a default page size) a breaking change?

    Correct answer: Clients relying on it get different results

    Defaults are part of the contract. Introduce new behavior opt-in or under a new version.

  9. 9. An API writes to a primary database and serves reads from replicas. A client creates an item and immediately lists items without seeing it. How should the API design handle this?

    Correct answer: Return the created item and offer read-your-writes

    Document consistency guarantees per endpoint. Clients can use the create response instead of re-reading immediately.

  10. 10. How should a multi-step operation spanning several services be exposed in an API?

    Correct answer: As an async operation resource with clear states

    Clients poll the operation or receive events; the backend handles retries and compensation.

  11. 11. How should idempotency keys behave when the first request is still in progress and a retry arrives?

    Correct answer: The retry waits or gets a 409, without new work

    Store the key before doing work, with a status. Release or expire locks if the worker crashes.

  12. 12. How long should a server keep idempotency keys?

    Correct answer: Long enough for real retry windows, e.g. 24 hours

    Expiring keys bounds storage. Clients must not reuse keys for different operations.

  13. 13. What problem does a 'thin event' webhook design solve?

    Correct answer: Receivers fetch the current state themselves

    The trade-off is an extra API call per event. 'Fat' events save calls but need versioning and ordering care.

  14. 14. How should a webhook system handle a subscriber that has been failing for days?

    Correct answer: Backoff, then disable the endpoint and notify

    An event log with replay lets consumers recover after fixing their endpoint.

  15. 15. What are risks of sending webhooks to arbitrary customer-provided URLs?

    Correct answer: SSRF into internal networks and tied-up workers

    Send webhooks from isolated egress infrastructure with strict network rules.

  16. 16. How do you design an API endpoint whose underlying query is expensive and popular?

    Correct answer: Cache it, paginate and rate limit per client

    Also make sure clients can use conditional requests so unchanged data costs almost nothing.

  17. 17. What does an API's p99 latency SLO imply for its dependencies?

    Correct answer: Tail latencies add up across sequential calls

    With several downstream calls per request, the slowest one dominates. Fan-out amplifies tail latency.

  18. 18. How should a public API protect itself from abusive or expensive usage patterns?

    Correct answer: With layered limits on rate, size and cost

    OWASP API4 and API6 (unrestricted access to sensitive business flows) cover both resource and business abuse.

  19. 19. What is cost-based rate limiting?

    Correct answer: Each request consumes points by how expensive it is

    GitHub's GraphQL API uses a point-based limit computed from the query's cost.

  20. 20. Why does HTTP/2 change the trade-offs around batching many small API requests?

    Correct answer: Multiplexing makes many small requests cheaper

    Per-request server work (auth, DB queries) still adds up, so batching can still help for heavy operations.

  21. 21. Why are persisted (allow-listed) queries valuable for public GraphQL APIs?

    Correct answer: The server runs only known queries, sent by ID

    For first-party apps, the build step can register all queries. Third-party APIs often still need complexity limits.

  22. 22. How should a GraphQL schema model mutations for good client experience?

    Correct answer: Specific mutations with input and payload types

    Returning changed objects lets normalized client caches update without refetching.

  23. 23. What's a risk of exposing database models directly as a GraphQL schema?

    Correct answer: The API gets coupled to storage and leaks fields

    Design the schema around client use cases and domain concepts, and add authorization per field where needed.

  24. 24. Why might introspection be disabled for a public GraphQL API in production?

    Correct answer: It reveals the whole schema to anyone

    It's not real security, since schemas can be inferred, but it reduces easy reconnaissance.

  25. 25. What are the backward-compatibility rules for Protocol Buffers messages?

    Correct answer: Never change or reuse field numbers

    Protobuf encodes field numbers, not names, so renaming is wire-safe, but renumbering corrupts data between versions.

  26. 26. Which gRPC features go beyond a typical REST API?

    Correct answer: Streaming, deadlines and generated typed clients

    Deadlines are especially useful: each hop knows how much time is left for the whole request.

  27. 27. How can you expose a gRPC service to browsers and REST clients without duplicating logic?

    Correct answer: Use gRPC-Web or a JSON transcoding gateway

    Google's APIs use HTTP annotations in protos to serve the same methods as REST and gRPC.

  28. 28. What's the difference between OWASP API1 (BOLA) and API5 (Broken Function Level Authorization)?

    Correct answer: BOLA is about objects; BFLA is about functions

    Both need server-side checks: per object (ownership) and per operation (role or permission).

  29. 29. What does OWASP API6:2023 (Unrestricted Access to Sensitive Business Flows) warn about?

    Correct answer: Flows that can be abused through automation

    Mitigations include device fingerprinting, CAPTCHAs for humans, per-account limits and anomaly detection.

  30. 30. What does OWASP API9:2023 (Improper Inventory Management) refer to?

    Correct answer: Forgotten old versions and undocumented hosts

    Keep an inventory of every deployed API version and environment; retire old ones.

  31. 31. What does OWASP API10:2023 (Unsafe Consumption of APIs) cover?

    Correct answer: Trusting data from third-party APIs too much

    Responses from partners are untrusted input. Validate them like user input.

  32. 32. Why should JWT access tokens for APIs be validated strictly?

    Correct answer: Forged tokens or ones for another service may pass

    Audience checks stop a token issued for service A being replayed against service B.

  33. 33. What does mutual TLS (mTLS) add for service-to-service APIs?

    Correct answer: Both sides present certificates to prove identity

    Service meshes often automate mTLS. Authorization policies still decide what each service may do.

  34. 34. How can an API minimize the impact of leaked credentials?

    Correct answer: Scoped, short-lived tokens and quick revocation

    Support two active keys per client so they can rotate without an outage.

  35. 35. Which metrics best describe an API's health from the consumer's point of view?

    Correct answer: Request rate, error rate and latency percentiles

    Per-client breakdowns show when one integration breaks even if global numbers look fine.

  36. 36. How should SLOs for a public API be defined?

    Correct answer: Per user-facing capability, with error budgets

    Error budgets balance reliability and change: when the budget is spent, focus shifts to stability.

  37. 37. Why propagate W3C traceparent headers through APIs?

    Correct answer: To trace one request across services

    OpenTelemetry uses W3C Trace Context by default. Accept it from trusted callers and pass it downstream.

  38. 38. How can you roll out a risky API change safely?

    Correct answer: Behind a flag, as a canary, with quick rollback

    Shadow traffic (replaying real requests against the new version) can also catch differences before release.

  39. 39. What is the 'long-running operation' pattern in Google's API guidelines?

    Correct answer: Slow methods return an Operation resource to poll

    A standard operation shape lets SDKs provide generic waiting helpers across all slow methods.

  40. 40. What problem do 'field masks' solve in update operations?

    Correct answer: They state exactly which fields an update touches

    Without a mask, older clients that don't know a new field may wipe it with a full PUT.

  41. 41. Why might an API use resource-oriented 'custom methods' like POST /orders/42:cancel?

    Correct answer: Some operations don't fit CRUD

    Google's AIP-136 describes custom methods; other guides use sub-resources like /orders/42/cancellation.

  42. 42. How do you design pagination for a feed that must stay consistent while new items arrive?

    Correct answer: Cursor pagination over a stable sort key

    Separate 'load newer' and 'load older' cursors are typical for timelines.

  43. 43. What's a good way to expose computed aggregates that are expensive, like monthly revenue per customer?

    Correct answer: Precompute them and expose read-only resources

    Document how fresh the numbers are (e.g. updated hourly) so clients don't treat them as real-time.

  44. 44. How can an API support offline-first mobile clients?

    Correct answer: Delta sync, idempotent writes, conflict detection

    Client-generated IDs (UUIDs) let the app create records offline and sync them later without duplicates.

  45. 45. What's the trade-off of exposing a generic query API (e.g. OData filters or raw GraphQL access to all data)?

    Correct answer: Client flexibility versus unpredictable performance

    Constrain what can be queried and measure actual usage before widening it.

  46. 46. Why can 'chatty' internal APIs become a problem in microservices?

    Correct answer: Each request triggers many calls, multiplying latency

    If two services constantly call each other, their boundary may be in the wrong place.

  47. 47. What's a downside of putting too much logic into an API gateway?

    Correct answer: It becomes a shared bottleneck coupling teams

    Keep gateways for cross-cutting concerns; put client-specific aggregation into BFFs owned by client teams.

  48. 48. How should an API handle personal data to support privacy requirements like GDPR?

    Correct answer: Return only the fields that are needed

    URLs end up in logs, analytics and referrers, so keep personal data in bodies or headers.

  49. 49. Why should an API avoid sequential, guessable identifiers for sensitive resources even with authorization in place?

    Correct answer: Guessable IDs make enumeration easy after any bug

    Opaque IDs are an extra layer, never a replacement for authorization.

  50. 50. How should multi-tenant APIs prevent data leaks between tenants?

    Correct answer: Derive the tenant from the authenticated identity

    A tenant ID from the client is just another object reference that needs authorization.

  51. 51. How do you choose between webhooks, SSE, WebSockets and polling for delivering updates?

    Correct answer: By direction, audience and how fresh data must be

    Consider infrastructure too: SSE works through most proxies as plain HTTP; WebSockets need connection-aware load balancing.

  52. 52. How should a real-time API recover from disconnects without losing events?

    Correct answer: Sequence IDs, so clients resume from the last seen

    If the buffer doesn't reach back far enough, tell the client to do a full resync.

  53. 53. Why document real-time and event APIs with AsyncAPI?

    Correct answer: Channels, schemas and guarantees are contracts too

    Without a contract, event-driven systems accumulate implicit dependencies that break silently.

  54. 54. What is consumer-driven contract testing?

    Correct answer: The provider verifies consumers' interactions in CI

    Tools like Pact let providers know exactly which changes would break which consumers.

  55. 55. How can you detect which clients would break before changing an API's behavior?

    Correct answer: Log and analyze real usage per client

    Usage data turns 'we think nobody uses this' into a verified fact.

  56. 56. Why can retries at several layers (client, gateway, service) cause 'retry storms'?

    Correct answer: Each layer multiplies the attempts on a dependency

    Retry at one layer, use budgets (e.g. at most 10% extra requests), and honor Retry-After.

  57. 57. What is request hedging, and when is it appropriate?

    Correct answer: A delayed duplicate read; the first response wins

    Hedging cuts tail latency at the cost of extra load; never hedge non-idempotent operations.

  58. 58. How should an API communicate that a request was partially applied and can't be safely retried?

    Correct answer: Avoid it by design, or return an explicit status

    Ambiguous partial failures are the hardest errors for clients to handle correctly.

  59. 59. What does designing an API 'outside-in' mean?

    Correct answer: Starting from consumers' use cases and workflows

    Inside-out APIs mirror tables; outside-in APIs fit how clients actually work.

  60. 60. Why might you provide official SDKs in addition to raw HTTP documentation?

    Correct answer: SDKs can encode best practices like retries

    The trade-off is maintenance per language; generated SDKs plus hand-written helpers are a common compromise.

  61. 61. What's the risk of tight coupling between an API's response shape and a single UI screen?

    Correct answer: Every UI change forces an API change

    Shared APIs should model the domain; UI-specific shaping belongs in a BFF or the client.

  62. 62. How should breaking changes to error formats be treated?

    Correct answer: As breaking changes: clients parse those errors

    Adopting RFC 9457 in an existing API is best done as an opt-in (e.g. via Accept: application/problem+json) or a new version.

  63. 63. When does an API need explicit optimistic concurrency (ETags/If-Match) by default?

    Correct answer: When lost updates to shared data would do harm

    Requiring If-Match on updates (428 if missing) makes lost updates impossible rather than unlikely.

  64. 64. Why should timeouts be part of an API's documented contract?

    Correct answer: Clients must set timeouts and know what happens

    For long work, the contract should switch to async operations instead of long timeouts.

  65. 65. How can you replace a legacy API with a new implementation without a big-bang switch?

    Correct answer: Strangler fig: route and move endpoints one by one

    Shadowing traffic to the new implementation and diffing responses builds confidence before switching each route.

  66. 66. What are scheduled 'brownouts' when retiring an API version?

    Correct answer: Planned short outages of the deprecated version

    Brownouts turn silent dependencies into visible, recoverable incidents. Announce them in advance.

  67. 67. How do you keep one large tenant from degrading a shared API for everyone?

    Correct answer: Per-tenant limits, fair queuing and separate pools

    This 'noisy neighbor' problem is mostly solved by isolation: limits, queues and capacity per tenant.

  68. 68. When might an API offer Protobuf or another binary format in addition to JSON?

    Correct answer: For high-volume clients, negotiated via Accept

    Binary formats save bytes and parsing time but are harder to debug and need schema distribution.

  69. 69. What's the risk of caching authenticated API responses at a CDN?

    Correct answer: One user's data can be served to another

    Cache shared, non-personalized data at the edge; personalize with separate requests or client-side merging.

  70. 70. Why do event-driven APIs usually promise 'at-least-once' rather than 'exactly-once' delivery?

    Correct answer: Exactly-once across failures is impractical

    Document the guarantee and give each event a unique ID for deduplication.

  71. 71. What is a schema registry used for in event-driven APIs (e.g. with Kafka)?

    Correct answer: Storing versioned schemas and checking compatibility

    Consumers can read any version they know; the registry rejects incompatible schema changes at publish time.

  72. 72. What does request signing (e.g. HMAC-based like AWS SigV4) add beyond a bearer token?

    Correct answer: Proof the request wasn't altered, plus replay protection

    Signing is common for server-to-server APIs and webhooks where integrity matters.

  73. 73. How should an API design handle data residency requirements (e.g. EU data stays in the EU)?

    Correct answer: Regional endpoints or routing by the tenant's region

    Region affects base URLs, latency, backups and which subprocessors handle the data.

  74. 74. Why should pagination tokens be tied to the query that produced them?

    Correct answer: Reuse with other filters gives inconsistent results

    Google's AIP-158 recommends that page tokens are only valid with the same parameters.

  75. 75. Where should quotas and rate limits per plan be documented?

    Correct answer: In public docs and in response headers

    Predictable limits reduce support load and prevent clients from building fragile retry loops.