Autocoder

Backend Developer Interview Questions and Answers

Last updated 2026-11-19

Backend interviews ask how you keep data correct and a service alive under load. Expect questions on HTTP and API design, SQL and indexing, transactions, caching, authentication and the trade-offs behind queues and scaling. The language matters less than the reasoning, though you will be asked to write real code.

This page is language-neutral. Examples use Python and SQL, and the ideas carry to Java, Node.js or Go. For framework specifics, see the Spring Boot, Django, Node.js and FastAPI pages. For the interview process, read how to crack a backend interview.

Core topicsHTTP, REST, SQL, indexes, transactions, caching, auth, queues
Typical roundsCoding, API or schema design, system design, debugging
Questions here18

What interviewers are really checking

They look for failure thinking. For every design you describe, expect: what happens when this call times out, when the same request arrives twice, when the database is slow, when two users update the same row. Answering with idempotency, timeouts, retries with backoff and constraints shows production sense.

Topics worth a deep revisit

Backend Developer Interview Questions and Answers: questions with worked answers

  1. 1

    What do the main HTTP methods mean, and which are idempotent?

    easy

    GET reads and is safe and idempotent. PUT replaces a resource and is idempotent. DELETE removes and is idempotent, since deleting twice leaves the same state. POST creates or triggers an action and is not idempotent. PATCH applies a partial change and is not guaranteed idempotent. Idempotent means repeating the request has the same effect as sending it once, which matters for safe retries. See REST API interview questions.

  2. 2

    Which HTTP status codes should an API use for common outcomes?

    easy

    200 for success, 201 with a Location header after creation, 204 for success with no body, 400 for malformed input, 401 when not authenticated, 403 when authenticated but not allowed, 404 for a missing resource, 409 for a conflict such as a duplicate, 422 for valid syntax but failed validation, 429 for rate limiting, and 500 or 503 for server faults. Do not return 200 with an error body.

  3. 3

    What is a database index and what does it cost?

    easy

    An index, usually a B-tree, lets the database find rows by a column without scanning the table, turning O(n) lookups into O(log n). The cost is extra storage and slower writes, since every insert, update or delete must maintain each index. Index columns used in WHERE, JOIN and ORDER BY on large tables, and avoid indexing low-selectivity columns such as a boolean on its own.

  4. 4

    How does a composite index work, and does column order matter?

    medium

    A composite index on (a, b) is sorted by a, then by b within each a. It serves queries filtering on a, or on a and b, but not b alone, because of the leftmost-prefix rule. Put equality columns first and range columns last. An index on (customer_id, created_at) serves WHERE customer_id = ? ORDER BY created_at DESC without a separate sort.

    sql
    CREATE INDEX idx_orders_cust_created ON orders (customer_id, created_at DESC);
    EXPLAIN SELECT * FROM orders
    WHERE customer_id = 42 ORDER BY created_at DESC LIMIT 20;
  5. 5

    What is the N+1 query problem and how do you fix it?

    medium

    You load a list with one query, then issue one query per item to fetch a related record, for N+1 in total. It looks fine in development and collapses under load. Fix it with a JOIN, an eager-loading option in your ORM such as select_related, JOIN FETCH or include, or a second query using WHERE id IN (...). Detect it by logging query counts per request in tests.

    python
    # Django: 1 query with a join instead of 1 + N
    orders = Order.objects.select_related("customer")[:50]
    for o in orders:
        print(o.customer.name)
  6. 6

    Explain transaction isolation levels.

    medium

    Read committed prevents dirty reads, so you only see committed data, but a repeated read can change. Repeatable read keeps the rows you read stable, though PostgreSQL implements it as snapshot isolation and MySQL InnoDB uses next-key locks. Serializable behaves as if transactions ran one after another and may abort some with a retry error. Higher isolation costs throughput. PostgreSQL defaults to read committed and MySQL InnoDB to repeatable read.

  7. 7

    Session cookies or JWTs for authentication?

    medium

    A server-side session stores state on the server, so you can revoke it instantly, and the cookie holds only an opaque ID. A JWT is self-contained and verified by signature, which scales across services without a lookup, but you cannot revoke it before expiry without a deny list. For a browser app, an HttpOnly, Secure, SameSite cookie with a session is usually simpler and safer. Use short-lived JWTs with refresh tokens for service-to-service or mobile.

  8. 8

    How do you prevent SQL injection?

    medium

    Never build SQL by concatenating user input. Use parameterised queries or prepared statements so the driver sends values separately from the query text, and use an ORM correctly. Whitelist anything that cannot be parameterised, such as column names in ORDER BY. Give the application database user minimal privileges. Escaping by hand is fragile.

    python
    cur.execute(
        "SELECT id, email FROM users WHERE email = %s",
        (email,),
    )
  9. 9

    Compare offset and cursor pagination.

    medium

    Offset pagination, LIMIT 20 OFFSET 4000, is simple but gets slower as the offset grows because the database still walks the skipped rows, and results shift if rows are inserted meanwhile. Cursor or keyset pagination filters from the last seen key, for example WHERE (created_at, id) < (?, ?) ORDER BY created_at DESC, id DESC LIMIT 20. It stays fast with a matching index and is stable, but cannot jump to page 50.

  10. 10

    Describe common caching strategies.

    medium

    Cache-aside: the app reads the cache, on a miss reads the database and fills the cache. Write-through writes both together, keeping the cache fresh at write cost. Write-behind buffers writes and risks loss. Always set a TTL. Watch for stampedes, where many requests rebuild an expired hot key at once, mitigated by locks, jittered expiry or serving stale data while refreshing.

  11. 11

    What is idempotency and how do you make a payment API idempotent?

    medium

    The client sends a unique Idempotency-Key header with each logical operation. The server stores the key with the request fingerprint and the response, and returns the stored response if the same key arrives again, so a retry after a timeout never charges twice. The key check and the charge must be in one transaction or protected by a unique constraint.

    sql
    CREATE TABLE idempotency_keys (
      key TEXT PRIMARY KEY,
      request_hash TEXT NOT NULL,
      response JSONB,
      created_at TIMESTAMPTZ DEFAULT now()
    );
  12. 12

    Implement a token bucket rate limiter.

    medium

    A bucket holds up to capacity tokens and refills at a fixed rate. Each request takes one token, and if none is left the request is rejected with 429. It allows short bursts while enforcing an average rate. In a distributed setup keep the counters in Redis and update them atomically with a Lua script. Complexity per request is O(1).

    python
    import time
    
    class TokenBucket:
        def __init__(self, capacity, rate):
            self.capacity, self.rate = capacity, rate
            self.tokens, self.ts = capacity, time.monotonic()
    
        def allow(self):
            now = time.monotonic()
            self.tokens = min(self.capacity, self.tokens + (now - self.ts) * self.rate)
            self.ts = now
            if self.tokens >= 1:
                self.tokens -= 1
                return True
            return False
  13. 13

    Why use a message queue?

    medium

    A queue decouples producers from consumers, so slow work such as sending email or generating reports runs asynchronously, spikes are absorbed, and a failed consumer can retry. Delivery is usually at-least-once, so consumers must be idempotent. Use a dead-letter queue for messages that keep failing. Kafka suits ordered, replayable event streams, while RabbitMQ or SQS suit task queues.

  14. 14

    Explain the CAP theorem accurately.

    hard

    During a network partition a distributed store must choose between consistency, where every read sees the latest write and some requests fail, and availability, where every request gets a response that may be stale. Partition tolerance is not optional in a real network. So the choice only applies during a partition. Mention PACELC: when there is no partition you still trade latency against consistency.

  15. 15

    How do you do a zero-downtime database migration, such as renaming a column?

    hard

    Use expand and contract. Add the new column, deploy code that writes both and reads the old, backfill existing rows in batches, switch reads to the new column, then drop the old one in a later release. Never rename in place while old code still runs. Add indexes concurrently where supported, and keep each migration small and reversible.

  16. 16

    How do you handle retries safely?

    hard

    Retry only idempotent operations or those protected by an idempotency key. Use exponential backoff with jitter so clients do not retry in lockstep, set a maximum attempt count and per-call timeouts, and retry only on transient errors such as timeouts and 503, not on 400. Add a circuit breaker so a failing dependency is not hammered, and make sure retries across layers do not multiply.

  17. 17

    What is connection pooling and what goes wrong without it?

    hard

    Opening a database connection costs a network round trip, authentication and server memory. A pool keeps a bounded set open and lends them to requests. Without one, load spikes exhaust the database connection limit. With one, size it from the database limit divided by the number of app instances, and always release connections in a finally block, or leaks stall the whole service. Tools like PgBouncer pool at the database side.

  18. 18

    How would you scale a read-heavy service?

    hard

    Profile first. Add indexes and fix slow queries, then add a cache for hot reads, then read replicas with the caveat of replication lag, so reads that must see a just-made write go to the primary. Put static content behind a CDN. Only then consider sharding, which adds large operational cost. Keep application servers stateless so they scale horizontally behind a load balancer.

Frequently asked questions

What should a backend developer know for interviews?

HTTP and REST, SQL and indexing, transactions, caching, authentication, queues, and how to reason about failures and scale. Know one language and one framework well.

Is system design asked for backend roles?

Yes, from about two years of experience onward, and often earlier in lighter form. Practise designing a URL shortener, a rate limiter and a notification service.

Which database should I focus on?

Know one relational database such as PostgreSQL or MySQL in depth, including indexes and transactions, and understand when a key-value or document store fits instead.

How do I answer scaling questions?

Start by measuring and finding the bottleneck, then apply the cheapest fix first: indexes, caching, replicas, and only then partitioning. Say what trade-off each step brings.

Related guides

More in Role-wise Interview Questions by Job and Tech Stack

See all in this section