Premium

Clinic Appointment Website

Check the slot is free, then book it — and two patients get 5:30pm. The application code was never what made it correct.

  • PHP
  • MySQL

About this project

A clinic website with real appointment booking — services, doctor profiles, a booking flow that generates slots from each doctor's stored availability, and an admin for appointments, doctors and their weekly timings.

The booking code almost everyone writes does a SELECT to check whether 5:30pm with Dr Menon is free, and INSERTs if it comes back empty. It reads correctly and passes every manual test, because a human cannot click twice in the same millisecond. It is a race: two requests can both run the SELECT before either INSERTs, and both patients are told they have the slot. The fix is not a bigger transaction — it is a UNIQUE constraint so the database refuses the second write, with application code that turns the duplicate-key error into a clean "that slot has just been taken". The proof runs ten separate OS processes against one slot and prints the rows, and its sharpest experiment points the fixed application code at the same table with the index dropped: still ten bookings. The code was never what made it correct.

What you will learn

  • Recognise check-then-act as a race, and stop trusting it in booking code
  • Enforce uniqueness with a database constraint, catching the duplicate-key error properly
  • Tell a duplicate slot apart from a duplicate reference — two unique keys, two meanings
  • Know when a constraint cannot express the rule, and reach for a lock instead
  • Generate bookable slots from stored availability rather than hardcoding a timetable

Before you start

  • PHP basics, and comfort reading SQL
  • PHP 8.1+ and MySQL 8 (or MariaDB 10.4+)
  • Some idea of what a race condition is — the project will make it concrete

New to PHP? The free PHP course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.