Bird
Raised Fist0
Rest APIprogramming~20 mins

409 Conflict in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Conflict Resolver
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the HTTP status code returned?

Consider a REST API endpoint that updates a user profile. If two clients try to update the same user data simultaneously, the server detects a conflict and returns a 409 Conflict status code.

What will be the HTTP status code in the response when this conflict occurs?

Rest API
HTTP/1.1 409 Conflict
Content-Type: application/json

{"error": "Conflict detected: resource has been modified."}
A409 Conflict
B404 Not Found
C200 OK
D500 Internal Server Error
Attempts:
2 left
💡 Hint

Think about which status code means the request conflicts with the current state of the resource.

🧠 Conceptual
intermediate
1:30remaining
Why use 409 Conflict instead of 400 Bad Request?

When a client sends a request that conflicts with the current state of a resource, why is it better to respond with a 409 Conflict status code rather than a 400 Bad Request?

ABecause 400 Bad Request indicates the server is down.
BBecause 400 Bad Request means the client sent malformed syntax, not a conflict.
CBecause 409 Conflict means the server accepted the request without issues.
DBecause 400 Bad Request is only for authentication errors.
Attempts:
2 left
💡 Hint

Think about the difference between syntax errors and resource state conflicts.

❓ Predict Output
advanced
2:00remaining
What is the output of this conflict handling code?

Given the following Python Flask code snippet handling a PUT request to update a resource, what will be the HTTP status code returned if the resource version does not match?

Rest API
from flask import Flask, request, jsonify
app = Flask(__name__)

resources = {"item1": {"version": 1, "data": "old"}}

@app.route('/resource/<id>', methods=['PUT'])
def update_resource(id):
    if id not in resources:
        return jsonify({"error": "Not found"}), 404
    client_version = request.json.get('version')
    if client_version != resources[id]['version']:
        return jsonify({"error": "Version conflict"}), 409
    resources[id]['data'] = request.json.get('data')
    resources[id]['version'] += 1
    return jsonify(resources[id]), 200

# Assume a PUT request with JSON {"version": 0, "data": "new"} to /resource/item1
A200 OK with updated resource data
B404 Not Found
C409 Conflict with error message 'Version conflict'
D500 Internal Server Error
Attempts:
2 left
💡 Hint

Check the version comparison logic in the code.

🔧 Debug
advanced
2:30remaining
Identify the bug causing incorrect status code

In this Node.js Express code, the server should return 409 Conflict when a resource update conflicts, but it always returns 200 OK. What is the bug?

Rest API
const express = require('express');
const app = express();
app.use(express.json());

const resources = { item1: { version: 1, data: 'old' } };

app.put('/resource/:id', (req, res) => {
  const id = req.params.id;
  if (!resources[id]) {
    return res.status(404).json({ error: 'Not found' });
  }
  const clientVersion = req.body.version;
  if (clientVersion !== resources[id].version) {
    return res.status(409).json({ error: 'Version conflict' });
  }
  resources[id].data = req.body.data;
  resources[id].version += 1;
  res.status(200).json(resources[id]);
});
AMissing return statements after res.status calls causing multiple responses
BIncorrect comparison operator used for version check
Cresources object is not defined properly
DMiddleware for parsing JSON is missing
Attempts:
2 left
💡 Hint

Check what happens after sending a response with res.status().json()

🚀 Application
expert
1:00remaining
How many items are in the conflict error response list?

A REST API returns a 409 Conflict response with a JSON body listing multiple conflicting fields as follows:

{
  "error": "Conflict detected",
  "conflicts": [
    {"field": "email", "message": "Email already in use"},
    {"field": "username", "message": "Username taken"},
    {"field": "phone", "message": "Phone number conflict"}
  ]
}

How many conflict items are in the "conflicts" list?

A4
B2
C1
D3
Attempts:
2 left
💡 Hint

Count the number of objects inside the "conflicts" array.

Practice

(1/5)
1. What does the HTTP status code 409 Conflict indicate in a REST API?
easy
A. The request cannot be completed because it conflicts with the current state of the server data.
B. The requested resource was not found on the server.
C. The server encountered an unexpected error while processing the request.
D. The request was successful and a new resource was created.

Solution

  1. Step 1: Understand HTTP status codes purpose

    Each HTTP status code has a specific meaning. 409 means conflict with current data.
  2. Step 2: Match 409 meaning to options

    The request cannot be completed because it conflicts with the current state of the server data. correctly describes 409 as a conflict preventing request completion.
  3. Final Answer:

    The request cannot be completed because it conflicts with the current state of the server data. -> Option A
  4. Quick Check:

    409 Conflict = Request conflicts with server data [OK]
Hint: 409 means data conflict stops request completion [OK]
Common Mistakes:
  • Confusing 409 with 404 Not Found
  • Thinking 409 means server error (500)
  • Assuming 409 means success
2. Which of the following is the correct way to respond with a 409 Conflict status in a REST API using HTTP headers?
easy
A. HTTP/1.1 200 OK
B. HTTP/1.1 500 Internal Server Error
C. HTTP/1.1 409 Conflict
D. HTTP/1.1 404 Not Found

Solution

  1. Step 1: Identify correct HTTP status line for 409

    The status line must include the code 409 and the phrase 'Conflict'.
  2. Step 2: Match status line to options

    HTTP/1.1 409 Conflict correctly shows 'HTTP/1.1 409 Conflict'. Others show wrong codes.
  3. Final Answer:

    HTTP/1.1 409 Conflict -> Option C
  4. Quick Check:

    409 Conflict status line = HTTP/1.1 409 Conflict [OK]
Hint: 409 Conflict status line must say '409 Conflict' exactly [OK]
Common Mistakes:
  • Using 200 OK instead of 409
  • Mixing 404 or 500 with 409
  • Omitting the status phrase 'Conflict'
3. Consider this REST API response snippet when two clients try to update the same resource simultaneously:
{
  "status": 409,
  "message": "Update conflict: resource has been modified by another client."
}

What is the expected client behavior after receiving this response?
medium
A. Fetch the latest resource state and resolve the conflict before retrying.
B. Ignore the conflict and assume update succeeded.
C. Retry the update immediately without changes.
D. Delete the resource to avoid conflicts.

Solution

  1. Step 1: Understand 409 Conflict meaning in concurrent updates

    It means the resource changed since client last fetched it, so update conflicts.
  2. Step 2: Determine safe client action

    Client should get latest data, resolve differences, then retry update to avoid overwriting.
  3. Final Answer:

    Fetch the latest resource state and resolve the conflict before retrying. -> Option A
  4. Quick Check:

    409 Conflict means update conflict; fetch and resolve first [OK]
Hint: On 409, fetch latest data before retrying update [OK]
Common Mistakes:
  • Retrying update blindly causing repeated conflicts
  • Ignoring the conflict and assuming success
  • Deleting resource unnecessarily
4. You have this server code snippet handling updates:
if resource.version != client_version:
    return Response(status=409, body={"error": "Version mismatch"})
else:
    update_resource()

But clients report they get 409 even when no conflict exists. What is the likely bug?
medium
A. Clients are sending wrong HTTP methods.
B. The update_resource() function is missing.
C. The server should return 404 instead of 409.
D. The server is not comparing versions correctly; types may differ causing mismatch.

Solution

  1. Step 1: Analyze version comparison logic

    If types differ (e.g., string vs int), equality check fails causing false conflicts.
  2. Step 2: Identify likely cause of false 409

    Incorrect type comparison leads to always triggering 409 even if versions match logically.
  3. Final Answer:

    The server is not comparing versions correctly; types may differ causing mismatch. -> Option D
  4. Quick Check:

    Type mismatch in version check causes false 409 [OK]
Hint: Check data types when comparing versions to avoid false conflicts [OK]
Common Mistakes:
  • Assuming missing update function causes 409
  • Confusing 409 with 404 errors
  • Blaming client HTTP methods without evidence
5. You are designing a REST API for editing documents. To prevent update conflicts, you decide to use the 409 Conflict status. Which approach best uses 409 to handle concurrent edits?
hard
A. Always accept updates and overwrite existing data without checks.
B. Require clients to send a version number with updates; if it doesn't match server's current version, respond with 409 and conflict details.
C. Return 409 whenever a client sends an update, regardless of version.
D. Ignore versioning and rely on client retries without conflict responses.

Solution

  1. Step 1: Understand concurrency control with 409

    Using version numbers lets server detect if data changed since client last fetched it.
  2. Step 2: Choose approach that uses 409 properly

    Require clients to send a version number with updates; if it doesn't match server's current version, respond with 409 and conflict details. uses version check and returns 409 only on real conflicts with details.
  3. Final Answer:

    Require clients to send a version number with updates; if it doesn't match server's current version, respond with 409 and conflict details. -> Option B
  4. Quick Check:

    Version check + 409 Conflict = best concurrency control [OK]
Hint: Use version numbers and 409 to handle concurrent edits safely [OK]
Common Mistakes:
  • Overwriting data blindly without conflict checks
  • Returning 409 for every update request
  • Ignoring versioning and conflicts
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard