Skip to content
Ameen Abozaid
Planned lessonJNR-034-L05

Demo: racing two requests against a unique constraint

  • Lesson 5 of 5
  • Junior
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

  1. Implement createProduct as if (!repo.existsBySku(sku)) repo.save(...) with no constraint.
  2. Fire two concurrent requests with the same SKU (two threads released by a CountDownLatch).
  3. Planned mistake: run it and show two rows with the same SKU.
  4. Add V3__unique_sku.sql (clean the duplicate first), then re-run.
  5. Map the violation to 409 in the exception handler.
  6. Result: one 201 and one 409, every time.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.