Quiz · Medium
Twenty-three applied questions on stateless servers, middleware, layered architecture and MVC, ACID, indexes, joins, caching, queues, auth basics and containers.
Why does a stateless HTTP server make horizontal scaling easier?
Stateless servers never need a database
Stateless servers cache every response automatically
Any server instance can handle any request because no per-client memory is kept on the instance
Stateless servers use fewer HTTP methods
If a request carries everything needed (a cookie or token) and shared state lives in a database or Redis, a load balancer can send each request to any instance. The tempting wrong answers confuse 'stateless' with 'no data storage': the app still has data, it just is not kept in one server's memory.
An Express app registers its authentication middleware AFTER the route handler for /admin. What happens?
The route runs without authentication, because middleware executes in registration order
Express automatically moves auth middleware to the front
Every request to /admin returns 401
Express throws an error at startup
Middleware and routes run in the order they are registered. A handler that sends a response ends the chain, so middleware registered later never runs for it. Register auth before the routes it protects.
In this MVC diagram, which component notifies the View (dashed arrow)?

Model
Database
Browser
Controller
The dashed 'notifies' arrow goes from the Controller to the View, while the Model fills the View with data and the Controller updates the Model. Do not confuse 'fills' (Model to View) with 'notifies' (Controller to View). Image: Xinfe (initial work by Deltacen), CC BY-SA 3.0, via Wikimedia Commons.
In a layered backend, where should SQL queries normally live?
In the route/controller layer
In the repository (data access) layer
In the view templates
In the browser
Controllers deal with HTTP, services with business rules, and repositories with queries. Keeping SQL in one layer lets you change the database or optimize queries without touching business logic. Putting queries in controllers couples HTTP code to storage.
The diagram compares virtual machines (left) with containers (right). What does each VM include that a container does not?

A network interface
Its own full guest operating system
An application
Application libraries
Every VM boots a complete guest OS on top of a hypervisor. Containers share the host kernel and package only the app and its libraries, which is why they are smaller and start faster. Apps and libraries exist on both sides. Image: Drinkler, CC BY-SA 4.0, via Wikimedia Commons.
A server crashes after debiting one account but before crediting another, leaving the database inconsistent. Which ACID property was violated?
Isolation
Durability
Consistency of the HTTP layer
Atomicity
Atomicity means a transaction is all or nothing; a partial transfer must be rolled back. Durability is about committed data surviving crashes, and isolation is about concurrent transactions.
Which measure most directly reduces the risk of CSRF for cookie-based sessions?
Using a longer password
Hashing the cookie value
Setting the SameSite attribute on the session cookie
Enabling gzip compression
SameSite stops the browser from attaching the cookie to most cross-site requests (anti-CSRF tokens are the other main defense). Password strength and compression are unrelated.
A table has an index on email. Why is this query still slow?
SELECT * FROM users WHERE LOWER(email) = '[email protected]';
Applying LOWER() to the column prevents the plain index from being used
Indexes only work on numeric columns
SELECT * can never use an index
Because the query uses a string literal
The index stores the original email values, not their lowercase versions, so the database cannot use it for the function result. Fix: store emails normalized, use a case-insensitive collation or create an index on LOWER(email).
Transaction A reads a row twice. In between, transaction B commits a change to that row, and A sees two different values. What is this anomaly?
Dirty read
Phantom read
Non-repeatable read
Deadlock
A non-repeatable read is the same row returning different values within one transaction. A dirty read would involve reading B's UNCOMMITTED data; a phantom read concerns rows appearing or disappearing from a repeated range query.
What is the purpose of the middle table in this diagram?

It stores backups of both tables
It speeds up joins by caching results
It enforces that every book has exactly one author
It turns a many-to-many relationship into two one-to-many relationships
A relational database cannot store many-to-many directly. The junction table holds (author_id, book_id) pairs so each side has a one-to-many relationship to it. It is not a cache and does not limit books to one author.
A page lists 50 posts and runs one extra query per post to load its author, so 51 queries in total. What is this called and how do you fix it?
A deadlock; add a lock
The N+1 problem; load the authors with a join or batched query
A phantom read; raise the isolation level
A cache stampede; add a TTL
N+1 means 1 query for the list plus N for related rows. Use eager loading (join/include) or a single WHERE id IN (...) query. The other options are real problems but unrelated to this pattern.
A product price is updated in the database, but visitors keep seeing the old price for about ten minutes. What is the most likely cause?
The database has not committed the update
The load balancer uses round robin
A cached copy with a 10-minute TTL was not invalidated
The API uses HTTPS
With cache-aside, entries live until their TTL expires unless the write path invalidates or updates them. Fix by deleting or refreshing the cache key on update, or by shortening the TTL.
Which task is NOT normally done by a reverse proxy?
Running the application's business logic
TLS termination
Load balancing across servers
Caching static responses
A reverse proxy forwards traffic (and can terminate TLS, balance load, compress and cache). Business logic runs in the application servers behind it.
Which operation is the best candidate for a background job processed from a queue?
Sending a welcome email and generating a PDF invoice
Checking whether the submitted password is correct
Returning a 404 for an unknown URL
Validating that a form field is not empty
Work that is slow, can fail and does not need to block the user belongs in the background with retries. Login checks, validation and error responses must happen synchronously.
A table users has 3 rows: Ana has 2 orders, Ben has 0 orders, Cy has 1 order. How many rows does SELECT u.name, o.id FROM users u LEFT JOIN orders o ON o.user_id = u.id return?
3
6
4
2
Ana appears twice, Ben once with a NULL order id (LEFT JOIN keeps him), and Cy once: 2 + 1 + 1 = 4. An INNER JOIN would return 3 rows (Ben dropped).
You want orders whose customers have placed more than 5 orders. Which clause filters on COUNT(*) > 5 after grouping?
WHERE
HAVING
ON
LIMIT
HAVING filters groups after aggregation. WHERE runs before grouping and cannot use aggregate functions.
Which is the best way to store user passwords?
Encrypt them with AES so you can decrypt them for support
Hash them with SHA-256 and no salt
Store them in an environment variable
Hash them with Argon2id or bcrypt using a unique salt
Password hashes must be one-way, salted and deliberately slow. AES is reversible (a key leak exposes every password) and an unsalted fast hash can be brute forced or looked up in rainbow tables.
This code builds a query from user input. What is the correct fix?
db.query("SELECT * FROM users WHERE name = '" + name + "'")
Use a parameterized query: db.query('SELECT * FROM users WHERE name = $1', [name])
Remove quotes from the input in the browser
Convert the input to lowercase
Run the query as the database administrator
Parameterized queries keep data separate from SQL so input cannot change the query. Client-side cleanup is easily bypassed, lowercasing does nothing against injection, and running as admin makes it worse.
The product owner wants to be able to log a user out of every device instantly. Which approach is easiest?
Long-lived JWTs stored in localStorage
Longer cookies
Client-side expiry timers
Server-side sessions stored in a database or Redis, deleting the session
With server-side sessions, deleting the stored session invalidates it immediately. A self-contained JWT stays valid until it expires unless you add a denylist or very short lifetimes with refresh tokens.
A list endpoint uses OFFSET 100000 LIMIT 20 and is getting slow. Which change fixes the root cause?
Add more RAM to the web server
Use keyset (cursor) pagination: WHERE id > :last_id ORDER BY id LIMIT 20
Increase the page size to 100000
Remove the ORDER BY
With OFFSET the database must walk past all the skipped rows on every request. Keyset pagination seeks directly via an index. The other options do not address the scan.
True or false: a Docker container runs its own full operating system kernel.
True
False
False. Containers share the host machine's kernel and are isolated using namespaces and cgroups. Virtual machines are the ones that run a separate guest OS and kernel.
According to the CAP theorem, what must a distributed data store sacrifice during a network partition?
Either durability or atomicity
Either latency or throughput
Either SQL or JSON support
Either consistency or availability
When nodes cannot talk to each other you must choose: refuse some requests to stay consistent, or answer with possibly stale data to stay available. Partition tolerance is not optional.
What is a health check endpoint used for?
Letting load balancers and orchestrators know whether an instance should receive traffic or be restarted
Encrypting traffic
Storing user sessions
Generating database migrations
A cheap route like /health returns 200 when the service works, so unhealthy instances are removed from rotation or restarted automatically.