AWS Builder Center
How to Prevent Double Booking in a Clinic Appointment System with DynamoDB and AWS Lambda

How to Prevent Double Booking in a Clinic Appointment System with DynamoDB and AWS Lambda

Prevent double booking in a clinic appointment system using AWS Lambda and DynamoDB transactions. Handle simultaneous requests, retries, cancellations, and rescheduling.

Series: Healthcare (8 articles)

  1. 2
    How to Prevent Double Booking in a Clinic Appointment System with DynamoDB and AWS Lambda This article

How to Prevent Double Booking in a Clinic Appointment System with DynamoDB and AWS Lambda

Two patients open the same clinic calendar. Both see a 10:30 a.m. slot available, and both click Book. If the backend checks availability and then saves the appointment in a separate operation, both requests can pass the check before either finishes writing.
The calendar can help patients choose a time. The booking write must decide who gets it.

Model the resource that can be booked only once

Start with a clinic that offers fixed, 15-minute appointments and takes bookings through one AWS Region. Create slot records ahead of time so the system can distinguish a bookable slot from a time the clinic never offered.
For a clinician who works across clinics, key the reservation by the clinician’s shared identifier and UTC start time. Store the clinic on the slot and verify it when booking. If the key includes the clinic, two locations could independently reserve the same clinician at the same time.
Record
Example
Purpose
Slot
 CLINICIAN#42 / 2026-11-12T05:00:00Z 
Holds availability and the current appointment reference
Appointment
 APPOINTMENT#a81 
Holds the patient, clinic, time, and status
Booking request
 REQUEST#p815#r73 
Associates an authenticated patient’s retry identifier with the original booking result

Reserve the slot and save the appointment together

After AWS Lambda checks the patient’s access and the requested appointment type, submit one DynamoDB transaction:
Update slot
Only if status = AVAILABLE and clinic = requested clinic
Set status = BOOKED and appointmentId = new appointment ID

Put appointment
Only if this appointment key does not exist

Put booking request
Only if this patient-scoped request key does not exist
Store the appointment ID and the normalized booking inputs
The writes commit as a unit. In the simultaneous booking example, one patient gets the appointment. The other receives a slot-unavailable response once the backend confirms the slot was taken. A transient database error should produce a retryable response, because the outcome may still be uncertain.
If the browser times out, it should retry with the same request identifier and booking inputs. Check the saved booking-request record before reporting a conflict. If the first attempt committed, return its appointment. If the same identifier arrives with different inputs, reject the conflicting request.

Make cancellations and rescheduling follow the same rules

A cancellation should release a slot only if the slot still points to the appointment being cancelled. In the same transaction, mark the appointment cancelled. A delayed cancellation retry can then leave a slot already reassigned to another patient intact.
When moving an appointment to a different slot, reserve the new slot, release the old slot, and update the appointment together. If the new slot is taken, the patient keeps the existing booking. For longer visits that span several fixed blocks, claim every required block in the same transaction.
Test
Expected result
Two patients request the same slot
One booking succeeds
One patient retries after a timeout
The original appointment is returned if it committed
The new slot is taken during rescheduling
The original booking remains active
A cancellation retries after another patient books the freed slot
The newer reservation is preserved
Run the concurrency test through both the patient portal and the staff booking interface. Every entry point must use the same reservation rule for the calendar to stay consistent.

Series: Healthcare (8 articles)

  1. 2
    How to Prevent Double Booking in a Clinic Appointment System with DynamoDB and AWS Lambda This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article