Explain the HTTP status code classes and give examples of codes a REST API commonly returns.
What the interviewer wants to hear
- 2xx success: 200, 201, 204
- 3xx redirection and caching: 301, 304
- 4xx client errors: 400, 401, 403, 404, 409, 422, 429
- 5xx server errors: 500, 502, 503, 504
- Correct codes help clients decide whether to retry
Model answer
Status codes are grouped by their first digit. 2xx means success: 200 OK for a normal response, 201 Created after creating a resource, and 204 No Content when there is nothing to return, such as after a delete. 3xx is about redirects and caching, like 301 for a permanent move and 304 Not Modified for a valid cached copy. 4xx means the client did something wrong: 400 for bad input, 401 when not authenticated, 403 when authenticated but not allowed, 404 when the resource does not exist, 409 for a conflict like a duplicate, 422 for valid JSON that fails business rules, and 429 for rate limiting. 5xx means the server failed: 500 for an unexpected error, 502 and 504 from gateways, and 503 when temporarily unavailable. Using them correctly matters because clients and proxies decide on retries from them: retrying a 503 makes sense, retrying a 400 does not.
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?
- Explain what happens on the backend from the moment a request hits your server until a response is sent.
- 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?