Skip to content
Ameen Abozaid
Planned lessonJNR-034-L01

The database as the last line of defense

  • Lesson 1 of 5
  • Junior
On This Lesson 4 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

explain why the database must enforce rules, not just the application.

Planned topics

  • Many applications and tools can write to one database: services, scripts, admins.
  • Application checks can be skipped, buggy, or out of date.
  • Concurrency: two requests pass the same application check at the same time ("check then insert"), then both insert.
  • Constraints are enforced by the database for every writer, atomically.
  • Keep application validation for friendly messages; keep constraints for guarantees.
Draft outline details

Demonstration

a timeline of two requests: both exists(sku) = false, both insert, two rows; with a unique constraint the second insert fails.

Check your understanding

Why does "check then insert" fail?

Show answer

Two requests can both check before either inserts.

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.

Continue to next lesson

Type to search levels, phases, modules and lessons.