HTTP status code when a resource already exists: 409 Conflict
Codemia Knowledge Hub ·
Return 409 Conflict when a POST request tries to create a resource that already exists. It tells the client exactly why the request failed and implies the conflict can be resolved, for example by choosing a different identifier. 422 Unprocessable Entity and 200 OK are sometimes used, but 409 Conflict is the widely accepted standard for duplicate creation attempts.
Why 409 Conflict fits duplicates
RFC 9110 (which supersedes RFC 7231) defines 409 as: "The request could not be completed due to a conflict with the current state of the target resource." A POST that creates a user with an email that already exists is a textbook case: the request payload conflicts with the existing state of the collection.
The body should explain the conflict and ideally point to the existing resource, so the client can decide whether to update it instead.
Other status codes and when they apply
| Status Code | Name | When to Use | RFC Basis |
409 Conflict | Conflict | Resource already exists, client can resolve | RFC 9110, Section 15.5.10 |
422 Unprocessable Entity | Unprocessable Entity | Valid syntax but semantic errors (validation failures) | RFC 9110, Section 15.5.21 |
200 OK | OK | Server ignores the duplicate and returns the existing resource | RFC 9110, Section 15.3.1 |
204 No Content | No Content | Server ignores the duplicate, nothing to return | RFC 9110, Section 15.3.5 |
303 See Other | See Other | Redirect client to the existing resource | RFC 9110, Section 15.4.4 |
400 Bad Request | Bad Request | Malformed request (not the right fit for duplicates) | RFC 9110, Section 15.5.1 |
409 vs. 422
422 Unprocessable Entity means the body is syntactically valid but semantically wrong, which fits validation errors like "email format is invalid" or "age must be positive." A duplicate is different: the data is valid, but it conflicts with existing state. Use 422 for validation failures and 409 for state conflicts.
200 OK for an idempotent POST
Some APIs deliberately treat POST as idempotent and return 200 OK with the existing resource. That is valid when the client does not care whether it created the resource or it already existed:
The already_existed flag lets the client tell a new creation from a pre-existing resource.
303 See Other
303 See Other says "this resource already exists, look here." It is semantically clean but rare in JSON APIs, because API clients do not typically follow redirects automatically for POST requests:
Returning 409 in Express, Spring Boot and Django
Express.js / Node.js
Spring Boot / Java
Django / Python
PUT vs. POST for existing resources
- POST creates a new resource. If it already exists, the server should reject the request (409) or treat it as idempotent (200).
- PUT creates or replaces the resource at a specific URL. If it exists, PUT updates it; replacement is the intended behavior, so there is no conflict.
For "create or update," use PUT with the identifier in the URL. For strict "create only," use POST and return 409 on duplicates.
Race conditions: enforce uniqueness in the database
Under concurrency, two requests can both check for existence, find nothing, and both create the resource. A database uniqueness constraint catches this:
The constraint is the source of truth. The application-level check is a performance optimization (it skips a write on obvious duplicates), not a correctness guarantee.
What a 409 response body should contain
Give the client enough information to act:
An empty body or a generic "Conflict" message leaves the client guessing which field caused the conflict and what to do next.
Mistakes with duplicate-resource responses
Using 400 Bad Request. A 400 means the request is malformed (bad JSON, missing required fields). A duplicate is a well-formed request that conflicts with existing state, a fundamentally different error category.
Returning 409 without identifying the conflict. Always include the conflicting field and a human-readable message.
Relying on check-then-insert. It is not atomic. Without a uniqueness constraint, two concurrent POSTs can both pass the check and create duplicates.
Using 409 for validation errors. "Email format is invalid" is a 422. Reserve 409 for conflicts with existing server state.
Inconsistent codes across endpoints. If /api/users returns 409 for duplicates but /api/products returns 422, clients need different handling per endpoint. Pick one convention for the whole API.
Related reading
- http server respnd with an output from an async function
- HTTP URL Address Encoding in Java
- HttpClient and using proxy - constantly getting 407
- HttpListener class with HTTPS support
- https on S3 WITHOUT cloudfront possible?
- httptrace endpoint of Spring Boot Actuator doesn't exist anymore with Spring Boot 2.2.0
- I want to get the host MAC address in kubernetes pod where that pod runing on
- I want to know the size of bounding box in object-detection api
System design interview problems on this topic
- Design a Load Balancer: solution and walkthrough
- Design a Domain Name System: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.