error code 409

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

  1. Duplicate registration

Trying to create:

  • existing username,
  • email,
  • phone number.
  1. Concurrent editing

Two users edit the same document simultaneously.

  1. Version mismatch

Updating old resource version:

http id=”u8w5kc”
If-Match: old-etag

  1. 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
  1. Validate uniqueness

Laravel

php id=”r4k9zn”
$request->validate([
’email’ => ‘unique:users’
]);

  1. Return proper conflict response

Node.js Express

js id=”t2p5xe”
res.status(409).json({
error: ‘User already exists’
});

  1. Database handling

MySQL unique index

sql id=”q6m3yt”
ALTER TABLE users
ADD UNIQUE(email);

  1. API optimistic locking

Use:

  • ETags
  • version numbers
  • timestamps

to prevent overwriting newer changes.

Difference between 400, 409, and 412

CodeMeaning
400Invalid request
409Resource state conflict
412Conditional request failed

Related HTTP status codes

| Code | Meaning |
| — | – |
| 400 | Bad Request |
| 404 | Not Found |
| 409 | Conflict |
| 410 | Gone |
| 412 | Precondition Failed |
| 422 | Validation Error |