Explain what happens on the backend from the moment a request hits your server until a response is sent.
What the interviewer wants to hear
- DNS, TCP/TLS connection and load balancer route the request
- Web server or framework parses the request and runs middleware
- Routing to a handler, validation, business logic
- Database or cache calls, then building the response
- Status code, headers, body; logging and metrics
Model answer
The client first resolves the domain through DNS and opens a TCP connection with TLS. The request usually reaches a load balancer or reverse proxy like Nginx, which forwards it to one of the app instances. The framework parses the method, URL, headers and body, then runs middleware such as logging, CORS, rate limiting and authentication. The router matches the URL to a handler. The handler validates input, runs business logic, and reads or writes data in the database or cache, possibly calling other services. It then builds the response with a status code, headers like Content-Type and caching headers, and a JSON body. Error-handling middleware turns exceptions into proper error responses. Finally, the request is logged with its duration and status, and metrics and traces are recorded for monitoring.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Backend Developer questions
- How would you design a REST API for a simple blog with posts and comments? Mention URLs, methods and status codes.
- When would you choose a SQL database and when a NoSQL database?
- What is the difference between authentication and authorization? How would you implement both in an API?
- What is a database index, and what are its costs? How do you decide which columns to index?
- What is a database transaction, and what do the letters in ACID mean? Give an example where you need one.
- What are logs, metrics and traces, and how would you use each one to run a backend service?
- How would you test a new POST /orders endpoint? Which kinds of tests would you write?
- Why do backend teams package services with Docker, and what makes a good Dockerfile?
- Explain the HTTP status code classes and give examples of codes a REST API commonly returns.