Bite-sized, standalone interview questions and answers for API Design. Read 5-10 per sitting. Each answer is 2-4 sentences max and stands on its own.

35 questions shown. Filter by keyword or difficulty below.

Topic: REST fundamentals & resources (Order 0)

API design is the work of defining the contract between a client and a server: the named things you can act on, the operations allowed on each, the request/response shapes, the errors, and the rules for change. Get the contract right and clients and servers can ship on independent schedules; get it wrong and every server change breaks someone. It is not “pick a framework” — the design questions are the same whether you serve JSON over HTTP or binary over HTTP/2.

A resource is the named, addressable thing an API exposes — an order, a user, an invoice — identified by a URI such as /orders/42, whose state is transferred as a representation (usually JSON) rather than as behavior. A resource is a conceptual mapping to a set of entities, not a row in a database, which is exactly why one resource can be backed by many tables. The client manipulates the resource through HTTP verbs instead of calling remote procedures.

A collection is a resource representing a set of child resources, usually a plural noun such as /orders, where POST /orders creates a member and GET /orders lists them. Members live under the collection at /orders/{id}, giving every item a stable, hierarchical address. Collections are the primary surface for listing, filtering, and pagination.

A safe method (GET, HEAD, OPTIONS) is defined by the HTTP spec as not expected to change server state, which lets clients, caches, and crawlers call it freely without side effects. This is a semantic contract, not an enforcement: a GET that increments a counter violates the contract even if the server accepts it. Because safe methods carry no side effects, intermediaries can cache and retry them without risk.

For external, browser-facing, or partner APIs, REST with resources under collections and a small uniform verb set (POST/GET/DELETE) is the pragmatic default because of universal tooling and debuggability. You reach for operation-oriented gRPC when you need typed, high-throughput internal calls where streaming and performance matter (Google’s API Design Guide recommends gRPC internally, REST externally). Many systems expose gRPC internally and a REST/OpenAPI gateway externally.

Topic: Idempotency, pagination & safe retries (Order 1)

An idempotent operation produces the same resulting server state no matter how many times it is applied with the same input. PUT, DELETE, and GET are idempotent by HTTP definition, while POST is not. This matters because networks drop packets: retrying an idempotent request cannot corrupt state, but a retried POST can create a duplicate order.

Networks drop requests, so a client that retries after a timeout can end up creating two orders — a second order, a second charge, a second shipment. Without an idempotency key or an idempotent method, the server has no way to recognize the replay as the same logical request. This is the single most common correctness bug in payment and order APIs, and it only appears under real network failure, never in happy-path tests.

The client sends a client-supplied Idempotency-Key (a UUID) in a header alongside the POST. The server stores the key with the result, so a replay with the same key returns the original 201 Created response instead of making a second order. This is the mechanism that makes an otherwise non-idempotent method safe to retry.

Deep offset pagination (?offset=10000) forces the database to scan and discard ten thousand rows, and the window drifts if rows are inserted or deleted mid-walk. It also gets slow on deep offsets because the database still scans all the skipped rows. The result is both wasted work and unstable pages under concurrent inserts.

You reach for cursors for any collection that grows and is traversed over time — order histories, activity feeds, audit logs — where inserts during a walk would otherwise shift an offset window and where deep offsets would force full scans. Offset pagination is acceptable only for small, static, or randomly-pageable result sets. Cursor pagination keeps the database doing an index seek instead of a growing scan.

Topic: The OpenAPI contract & contract testing (Order 2)

OpenAPI (currently 3.1, maintained by the OpenAPI Initiative at OAI/OpenAPI-Specification) is a machine-readable JSON or YAML description of an HTTP API’s paths, parameters, request/response schemas, auth, and status codes. “Swagger” is the older name for the 2.0 spec and its tooling; OpenAPI 3.x is the successor format. Because it is machine-readable, one document drives stubs, SDKs, mocks, and contract tests.

A schema is the formal description of a resource’s shape — its fields, types, optionality, and constraints — expressed in JSON Schema inside an OpenAPI document. Schemas let tooling validate a request body before it reaches business logic and generate typed clients, turning “the payload looks like this” into an enforceable contract. A change to a schema is the most common source of a breaking change, which is why schemas are versioned alongside the API.

Contract testing verifies that a provider and consumer agree on the request/response shape without running the full system — the consumer publishes the expectations it sends and receives, and the provider is checked against them in isolation. Tools like Pact record these interactions and fail the build when either side drifts. It catches breaking changes earlier and cheaper than end-to-end tests, which is why it pairs naturally with an OpenAPI document as the source of truth.

HATEOAS (Hypermedia As The Engine Of Application State) is the REST constraint that a response should embed links describing the next available actions, so the client discovers flows from the server rather than hardcoding URIs. A returned order might include links: { "pay": "/orders/42/pay", "cancel": "/orders/42/cancel" }, letting the API change those paths without breaking clients. It is the least-followed constraint in practice because clients usually prefer stable, documented endpoints over runtime discovery.

Topic: REST vs gRPC — the architectural fork (Order 3)

REST models things you act on with a small uniform set of verbs (resources under /v1/orders with POST/GET/DELETE); gRPC models operations you call directly (a OrderService with CreateOrder/GetOrder). That difference drives everything else: REST’s contract is the URL space plus an OpenAPI doc, while gRPC’s contract is the .proto. Google’s API Design Guide frames both as valid choices depending on the audience.

REST usually rides HTTP/1.1 with JSON, while gRPC rides HTTP/2 with Protocol Buffers — smaller, faster, and multiplexed, with deadlines and cancellation as first-class. gRPC’s binary payloads parse faster than JSON and stream over one HTTP/2 connection. REST wins on human-debuggability and universal client support since any HTTP tool works.

In gRPC, an RPC like ListOrders can return stream Order — the server pushes pages over one HTTP/2 stream, which is the gRPC-native answer to pagination and long-polling. REST has no built-in streaming, so it bolts on SSE, websockets, or webhooks instead. Streaming (server, client, bidirectional) is declared directly in the .proto and generated into the stub.

Protocol Buffers is a binary serialization format where messages are defined in a .proto schema with typed fields and numbered tags; the compiler generates code that encodes them into compact, fast binary on the wire. Field numbers (not names) identify fields, so adding an optional field with a new number is backward compatible while reusing a number with a different type is not. This is what makes gRPC payloads smaller and faster to parse than JSON.

For internal service-to-service calls where performance, streaming, and typed stubs matter, gRPC shines; for external, browser-facing, or partner APIs, REST with OpenAPI is the pragmatic default because of universal tooling and debuggability. Google’s API Design Guide recommends exactly this split, and many systems do both — gRPC internally, a REST/OpenAPI gateway in front for external clients.

A unary RPC is the classic request-then-response call (e.g. rpc GetOrder(OrderId) returns (Order)), one message in and one out. Streaming variants let the server send a stream back (returns (stream Order)), the client send a stream in, or both directions at once — all over a single HTTP/2 stream, ideal for live feeds like order-status updates. The four patterns (unary, server-streaming, client-streaming, bidi) are declared directly in the .proto and generated into the stub.

Topic: Versioning, deprecation & lifecycle (Order 4)

URL versioning puts v1/v2 in the path (/v2/orders), header versioning uses a custom request header, and media-type versioning encodes it in the Accept header (application/vnd.api.v2+json). URL versioning is the most visible and easiest to debug; media-type versioning is the most REST-pure but harder for clients and browser testing. The goal in every style is to let old clients keep calling the old contract while new clients opt into the new one.

You can version via header or media type (media-type versioning is the most REST-pure), but URL versioning wins on simplicity and debuggability — you can see and share the version in the path, and browser/dev-tools testing just works. Pick one and apply it consistently; the post’s FAQ frames URL versioning as the pragmatic default for those reasons.

Deprecation is the managed retirement of an endpoint, field, or version — the server marks it as going away (often via a Deprecation response header and a Sunset header naming the cutoff date) while still serving it for a grace period. Clients get a clear, machine-readable signal to migrate instead of a sudden 404. A documented deprecation policy with a minimum notice window is what keeps versioning from becoming a surprise for consumers.

Versioning in the URL (/v1, /v2, /v3…) is easy to start and hard to end: every version is code you must keep running, testing, and securing forever. Without a deprecation policy a Sunset header and a notice window, versions pile up. The discipline is: version only on a real breaking change, deprecate aggressively, and delete old versions on a schedule.

Topic: Breaking changes, over/under-fetching & other reliability traps (Order 5)

Removing a JSON field, renaming it, tightening a type from string to integer, or changing a 200 to a 201 all break clients coded against the old shape. Because the OpenAPI schema is the contract, a change there should be reviewed as a compatibility decision, not a free edit. The safe move is additive-only on a live version and a new version for anything subtractive.

A “get customer” endpoint that returns the full order history for every profile view is over-fetching — the client downloads megabytes it ignores. Good design lets the client ask for the shape it needs (field selection or a GraphQL-style projection) or at least scopes collections sensibly. Watching the payload shape is one of the core design disciplines to avoid this waste.

An endpoint that returns only an ID, forcing the client to call GET /order per item, is under-fetching — the infamous N+1 call explosion, where one list view triggers one plus N follow-up requests. It hammers the server and slows the client compared to returning the needed data in the first call. Good design scopes collections and supports server-side filtering/sorting to avoid it.

HTTP status codes are the standardized, machine-readable outcome of a request — 201 Created for a successful POST, 202 Accepted for async work, 409 Conflict for a duplicate, and so on — that clients and intermediaries branch on. Using 200 OK for every response hides failures from caches and clients and defeats the uniform interface. Generic middleware can then handle caching, retries, and error display without parsing the body.

RFC 7807 defines a standard application/problem+json media type for error responses, carrying type, title, status, detail, and instance fields so errors are structured instead of free-text. A client can branch on the type URI (e.g. /errors/out-of-stock) rather than string-matching a message. It replaces the ad-hoc { "error": "..." } shape with a contract both sides understand.

A webhook is a reverse API: instead of the client polling, the server pushes an event to a callback URL the client registered in advance, usually an HTTP POST with a signed JSON payload — so the client reacts the moment an order ships. Long-polling is the older workaround where the client makes a request the server holds open until an event or timeout, then immediately re-issues it; it is heavier and less efficient than webhooks or gRPC streaming, kept only for clients that cannot receive inbound connections. The client must verify the webhook signature and acknowledge quickly (often with 2xx) or the server will retry.

Topic: Auth, errors & real-time (Order 6)

PUT replaces the entire resource — you must send every field, and missing optional fields become null. PATCH applies a partial update, typically a list of changes like [{ "op": "replace", "path": "/email", "value": "new@example.com" }]. PUT is idempotent (sending it twice has the same effect); PATCH is idempotent only if you design it that way (e.g., using If-Match to prevent lost updates). Interviewers test whether you know PATCH is not automatically idempotent by the HTTP spec.

Three common approaches: Webhooks (server pushes to a client URL — best for server-to-server), Server-Sent Events (one-way stream over HTTP — best for browser dashboards), and gRPC bidirectional streaming (full duplex — best for low-latency internal services). Webhooks require signature verification and retry handling; SSE requires a persistent HTTP connection but is simpler than WebSockets; gRPC streaming gives the lowest latency but needs HTTP/2. The right choice depends on who is consuming (browser vs server) and latency requirements.

A circuit breaker wraps calls to a downstream dependency and tracks failure rates. When failures exceed a threshold, the circuit “opens” and immediately rejects requests (or returns a fallback) without calling the dependency, preventing timeout pile-ups. After a cooldown period, it enters a “half-open” state and lets a probe request through; if it succeeds, the circuit closes again. This prevents one slow dependency from exhausting the caller’s thread pool and cascading to other dependencies.

Offset pagination (?page=3&size=20) is simple and lets clients jump to arbitrary pages, but it becomes slow on large datasets because the database must scan and discard the first N rows. Cursor pagination (?cursor=abc123&size=20) uses a stable sort column (usually the primary key or timestamp) to resume from where the last page ended — O(1) regardless of depth. Choose cursor when you have large, frequently-updated datasets (feeds, timelines); choose offset when you need page-number jumping (admin dashboards, search results).

Breaking changes (removing a field, changing a type) require a new API version. Strategies: URL versioning (/v2/orders) is the most explicit and cache-friendly; header versioning (Accept: application/vnd.api.v2+json) keeps URLs clean but is harder to test in a browser. Regardless of strategy, the old version must remain available for a deprecation window (typically 6-12 months), with a Sunset header and migration guide. Dark launches (routing a percentage of traffic to the new version before full release) help catch issues before they affect all clients.


Last updated: July 2026 Total Q&A: 35 across API Design

Back to Q&A Index