HTTP
Response Code
POST Method
Web Development
Server Responses

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.

http
1POST /api/users HTTP/1.1
2Host: api.example.com
3Content-Type: application/json
4
5{
6  "email": "[email protected]",
7  "name": "Alice Smith"
8}
http
1HTTP/1.1 409 Conflict
2Content-Type: application/json
3
4{
5  "error": "conflict",
6  "message": "A user with email [email protected] already exists",
7  "field": "email",
8  "existing_resource": "/api/users/42"
9}

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 CodeNameWhen to UseRFC Basis
409 ConflictConflictResource already exists, client can resolveRFC 9110, Section 15.5.10
422 Unprocessable EntityUnprocessable EntityValid syntax but semantic errors (validation failures)RFC 9110, Section 15.5.21
200 OKOKServer ignores the duplicate and returns the existing resourceRFC 9110, Section 15.3.1
204 No ContentNo ContentServer ignores the duplicate, nothing to returnRFC 9110, Section 15.3.5
303 See OtherSee OtherRedirect client to the existing resourceRFC 9110, Section 15.4.4
400 Bad RequestBad RequestMalformed 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:

http
1POST /api/subscriptions HTTP/1.1
2Content-Type: application/json
3
4{
5  "user_id": 42,
6  "plan": "pro"
7}
http
1HTTP/1.1 200 OK
2Content-Type: application/json
3
4{
5  "id": 99,
6  "user_id": 42,
7  "plan": "pro",
8  "created_at": "2025-01-15T10:30:00Z",
9  "already_existed": true
10}

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:

http
HTTP/1.1 303 See Other
Location: /api/users/42

Returning 409 in Express, Spring Boot and Django

Express.js / Node.js

javascript
1app.post('/api/users', async (req, res) => {
2  const { email, name } = req.body;
3
4  const existingUser = await db.users.findByEmail(email);
5
6  if (existingUser) {
7    return res.status(409).json({
8      error: 'conflict',
9      message: `A user with email ${email} already exists`,
10      existing_resource: `/api/users/${existingUser.id}`
11    });
12  }
13
14  const user = await db.users.create({ email, name });
15  res.status(201).json(user);
16});

Spring Boot / Java

java
1@PostMapping("/api/users")
2public ResponseEntity<?> createUser(@RequestBody CreateUserRequest request) {
3    Optional<User> existing = userRepository.findByEmail(request.getEmail());
4
5    if (existing.isPresent()) {
6        Map<String, String> error = Map.of(
7            "error", "conflict",
8            "message", "A user with this email already exists",
9            "existing_resource", "/api/users/" + existing.get().getId()
10        );
11        return ResponseEntity.status(HttpStatus.CONFLICT).body(error);
12    }
13
14    User user = userRepository.save(new User(request.getEmail(), request.getName()));
15    URI location = URI.create("/api/users/" + user.getId());
16    return ResponseEntity.created(location).body(user);
17}

Django / Python

python
1from rest_framework import status
2from rest_framework.response import Response
3from rest_framework.views import APIView
4
5class UserCreateView(APIView):
6    def post(self, request):
7        email = request.data.get('email')
8
9        if User.objects.filter(email=email).exists():
10            return Response(
11                {
12                    'error': 'conflict',
13                    'message': f'A user with email {email} already exists',
14                },
15                status=status.HTTP_409_CONFLICT
16            )
17
18        serializer = UserSerializer(data=request.data)
19        serializer.is_valid(raise_exception=True)
20        user = serializer.save()
21        return Response(
22            UserSerializer(user).data,
23            status=status.HTTP_201_CREATED
24        )

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.
http
1# POST: "Create a user" - 409 if email exists
2POST /api/users
3{"email": "[email protected]", "name": "Alice"}
4
5# PUT: "Set this specific user" - replaces if exists, creates if not
6PUT /api/users/[email protected]
7{"name": "Alice Smith"}

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:

sql
-- The database constraint catches what application-level checks miss
ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email);
python
1from django.db import IntegrityError
2
3class UserCreateView(APIView):
4    def post(self, request):
5        serializer = UserSerializer(data=request.data)
6        serializer.is_valid(raise_exception=True)
7        try:
8            user = serializer.save()
9            return Response(UserSerializer(user).data, status=201)
10        except IntegrityError:
11            return Response(
12                {'error': 'conflict', 'message': 'User already exists'},
13                status=409
14            )

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:

json
1{
2  "status": 409,
3  "error": "conflict",
4  "message": "A user with email [email protected] already exists",
5  "conflicting_field": "email",
6  "existing_resource_url": "/api/users/42",
7  "suggestion": "Use PUT /api/users/42 to update the existing user"
8}

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.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design