HTTP 409 Conflict — What It Means and How to Fix It
The HTTP 409 Conflict status code indicates that the request could not be completed due to a conflict with the current state of the target resource. This typically happens when a client attempts to modify a resource that has been updated by another client, or when a unique constraint is violated.
Essential Reading: Designing Data-Intensive Applications
The system design bible for software engineers. Learn to build reliable, scalable, and maintainable systems.
Common Causes
- Concurrent updates to the same resource (e.g., two users editing the same document simultaneously).
- Violation of a unique constraint (e.g., trying to create a user with an email address that already exists).
- Attempting to perform an operation on a resource that is in an invalid state for that operation (e.g., deleting a non-empty directory without specifying a recursive delete).
- Version mismatch, often indicated by an `If-Match` header failing.
Code Examples to Handle HTTP 409
curl -I https://httpbin.org/status/409
How to Fix It
- Review the response body for specific details about the conflict, as the server should provide information on why the request failed.
- If the conflict is due to concurrent updates, retrieve the latest version of the resource, merge changes if necessary, and then re-attempt the request.
- If a unique constraint is violated, modify the request payload to ensure uniqueness (e.g., provide a different email address).
- For version conflicts, ensure the `If-Match` header (if used) contains the correct ETag for the current resource state.
Related Status Codes
Frequently Asked Questions
What causes HTTP 409?
HTTP 409 is caused by a conflict with the current state of the resource, often due to concurrent modifications, unique constraint violations, or attempting an operation on a resource in an unsuitable state.
How do I fix HTTP 409?
To fix HTTP 409, examine the server's response for details. You'll typically need to retrieve the latest resource version, resolve any conflicts (e.g., merge changes), or modify your request to satisfy unique constraints before re-attempting the operation.