Demo: racing two requests against a unique constraint
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
prove the application check fails under concurrency and the constraint saves you; prepares JNR-034-LAB1.
Draft outline details
Step by step
- Implement
createProductasif (!repo.existsBySku(sku)) repo.save(...)with no constraint. - Fire two concurrent requests with the same SKU (two threads released by a
CountDownLatch). - Planned mistake: run it and show two rows with the same SKU.
- Add
V3__unique_sku.sql(clean the duplicate first), then re-run. - Map the violation to 409 in the exception handler.
- Result: one 201 and one 409, every time.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.