20 questions · untimed

Python interview: Backend and design round

Pick an option and check it. The explanation shows after each answer. Take as long as you like; nothing is timed and nothing is sent.

20 questions

Question 1 · easy

In a REST API, which HTTP method is not idempotent by its definition in the HTTP standard (RFC 9110)?

Question 2 · easy

A client sends POST /orders and the server creates order 981. What is the best response?

Question 3 · easy

A user resource has name, email and phone. The client wants to change only the phone number. How do PUT /users/7 and PATCH /users/7 differ for this?

Question 4 · medium

A student logs in and receives a valid token. With that token she calls GET /admin/reports, which only admins may see. Which status code should the API return?

Question 5 · medium

What does this Python 3.12 program print?

IDEMPOTENT = {"GET", "PUT", "DELETE", "HEAD", "OPTIONS"}

def can_retry(method, status):
    if status == 429 or status >= 500:
        return method in IDEMPOTENT
    return False

calls = [("GET", 503), ("POST", 503), ("PUT", 429),
         ("DELETE", 404), ("GET", 400)]
print([m for m, s in calls if can_retry(m, s)])

Question 6 · easy

A teammate proposes adding an index on every column of the orders table, which takes thousands of inserts per minute, "so that every query is fast". What is the best advice?

Question 7 · medium

The orders table has a composite index on (customer_id, created_at). Which query can not use this index efficiently to find its rows?

Question 8 · medium

A page lists 50 orders. The code runs one query to fetch the orders and then, inside a loop, one query per order to fetch its customer. The page is slow. What is the problem, and what is the fix?

Question 9 · hard

Transaction T1 reads an account balance of 1000. Transaction T2 then updates it to 800 and commits. T1, still open, reads the same row again and gets 800. What is this anomaly, and what is the lowest standard SQL isolation level that prevents it?

Question 10 · easy

A money transfer debits account A and credits account B inside one transaction. The server crashes after the debit but before the commit. After the restart, account A still has its money. Which ACID property guarantees this?

Question 11 · easy

In the cache-aside (lazy loading) pattern, what does the application do when a read misses the cache?

Question 12 · medium

What does this Python 3.12 program print?

from functools import lru_cache

@lru_cache(maxsize=2)
def price(item):
    return len(item) * 10

for item in ["pen", "book", "pen", "bag", "book"]:
    price(item)
print(price.cache_info())

Question 13 · hard

Product prices are cached with cache-aside and a 10-minute TTL. When an admin changes a price, the service writes the new price to the database. What should it do with the cache so that reads stay correct with the least risk of serving a stale price?

Question 14 · easy

Your API runs on one server that is at full CPU. What is the difference between scaling it vertically and scaling it horizontally?

Question 15 · medium

You scale a web app from one server to three behind a round-robin load balancer. Login sessions are kept in each server's process memory. Users now get logged out at random. What is the best fix?

Question 16 · easy

After signup the API generates a welcome PDF and emails it to the user, which takes about 8 seconds, and the signup request waits for all of it. What is the standard design fix?

Question 17 · medium

You are designing a URL shortener. Every new long URL needs a short, unique key such as aZ3k9Qx. Which key scheme guarantees unique keys without checking for collisions?

Question 18 · hard

Writes go to the primary database and reads go to a read replica. A user edits their profile name, is redirected to the profile page and still sees the old name; a refresh a second later shows the new one. What is happening, and what is a good fix?

Question 19 · medium

Your API allows each client 100 requests per minute. A client sends its 101st request within the same minute. What is the best response?

Question 20 · medium

A social feed API pages with ?offset=...&limit=20 over ORDER BY created_at DESC. Users scrolling deep see duplicate posts as new posts arrive, and very deep pages are slow. Which design fits better?

Back to all rounds