HTTP Status Code 409 = “Conflict”
The request could not be completed because it conflicts with the current state of the resource on the server.
Common causes
- Duplicate data creation
- Concurrent updates
- Version conflicts
- Resource already exists
- Git merge conflicts
- Database uniqueness violations Example Client request
http id=”m7q2we”
POST /users
Payload
json id=”v4k8ra”
{
“email”: “user@example.com”
}
If that email already exists:
http id=”n3p1xd”
HTTP/1.1 409 Conflict
Common real-world scenarios
- Duplicate registration
Trying to create:
- existing username,
- email,
- phone number.
- Concurrent editing
Two users edit the same document simultaneously.
- Version mismatch
Updating old resource version:
http id=”u8w5kc”
If-Match: old-etag
- Git conflict
bash id=”g7q2mv”
git push
fails because remote changes exist.
Fixes
For users
- Refresh latest data
- Retry request
- Use different username/email
- Resolve merge conflicts For developers
- Validate uniqueness
Laravel
php id=”r4k9zn”
$request->validate([
’email’ => ‘unique:users’
]);
- Return proper conflict response
Node.js Express
js id=”t2p5xe”
res.status(409).json({
error: ‘User already exists’
});
- Database handling
MySQL unique index
sql id=”q6m3yt”
ALTER TABLE users
ADD UNIQUE(email);
- API optimistic locking
Use:
- ETags
- version numbers
- timestamps
to prevent overwriting newer changes.
Difference between 400, 409, and 412
| Code | Meaning |
|---|---|
400 | Invalid request |
409 | Resource state conflict |
412 | Conditional request failed |
Related HTTP status codes
| Code | Meaning |
| — | – |
| 400 | Bad Request |
| 404 | Not Found |
| 409 | Conflict |
| 410 | Gone |
| 412 | Precondition Failed |
| 422 | Validation Error |