Backend Developer Interview Questions and Answers

Backend interviews are less about one language and more about how you design APIs, model data, keep systems fast under load and recover when something breaks. The answers below are language-neutral, so they work whether you write Node.js, Python, Java, Go or PHP.

54 questions with answersLevels: Fresher to SeniorUpdated November 2026

APIs

Designing and running HTTP APIs.

Q1.What makes an API RESTful?

Resources identified by URLs such as /orders/42, standard HTTP methods for actions, stateless requests that carry all the context they need, meaningful status codes and representations like JSON. Good REST APIs are consistent and predictable more than strictly pure.

Q2.What does idempotent mean, and which methods are idempotent?

Repeating the request has the same effect as sending it once. GET, PUT, DELETE, HEAD and OPTIONS are idempotent; POST is not. For payments and order creation, clients send an idempotency key so retries do not create duplicates.

Q3.How do you version an API?

Common options are a URL prefix like /v1, a header, or a media type. URL versioning is the simplest to operate. Avoid breaking changes where possible by adding fields instead of changing them.

Q4.How do you design pagination?

Offset and limit is simple but slow and inconsistent on large, changing tables. Cursor or keyset pagination uses the last seen ID or timestamp, which is fast and stable. Return the next cursor in the response.

Q5.What is rate limiting and how is it implemented?

Limiting how many requests a client can make in a time window to protect the service. Token bucket and sliding window algorithms are common, usually stored in Redis, and the API returns 429 with a Retry-After header.

Q6.How should an API return errors?

With the correct status code and a consistent JSON body containing a machine-readable code, a human message and field-level details for validation errors. RFC 9457 problem details is a standard format.

Q7.When would you choose gRPC or GraphQL over REST?

gRPC suits internal service-to-service calls that need speed, streaming and strict contracts through Protocol Buffers. GraphQL suits clients that need flexible queries across many entities, such as mobile and web apps with different needs.

Q8.What are webhooks?

HTTP callbacks a service sends to your URL when an event happens, such as a payment succeeding. Verify the signature, respond quickly with 2xx, process the work asynchronously and handle duplicate deliveries.

Q9.What is an API gateway?

A single entry point in front of services that handles routing, authentication, rate limiting, TLS and logging, so each service does not repeat that work.

Q10.What is the difference between PUT and PATCH?

PUT replaces the whole resource with the body you send, so missing fields may be cleared. PATCH applies a partial update. PUT is idempotent by definition; PATCH can be designed to be.

Q11.How do you validate request data?

Validate at the edge with a schema library such as Zod, Joi, Pydantic or Bean Validation, reject unknown or malformed fields with a 400 or 422 and clear messages, and never trust client-side validation alone.

Databases

SQL, NoSQL and data modelling questions.

Q12.What is the difference between SQL and NoSQL databases?

SQL databases like PostgreSQL and MySQL store data in tables with fixed schemas, support joins and strong transactions. NoSQL covers document, key-value, wide-column and graph stores, which trade some of that for flexible schemas or horizontal scale. Choose by data shape and access patterns.

Q13.What is normalisation?

Organising tables to remove duplicated data, so each fact lives in one place. It prevents update anomalies. Read-heavy systems sometimes denormalise on purpose for speed.

Q14.What are ACID properties?

Atomicity: a transaction is all or nothing. Consistency: it moves the database from one valid state to another. Isolation: concurrent transactions do not interfere. Durability: committed data survives crashes.

Q15.What are transaction isolation levels?

Read uncommitted, read committed, repeatable read and serializable. Higher levels prevent more anomalies such as dirty reads, non-repeatable reads and phantom reads, at the cost of concurrency. PostgreSQL defaults to read committed.

Q16.How does a database index work?

Most indexes are B-trees that keep column values sorted with pointers to rows, turning full table scans into fast lookups. Indexes speed reads but slow writes and use storage, so add them for real query patterns.

Q17.What is a composite index and why does column order matter?

An index on several columns, such as (user_id, created_at). It helps queries that filter on the leftmost columns first, so an index on (a, b) helps filters on a, or a and b, but not on b alone.

Q18.How do you find a slow query?

Enable the slow query log or pg_stat_statements, run EXPLAIN ANALYZE to see the plan, look for sequential scans on large tables, bad join orders or missing indexes, and check whether the query returns more rows than needed.

Q19.What is the N+1 query problem?

Loading a list, then running one extra query per item to load related data. Fix it with joins, eager loading in the ORM or batching with an IN query or a DataLoader.

Q20.What is the difference between INNER JOIN and LEFT JOIN?

INNER JOIN returns only rows with matches in both tables. LEFT JOIN returns all rows from the left table and NULLs where there is no match on the right.

Q21.What are database replication and sharding?

Replication copies data to other servers for reads and failover. Sharding splits data across servers by a key, such as customer ID, to scale writes and storage. Sharding adds complexity in cross-shard queries and rebalancing.

Q22.What is the CAP theorem?

In a distributed system with a network partition, you must choose between consistency and availability. In practice, systems choose per operation, and PACELC adds that even without partitions you trade latency against consistency.

Q23.How do you run database migrations safely?

Use versioned migration files in source control, make changes backwards compatible (add a column, deploy code, backfill, then remove the old column later), avoid long locks on big tables and test on a copy of production data.

Q24.What is the difference between DELETE, TRUNCATE and DROP?

DELETE removes chosen rows, can be filtered with WHERE and is logged row by row. TRUNCATE quickly empties a whole table. DROP removes the table itself, structure and all.

Q25.What are soft deletes and when are they useful?

Marking rows as deleted with a column like deleted_at instead of removing them. They allow undo and auditing, but every query must filter them out and unique constraints need care.

Caching, queues and performance

Keeping systems fast under load.

Q26.What caching strategies do you know?

Cache-aside: the app reads the cache and falls back to the database, then fills the cache. Write-through: writes go to cache and database together. Write-behind: writes go to cache and are flushed later. Cache-aside is the most common.

Q27.What is cache invalidation and why is it hard?

Removing or updating cached data when the source changes. It is hard because of race conditions and many places that change data. Use TTLs, delete keys on writes, and version keys when needed.

Q28.What is a cache stampede and how do you prevent it?

Many requests miss an expired key at once and all hit the database. Prevent it with request coalescing or locks, early refresh before expiry and random jitter on TTLs.

Q29.Why use a message queue?

To decouple services and do slow work asynchronously, such as sending emails or processing images. Queues absorb traffic spikes and allow retries. Examples are RabbitMQ, Amazon SQS, Kafka and Redis-based job queues.

Q30.What is the difference between a queue and an event stream like Kafka?

A queue delivers each message to one consumer and removes it after processing. Kafka keeps an ordered log that many consumer groups can read independently and replay.

Q31.What delivery guarantees exist in messaging?

At most once can lose messages, at least once can deliver duplicates, exactly once is hard and usually means at least once plus idempotent consumers. Design consumers to handle duplicates.

Q32.What is a dead letter queue?

A queue where messages go after failing a set number of times, so they do not block the main queue and can be inspected and replayed.

Q33.How do you scale a backend horizontally?

Keep app servers stateless, store sessions in Redis or use tokens, put a load balancer in front, scale the database with read replicas, caching and partitioning, and move slow work to background workers.

Q34.What is connection pooling?

Reusing a set of open database connections instead of opening one per request, which is slow and can exhaust the database. Tools include PgBouncer and built-in ORM pools.

Q35.What is the difference between vertical and horizontal scaling?

Vertical scaling adds CPU and memory to one server, which is simple but has a ceiling. Horizontal scaling adds more servers behind a load balancer, which needs stateless services but scales much further.

Q36.What is a CDN's role for a backend?

Besides static files, a CDN can cache API responses that are the same for many users, terminate TLS near users and absorb attacks, reducing load on the origin.

Security and reliability

Auth, secrets and running in production.

Q37.What is the difference between authentication and authorisation?

Authentication checks who you are, for example with a password or SSO. Authorisation decides what you can do, for example with roles or permissions.

Q38.How do JWTs work and what are their risks?

A JWT is a signed token with a header, payload of claims and signature. The server verifies the signature without a database lookup. Risks include long lifetimes, storing them where scripts can read them and accepting weak algorithms. Use short-lived access tokens with refresh tokens and allow revocation.

Q39.Session cookies or JWTs: which would you choose?

For a web app on one domain, server sessions with HttpOnly, Secure, SameSite cookies are simple and easy to revoke. JWTs suit APIs used by mobile apps or several services. Both are valid if implemented carefully.

Q40.What is OAuth 2.0 and OpenID Connect?

OAuth 2.0 lets an app get limited access to a user's resources on another service through access tokens. OpenID Connect adds an identity layer with ID tokens for login. Use the authorization code flow with PKCE for web and mobile clients.

Q41.How do you store secrets?

In a secret manager such as AWS Secrets Manager, Vault or the platform's encrypted environment variables, never in the code repository. Rotate them and give each service only the secrets it needs.

Q42.What is the OWASP Top 10?

A list of the most critical web application risks, including broken access control, cryptographic failures, injection, insecure design, security misconfiguration and vulnerable components. It is a common checklist for code reviews.

Q43.What are logging, metrics and tracing?

Logs record events, metrics are numbers over time such as request rate and latency, and traces follow one request across services. Together they are observability, often collected with OpenTelemetry.

Q44.What is a health check and a readiness probe?

A liveness check says the process is running; a readiness check says it can accept traffic, for example after connecting to the database. Load balancers and Kubernetes use them to route traffic and restart unhealthy instances.

Q45.What is a circuit breaker?

A pattern that stops calling a failing dependency after repeated errors and returns a fallback quickly, then tries again after a timeout. It prevents one slow service from taking down the whole system.

Q46.How do you prevent broken access control?

Check permissions on the server for every request and every object, not just by hiding buttons. Make sure a user cannot read /orders/43 just by changing the ID, and write tests for those checks.

System design and scenarios

Open questions for mid and senior roles.

Q47.Design a URL shortener.

Accept a long URL, generate a short unique code with a base62 counter or random ID with collision checks, store the mapping in a database, serve redirects from a cache, track clicks asynchronously through a queue and add rate limits and abuse checks.

Q48.Design a notification service for email, SMS and push.

An API accepts notification requests, stores them and puts jobs on a queue per channel. Workers call providers with retries and backoff, respect user preferences and quiet hours, deduplicate with idempotency keys and record delivery status.

Q49.An endpoint got slow after a release. How do you investigate?

Compare latency metrics before and after the release, look at traces to find the slow span, check new queries with EXPLAIN, check for N+1 queries, external calls without timeouts or a missing cache. Roll back if users are badly affected.

Q50.How would you handle a file upload of several gigabytes?

Let the client upload directly to object storage with pre-signed URLs and multipart uploads, so the API server is not in the data path. Process the file asynchronously after upload and show progress.

Q51.Two users buy the last item at the same time. How do you prevent overselling?

Use a database transaction with a conditional update such as decrementing stock only where stock is greater than zero, or row-level locks, and treat zero affected rows as sold out. Reservation with expiry works for carts.

Q52.How would you move a monolith to microservices?

Only with a clear reason, such as team scaling. Identify bounded contexts, extract one service at a time behind the existing API using the strangler pattern, give each its own data, and invest in observability and CI first.

Q53.How do you design for zero-downtime deployments?

Run several instances behind a load balancer, use rolling or blue-green deployments, make database changes backwards compatible, drain connections before shutdown and keep feature flags for risky changes.

Q54.Design a rate limiter for a public API.

Identify clients by API key or IP, store counters in Redis using a sliding window or token bucket with atomic operations or a Lua script, return limits in response headers and 429 when exceeded, and allow different tiers per plan.

How to prepare for the interview

  • Expect a schema design question: tables, keys, indexes and the queries the app will run.
  • Practise one system design end to end, such as a URL shortener or a notification service.
  • Know how you would debug a slow endpoint in production, step by step.
  • Be ready to write an API endpoint with validation, error handling and a test.