38 Backend & API interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
Backend and API design deals with how a server exposes data over HTTP so that clients can use it predictably, even when requests fail or are retried. The questions cover offset versus cursor pagination, HTTP methods and status codes, idempotency keys, versioning, error response contracts, rate limiting, filtering and sorting parameters, and asynchronous or bulk operations.
and 22 more topics.
The problem: POST is not idempotent — if a client submits a create-order/payment and the network times out, it cannot tell whether the server received it. A blind retry → duplicates (double order, double charge). An idempotency key is a unique string (usually a UUID)…
- Offset (LIMIT 20 OFFSET 40 / ?page=3): simple, jumps to any page, can show total page count. Two weaknesses: (1) slow on deep pages — the DB still scans and discards the first 40 rows; (2) result drift — if rows are inserted/deleted meanwhile,…
Safe = the method is read-only and does not change server state (GET, HEAD, OPTIONS). Idempotent = calling it once or N times leaves the same state (GET, HEAD, PUT, DELETE, OPTIONS). Every safe method is idempotent; the converse is false. Method Safe Idempotent ---------…
PUT replaces the whole resource with the body you send: any field missing from the body is treated as removed or reset to default. PATCH describes only the change. Two common PATCH formats: - JSON Merge Patch (application/merge-patch+json): the body mirrors the resource, and null…
Pick based on whether the work is finished and whether there is a body: - 201 Created — a new resource now exists. Include a Location header pointing at its URL; the body is usually the resource itself. - 200 OK — work finished and…
The three map to three different layers of failure: - 400 Bad Request — the request is syntactically wrong and the server cannot parse it: malformed JSON, badly formed headers. - 422 Unprocessable Content — syntax is fine and it parses, but the content is…
The principle: one error format across the whole API, machine-readable and debuggable. RFC 9457 standardizes exactly that, served as Content-Type: application/problem+json. Standard members: - type — a URI identifying the error class (clients match on this, not on the title string). - title — a…
Use a client-generated idempotency key; the server remembers the outcome and replays it instead of reprocessing. The flow: 1. The client generates a unique key per payment intent (UUID v4, created when the checkout screen opens, reused across retries) and sends it in an Idempotency-Key…
Two common approaches: - URL path (/v1/orders) — what the Google API design guide and most public APIs use. Visible, easy to route, cache, and split at the gateway. Downside: one resource ends up with several URIs. - Header (Accept: application/vnd.api+json; version=2, or a dedicated…
Algorithms, from simplest to most accurate: - Fixed window — count requests per minute. Simplest, but it has a boundary flaw: 100 requests at the end of minute 1 plus 100 at the start of minute 2 means 200 requests in two seconds, all legal.…
Keep one convention across every collection endpoint rather than inventing a new shape per endpoint. - Filter: expose simple fields directly as query params (status=paid). For complex expressions use one filter param with a fixed grammar (filter=status=paid AND total100000), as the Google API design guide…
Move from a synchronous request to an async job: accept the request, return immediately, process in the background, and let the client track the outcome. The client then tracks it one of two ways: Polling — GET /jobs/7c2 returns { "status": "running" "succeeded" "failed", "progress":…
First agree on the semantics with the caller, because this is a business question more than an HTTP one: Option 1 — all-or-nothing (atomic). Run the whole batch in one transaction; a single bad record rolls everything back and returns 422 with the list of…
Because the DB and the message broker are two separate systems with no shared transaction. You write to both in one function, but nothing guarantees both succeed. Two failure directions: - DB committed, publish fails (broker down, process killed): the order exists in the DB…
Idempotent means processing the same message multiple times yields the same result as processing it once. It is required because brokers deliver at-least-once: retries, rebalances, and lost acks all create duplicates. Common approach — record the handled message in the same transaction as the business…
Retrying immediately and without a limit is the fastest way to turn a small incident into a large one: the struggling downstream service receives the retry traffic on top of the original load. Exponential backoff — grow the wait geometrically (1s, 2s, 4s, 8s...) capped…
First separate two situations, because they are handled completely differently. Temporarily slow (a traffic spike) — the queue is the buffer, that is its job. You only need enough storage and monitoring to know when the backlog drains. Nothing else is required. Persistently slow (consumer…
Choose by how the data is consumed, not by popularity. Kafka — a distributed log where messages are retained by policy and consumers read by offset. Pick it when: - You need replay: a new service wants the history, or you must reprocess after fixing…
Never use float/double for money. Binary floating point cannot represent 0.1 exactly, so summing many rows drifts by cents and breaks reconciliation. Two correct options: - Integer in the smallest unit: store amountminor BIGINT. VND has no decimal part, so 150000 = 150,000 VND; USD…
The minimal model is three tables — users, roles, permissions — plus two join tables, userroles and rolepermissions. Users get roles; roles bundle permissions shaped as verb + resource (order.read, order.refund, user.ban). Implementation rules: - Check on the server, on every request. Hiding a button…
Once a request carries cookies cross-origin, the browser applies stricter rules. The server must return both headers: - Access-Control-Allow-Origin: https://app.example.com — it must be a concrete origin; is rejected. - Access-Control-Allow-Credentials: true. If a preflight is involved, the OPTIONS response must repeat both, and Access-Control-Allow-Headers…
The first question is not the protocol but: does the caller need the result before it can continue? Synchronous (REST / gRPC) — the result is required to proceed: checking stock before creating an order, validating a token. The price is that the caller depends…
The gateway is the single entry point for clients and handles cross-cutting concerns — things every service needs and should not reimplement ten times. Belongs there: - Routing requests to the right service; hiding internal topology from clients. - Authentication (validate the token, reject anonymous…
A BFF is a backend dedicated to one client type (web, iOS/Android, internal console), owned by that frontend team, sitting between the client and the business services. The problem it solves: a single shared API is always wrong for someone. Mobile wants small payloads, fewer…
Principle: backward-compatible changes need no new version; breaking changes require running two versions side by side for a while. Safe changes (add, never remove): new fields, new enum values with a default branch, new endpoints. This only holds if consumers are written as tolerant readers…
Yes. An ORM is only safe in the statements it generates itself; anywhere you concatenate strings you are back to the original risk. Three common gaps: Raw queries with concatenation. The ORM escape hatches ($queryRawUnsafe, string-based createQuery, the driver's query()) do not parameterise for you.…
The risk is command injection: once a string passes through a shell, characters like ;, , &&, $(...), and backticks are interpreted as new commands running with the application process's privileges. The rewrite — drop the shell: execFile/spawn (with shell: false, the default) hands the…
Yes, and it is non-negotiable. Client validation is a user-experience feature, not a security control — the client is entirely under the user's control, and anyone can call the API directly with curl or Postman, bypassing the form completely. Server-side validation principles: - Allowlist, not…
This is excessive data exposure: the API returns everything it has and lets the client pick what to render. But the client is not a hiding place — open the Network tab and the whole response is visible. Returning an ORM entity directly usually drags…
SOAP is a protocol with a strict standard: every message is XML wrapped in an Envelope, and the API contract is described by a WSDL file. REST is an architectural style built on HTTP: everything is a resource with a URL, manipulated through HTTP methods…
The URL is a noun naming the resource; the HTTP method is the verb. Write GET /orders/42, not GET /getOrder?id=42. The conventions most teams use: - Plural nouns for collections: /users, /users/42. Use plural in both forms so nobody has to remember where it is…