Design Doctor appointment booking system
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2021-12-17
Problem Statement
Design a scalable and reliable Doctor Appointment Booking System (like Practo, Zocdoc, or 1mg) that allows patients to search for doctors, view availability, book appointments, make payments, and receive reminders.
Functional Requirements (FR)
User Management
•Patient registration/login (email, phone, social login).
•Doctor registration with specialization, clinic/hospital details, consultation fee, availability schedule.
Doctor Discovery
•Search doctors by specialization, location, hospital, ratings, and availability.
•View doctor profiles (experience, reviews, consultation fees).
Appointment Booking
•Real-time slot availability for each doctor.
•Book, reschedule, or cancel appointments.
•Prevent double-booking of the same slot.
Payments
•Online payments (UPI, cards, wallets).
•Support cash at clinic.
•Refunds on cancellation (as per policy).
Notifications
•SMS/Email/App reminders for booked or canceled appointments.
•Alerts to doctors for new bookings.
Reviews & Ratings
•Patients can rate doctors and share feedback.
Admin Features
•Manage doctors, patients, and clinics.
•Analytics dashboard (most booked doctors, peak hours, revenue).
Non-Functional Requirements (NFR)
•Scalability: Handle millions of users, doctors, and appointments.
•Availability: High uptime (99.9%), as healthcare services are critical.
•Performance: Appointment booking should complete in < 200 ms.
•Consistency: Strong consistency required for slot booking (no double-booking).
•Security: Patient data must be encrypted (HIPAA/GDPR compliance).
•Reliability: System must guarantee that confirmed bookings are never lost.
Core Components / Modules
•User Service – registration, authentication, profiles.
•Doctor Service – manages doctor profiles, schedules, fees.
•Search Service – indexing & querying doctors (Elasticsearch).
•Appointment Service – handles slot availability, booking, rescheduling, and cancellation.
•Payment Service – integrates with external gateways.
•Notification Service – sends reminders/alerts.
•Review & Rating Service – stores patient feedback.
•Admin/Analytics Service – dashboards and reporting.
Data Flow (High Level)
1.Patient searches for a doctor → Search Service fetches from Doctor DB + cache.
2.Patient selects a doctor → Appointment Service checks slot availability.
3.If available → Appointment locked + stored in DB (atomic transaction).
4.Payment initiated → Payment Service validates → success/failure updates Appointment Service.
5.Notifications sent to patient & doctor.
Key Challenges / Design Considerations
•Preventing double booking → use row-level locking, distributed locks, or optimistic concurrency control.
•Scaling search across thousands of doctors with filters.
•Maintaining real-time availability when multiple patients attempt bookings simultaneously.
•Handling cancellations & refunds with idempotency.
•Compliance with healthcare data privacy regulations (HIPAA, GDPR).