Backend Interview Questions (with real STAR answers)

The backend interview questions that come up most, from junior to senior - HTTP and REST, databases, caching, authentication, concurrency, and system design. Short model answers for the technical questions, and STAR answers for the "tell me about a time" questions, built from real production work you can do yourself.

Get started - freeLive cloud workspace in your browser · nothing to install

Backend interviews mix technical questions, system design, troubleshooting scenarios, and behavioral questions. This page covers the questions that come up most, from junior to senior: behavioral questions with STAR answers built from real production work you can do yourself, then technical and scenario questions with short model answers.

Backend behavioral interview questions (STAR answers)

Tell me about a time you improved the performance of a system.

Situation: An endpoint was timing out under normal load, and the logs showed it was running hundreds of small database queries per request.
Task: I had to bring the response time down without changing the API contract.
Action: I traced the query pattern, identified a classic N+1, and replaced the per-row lookups with a single joined query plus the right index.
Result: The endpoint went from timing out to fast and predictable, and I documented the pattern so it would not come back.

Go earn this story: Fix the N+1 Query →

Tell me about a time you fixed a tricky concurrency bug.

Situation: Under concurrent requests, the payment path could charge a customer twice - a race between the check and the write.
Task: I needed to guarantee a single charge per order even when requests overlapped.
Action: I reproduced the race with parallel requests, then made the charge atomic with a row lock (SELECT ... FOR UPDATE) and a unique constraint on the order, so only one charge could succeed.
Result: Double charges stopped entirely, and I added a test that runs the concurrent path to keep it that way.

Go earn this story: Stop a Double-Charge Race Condition →

Tell me about a time you secured an API.

Situation: An API exposed protected endpoints with weak token handling that could be bypassed.
Task: I had to put real authentication in place without breaking existing clients.
Action: I implemented JWT auth, verifying the signature, the allowed algorithm, and the expiry on every request and rejecting anything malformed with a 401.
Result: Protected routes were really protected, and forged or expired tokens were cleanly refused.

Go earn this story: Add JWT Authentication to an API →

Tell me about a time you tracked down a resource leak in production.

Situation: After a few hours of traffic, the API started failing with 'too many connections' errors from Postgres, and a restart only helped for a while.
Task: I had to find what was holding connections and stop the failures for good.
Action: I checked pg_stat_activity and saw many idle connections from the app. In the code, an error path took a connection from the pool and never returned it. I moved the release into a finally block (a context manager) so every path returns the connection.
Result: The connection count stayed flat under load and the errors stopped. I also added a pool metric to the dashboard so a leak would show up early.

Go earn this story: Plug a Postgres Connection Pool Leak →

Tell me about a time you changed a database schema on a live system.

Situation: We needed a new required column on a large, busy table, and adding it as NOT NULL in one step would lock the table and break running code.
Task: I had to add the column with no downtime and no failed requests.
Action: I split it into steps: add the column as nullable, update the code to write it, backfill old rows in small batches, and only then add the NOT NULL constraint.
Result: The migration finished with zero downtime, and the team reused the same expand-and-contract steps for later schema changes.

Go earn this story: Add a NOT NULL Column With a Zero-Downtime Backfill →

Tell me about a time a slow dependency caused problems for your service.

Situation: A third-party API became slow, and because our HTTP client had no timeout, requests piled up and our whole service stopped responding.
Task: I had to stop one slow dependency from taking down everything else.
Action: I set explicit connect and read timeouts on the client, returned a clear error or a fallback when the call failed, and added limited retries with backoff.
Result: When the dependency was slow again later, our service stayed up and only the one feature was affected.

Go earn this story: Set an HTTP Client Timeout to Stop Cascading Failures →

Backend technical and scenario interview questions

What is the difference between POST, PUT, and PATCH?

POST creates a resource or triggers an action and is not idempotent. PUT replaces the whole resource at a known URL and is idempotent - sending it twice has the same effect as once. PATCH changes only some fields of a resource.

Which HTTP status codes should an API return?

200 OK for success, 201 Created after creating a resource, 204 No Content for success with no body, 400 for bad input, 401 when the caller is not authenticated, 403 when they are authenticated but not allowed, 404 when the resource does not exist, 409 for a conflict, 429 for rate limiting, and 5xx only for server errors.

What is a database index, and when can it hurt?

An index (usually a B-tree) lets the database find rows without scanning the whole table, which speeds up WHERE, JOIN, and ORDER BY on the indexed columns. Indexes cost disk space and slow down every INSERT, UPDATE, and DELETE, so add them for real query patterns and confirm with EXPLAIN ANALYZE.

What is the N+1 query problem?

The code runs one query to load a list, then one more query for each item in the list. With 100 items that is 101 queries. Avoid it with a JOIN, a single WHERE id IN (...) query, or the ORM's eager loading.

What does ACID mean, and what are transaction isolation levels?

ACID is Atomicity (all or nothing), Consistency (constraints always hold), Isolation (concurrent transactions do not see each other's partial work), and Durability (committed data survives a crash). Isolation levels - Read Committed, Repeatable Read, Serializable - trade performance for protection against anomalies like non-repeatable reads and lost updates.

What is the difference between offset and cursor pagination?

Offset pagination (LIMIT 20 OFFSET 1000) is simple but gets slower on deep pages and can skip or repeat rows when data changes. Cursor pagination uses the last seen value (WHERE id > last_id ORDER BY id LIMIT 20), so it stays fast and stable, but you cannot jump to a page number.

How does JWT authentication work, and what are its downsides?

The server signs a token that contains claims such as the user id and expiry. Each request sends the token, and the server checks the signature and expiry without a database lookup. The downside is that a token cannot easily be revoked before it expires, so keep access tokens short-lived, use refresh tokens, and always pin the expected algorithm.

What is the difference between authentication and authorization?

Authentication checks who you are (login, token, API key). Authorization checks what you are allowed to do (roles, ownership of a record). A failed authentication returns 401; a failed authorization returns 403.

How would you design a rate limiter?

A common choice is the token bucket: each client has a bucket that refills at a fixed rate, and each request takes one token; when the bucket is empty, return 429 with a Retry-After header. Keep the counters in Redis with atomic operations so all app instances share the same limits.

What is cache-aside, and how do you keep the cache correct?

With cache-aside, the app reads from the cache first and, on a miss, reads the database and writes the result to the cache. Keep it correct with a TTL and by deleting the cache key when the data changes. Watch for a cache stampede, where many requests miss at once and all hit the database.

What is an idempotency key?

A unique key the client sends with a request, often in an Idempotency-Key header. The server stores the key with the result, and if the same key arrives again (for example a retry after a timeout) it returns the stored result instead of doing the action twice. This is standard for payments.

Why should message queue consumers be idempotent?

Most queues, such as SQS and Kafka, deliver at least once, so the same message can arrive twice after a retry or crash. The consumer must handle duplicates safely, for example by recording processed message ids or using upserts. Messages that keep failing should go to a dead-letter queue.

When would you choose SQL or NoSQL?

Choose a relational database such as Postgres when data has relations, you need transactions and flexible queries, which covers most apps. Choose a NoSQL store such as DynamoDB when access patterns are simple and known in advance and you need very high scale with predictable latency.

Scenario: an endpoint got slow after a release. How do you find the cause?

Confirm it with latency metrics and find which endpoint and when it started. Compare the release diff, then look at traces (for example OpenTelemetry) to see where the time goes - database, external call, or code. For the database, check slow query logs and EXPLAIN ANALYZE for missing indexes or N+1 patterns. Roll back if users are badly affected.

Scenario: design a URL shortener.

API: POST a long URL, get a short code; GET the code to redirect with 301 or 302. Generate codes with base62 encoding of a unique id or a random string with a collision check. Store code to URL in a database with a unique index, and put a cache such as Redis in front because reads far outnumber writes. Add rate limiting and expiry if needed.

What questions are asked in a backend interview?

Expect behavioral questions (tell me about a time you...), technical questions on APIs, databases, caching, authentication, and concurrency, and system design for mid and senior roles. Many companies also give a coding or take-home task. The questions on this page cover all of these.

How do you answer behavioral interview questions?

Use STAR: Situation, Task, Action, Result. Keep it concrete - a specific incident, what you owned, what you did, and the result. The answers above are all structured this way.

More for Backend engineers

Backend projectsBackend roadmapResume projectsCareer guide

Do real production work, free. Live cloud workspaces in your browser - every project you complete lands on your portfolio.

Get started - free
Get started - free