Conflict and Validation Errors: 409 and 422
You'll learn when to use HTTP 409 Conflict versus 422 Unprocessable Entity to communicate why a request failed.
What's the Difference?
When a REST API rejects a request, choosing the right 4xx status code helps clients understand why and how to fix it. Two commonly confused codes are 409 Conflict and 422 Unprocessable Entity.
409 Conflict signals a state conflict — the request is valid, but it conflicts with the current state of the resource. Think of it like trying to book a hotel room that someone just reserved seconds ago. Your request format was perfect, but the timing created a conflict with reality.
422 Unprocessable Entity indicates validation failure — the server understood the request format, but the data itself doesn't meet business rules. Imagine submitting a form where the email address is missing the "@" symbol, or a password is too short. The request reached the server fine, but the content fails validation.
The Hotel Analogy
- 409: "Sorry, that room was just booked by another guest" — resource state conflict
- 422: "Sorry, your check-in date can't be before today" — data validation error
When to Use Each
Use 409 Conflict when:
- A resource already exists (trying to create duplicate username)
- Concurrent modification detected (optimistic locking failure)
- Business state prevents the action (can't delete an order being shipped)
Use 422 Unprocessable Entity when:
- Required fields are missing
- Data format is wrong (invalid email, negative quantity)
- Business rules violated (discount code expired, insufficient stock)
Key Takeaway: Use 409 for conflicts with resource state and timing; use 422 for problems with the submitted data itself. Both help clients understand whether to retry, modify their data, or handle the situation differently.