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)?
A method is idempotent when sending the same request several times leaves the server in the same state as sending it once. GET, PUT and DELETE are idempotent: putting the same body twice or deleting an already deleted resource changes nothing more (the second DELETE may return 404, but the state is the same). POST is not, so two identical POST /orders calls can create two orders, which is why clients must not retry it blindly.
Question 2 · easy
A client sends POST /orders and the server creates order 981. What is the best response?
201 Created says a new resource now exists, and the Location header gives its URL so the client can fetch or link to it. 204 No Content drops the body, so the client never learns the server-assigned id. 202 Accepted means the work was only queued and is not done yet, which would mislead the client here.
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?
PUT means "make the resource at this URL equal to this body", so fields left out may be cleared and a one-field update must still send the full object. PATCH carries a set of changes and is the method for partial updates. PUT is idempotent by definition; PATCH is not guaranteed to be (an "append to this list" patch adds again on every retry).
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?
401 means the request lacks valid credentials (missing, expired or wrong token) and the client should authenticate. Here the server knows exactly who she is but she lacks the permission, which is 403: logging in again will not help. Some APIs answer 404 on purpose to hide that a resource exists, but that is a privacy choice, and 400 is for a malformed request.
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)])
A retry only helps when the failure can be temporary: a 5xx server error, or 429 after waiting. It is only safe to do automatically for idempotent methods, so the POST that got 503 is skipped, since the first attempt may already have created the order. 404 and 400 are client errors, and the same request would fail again.
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?
An index speeds up lookups, joins and sorts on its columns, but it is a second data structure the database keeps in sync on every write, and it takes storage. On a write-heavy table each extra index slows inserts and updates. Add indexes for the queries the app really runs and check in the query plan that they are used.
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?
A composite index is sorted by its first column and then by the second within each first-column value, like a phone book sorted by surname, then first name. Queries that filter on the leftmost column, alone or together with the next one, seek straight to their rows and even get created_at order for free. A filter on created_at alone skips the leading column, so the database has to scan instead; put the equality-filtered column first.
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?
N+1 means one query for the list plus one per row, so the cost grows with the page size and every query pays a network round trip. Fetch the related rows in one go: a join, or a second query with IN over the collected ids, which is what eager loading in an ORM does. Caching or a bigger server hides the symptom without removing the extra round trips.
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?
A dirty read is seeing another transaction's uncommitted change, but T2 had committed, so this is not one. Reading the same row twice in one transaction and getting two different committed values is a non-repeatable read: READ COMMITTED allows it and REPEATABLE READ forbids it. A phantom is about new rows appearing when a range query is repeated, not about a changed row.
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?
Atomicity means a transaction is all or nothing: if it does not commit, every change in it is rolled back, so a half-done transfer never survives. Durability is the promise for work that did commit (it survives a crash). Isolation keeps concurrent transactions from seeing each other's partial work, and consistency means a transaction moves the database from one valid state to another under its rules and constraints.
Question 11 · easy
In the cache-aside (lazy loading) pattern, what does the application do when a read misses the cache?
In cache-aside the application does both steps itself: check the cache, and on a miss load from the database, store the value in the cache (usually with a TTL) and return it. Later reads of the same key are hits until the entry expires or is invalidated. A cache that loads from the database on its own is the read-through pattern, a different design.
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())
lru_cache(maxsize=2) keeps the two most recently used results. pen and book miss; the second pen is a hit and makes pen the most recent, so bag evicts book, the least recently used, and the final book misses again. That is 1 hit and 4 misses; a FIFO cache, which evicts by insertion order, would have evicted pen instead and scored 2 hits.
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?
Deleting the key after the commit means the next read misses and loads the committed value. Writing the cache first can leave a price in the cache that the database never accepted if the write fails, and with concurrent writers the two can end up disagreeing. Relying on the TTL alone serves the old price for up to 10 minutes, and flushing everything sends every read to the database at once; the TTL is still useful as a backstop for a missed invalidation.
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?
Vertical scaling (scale up) is simple and needs no code changes, but it hits a hardware ceiling and the one machine stays a single point of failure. Horizontal scaling (scale out) adds servers behind a load balancer and can keep growing, but the app must be stateless, with no per-server sessions or local files, so that any server can serve any request.
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?
With round-robin, a user's requests reach different servers, and a server that did not create the session does not know it. Moving session state out of the app servers, to a shared store or into a signed token, makes them stateless, so servers can be added, removed or restarted freely. Sticky sessions also hide the problem, but a user loses the session when that server dies and the load becomes uneven.
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?
Slow work the user does not need in the response belongs outside the request: the API commits the signup, enqueues a job and replies quickly. Workers consume the queue at their own pace, can be scaled separately and can retry a failed email. A longer timeout or a thread the request waits on still keeps the user waiting and ties up a server worker.
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?
Base62-encoding a unique integer is a one-to-one mapping, so distinct IDs always give distinct keys, and 7 characters cover 62^7, about 3.5 trillion IDs. A truncated hash or a random string can collide, so those schemes need a uniqueness check and a retry. A timestamp collides whenever two links are created in the same second.
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?
Replicas usually apply the primary's changes asynchronously, so they can be slightly behind. That is fine for most reads but breaks the expectation that users see their own changes at once. Routing a user's reads to the primary for a short window after a write, or reading that one page from the primary, gives read-your-own-writes while the rest of the read load stays on the replicas.
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?
429 tells the client exactly what happened (it, not the server, went over a limit), and Retry-After tells it how long to wait, so well-behaved clients back off instead of hammering. 503 blames the server and 403 suggests a permission problem that waiting will not fix. When several servers enforce the same limit, keep the counters in a shared store, or each server would allow its own 100.
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?
With offset, the database reads and throws away every skipped row, so deep pages get slower, and new rows at the top shift every later page, which causes duplicates or skipped items. A cursor remembers where the last page ended, so the next query seeks straight there through the index and stays stable when new items arrive. The trade-off is that a cursor cannot jump to an arbitrary page number.
Your answers stay in this browser tab. Nothing is sent or saved.