All jobs / Backend developer / API Development
Backend developer interview question · 0–1 years
The interviewer asks: “When is 404 the right status, and when is 400?” Strongest answer?
The strongest answer
404: that resource isn't here (or I must not reveal that it is). 400: the request itself is malformed — bad JSON, missing field, invalid id format.
Why it works
Exactly. 400 is “you sent something I cannot interpret.” 404 is “that thing isn't here.” Don't punish a missing row with a 5xx.
What a good answer covers
- 400 = malformed request; 404 = missing resource.
- Validate shape first — that is 400.
- A well-formed id that doesn't exist is 404.
- Don't turn “not found” into 500.
Answers that fall short
- Close, but not the strongest: 404 means not found, 400 means bad request. I return whichever the framework throws.
The dictionary is right; the habit of bubbling the framework's default is not. Choose the status for the client, then map the exception. - Weak: Use 404 for every client mistake so the URL looks cleaner.
A malformed body is not “not found.” 404 for syntax errors trains clients to retry the wrong way. - Red flag: Return 500 when a user asks for a missing id — the server failed to find it.
A missing resource is the client's request, not an outage. 500 pages people. 404 does not.
Who gets asked this
More API Development questions
- The interviewer sketches /getOrder and /doDeleteUser. Strongest design?
- The interviewer asks: “Which HTTP methods are safe to retry, and why?” Strongest answer?
- The interviewer asks: “How do you send and read JSON on an HTTP API?” Strongest answer?
- The interviewer asks: “What status do you return when POST creates a resource?” Strongest answer?
- The interviewer asks: “When do you nest URLs like /orders/12/items?” Strongest answer?
- In a GraphQL API, what is the schema and what is a resolver?
- The interviewer asks: “Do you return the database entity as JSON?” Strongest answer?
- The interviewer asks: “A handler throws. What does the client see?” Strongest answer?