π₯ Patient Tracker β Complete Interview Mastery & Project Walkthrough
The Ultimate Guide for Senior / Staff / SDE-1 / SDE-2 Technical & Managerial Interviews.
Contains verbatim spoken scripts, elevator pitches, step-by-step technical explanations, architectural diagrams, concurrency deep dives, and exact word-for-word answers to every tough cross-question.
π Table of Contents
- What Is This Project About? (The Plain-English Concept)
- What to Say in an Interview: "Explain Your Project"
- End-to-End Workflow & User Journeys
- High-Level System Architecture
- Tech Stack & Justifications ("Why X over Y?")
- Your Specific Contributions & Resume Bullet Points
- The 3 Core Technical Stories (STAR Method)
- Concurrency & Thread Safety Deep Dive (Juspay / High-Bar Focus)
- Scaling, Bottlenecks & 10x/100x Evolution
- Engineering Trade-offs & What You Would Do Differently
- Cross-Questioning Masterclass (15+ Exact Q&A Scripts)
- Provable Numbers & Metrics Sheet
1. What Is This Project About? (The Plain-English Concept)
The Real-World Problem:
Most outpatient healthcare and small-to-medium clinics suffer from a severe "post-consultation gap":
- After a doctor consults a patient and hands them a paper prescription, they have zero visibility into whether the patient actually takes their medicine on time.
- Patients forget their dosages or timing, leading to high non-adherence rates and poor clinical outcomes.
- Appointment booking is handled via phone calls, WhatsApp, or receptionist paper logs, causing frequent double-booking and administrative overhead.
- Follow-up communication is fragmented across unorganized chat apps.
The Solution:
Patient Tracker is an end-to-end clinical workflow and adherence platform that digitizes the entire doctor-patient relationship:
- Doctors onboard patients, generate multi-medicine structured prescriptions, manage appointment availability, and monitor live adherence analytics.
- Patients receive a streamlined daily schedule (Morning / Afternoon / Evening), log their medication consumption (
Taken/Missed), book conflict-free appointment slots, and chat directly with their assigned doctor in real time. - The System runs automated background sweeps at scheduled transition intervals (8 AM, 1 PM, 8 PM), sends reminder emails, detects overdue doses, and enforces strict database-level concurrency protection so no two patients can ever book the same doctor at the same time.
2. What to Say in an Interview: "Explain Your Project"
Use the level of detail matching how the interviewer asked the question.
β‘ 30-Second Elevator Pitch (Quick Round)
"I built Patient Tracker, a full-stack clinical management and medication adherence system using React 19, Node.js/Express, PostgreSQL with Prisma, and Socket.io.
It bridges the post-consultation gap: doctors issue structured digital prescriptions, while patients get a daily time-windowed medication schedule with automated email reminders and adherence tracking.
The key technical highlight is our concurrency-safe appointment engine, which uses a PostgreSQL partial unique index to guarantee zero double-booking under race conditionsβvalidated with a 50-request parallel load test."
ποΈ 90-Second Standard Interview Response (The Gold Standard)
(When the interviewer says: "Tell me about your project", "Walk me through what you built", or "Pick a project from your resume and explain it")
"The core problem I tackled with Patient Tracker is post-consultation non-adherence and fragmented clinic operations. Small clinics still rely on paper prescriptions and phone calls, leaving doctors blind to whether patients follow their treatment plan.
I designed and built a two-role platform for Doctors and Patients with three core pillars:
- Prescription & Adherence Engine: When a doctor prescribes medications with specific daily timings, the system translates them into discrete morning, afternoon, and evening
MedicineAdherenceentities. A background scheduler runs at 8 AM, 1 PM, and 8 PM to dispatch reminder alerts and auto-mark overdue doses as missed.- Concurrency-Safe Slot Booking: To solve double-booking race conditions when multiple patients attempt to book the same doctor slot simultaneously, I implemented a PostgreSQL partial unique index on
(doctorId, slotStart) WHERE status <> 'cancelled'. This offloads conflict serialization directly to the database engine, returning a clean 409 Conflict upon collision.- Real-Time Communication & Security: I implemented room-isolated WebSockets using Socket.io for clinical consultations and strict RBAC middleware preventing Insecure Direct Object References (IDOR) by validating doctor-patient relationships prior to data retrieval.
The stack is React 19 with Tailwind on the client, Node.js/Express on the backend, and PostgreSQL with Prisma ORM. If I were rebuilding it today, I'd decouple the in-process cron into a distributed queue like BullMQ with Redis to enable horizontal scaling."
ποΈ 3-Minute Deep Technical Walkthrough (System Design / Deep Dive)
(When an interviewer asks: "Explain the architecture, how data flows, and your core technical decisions")
"Let me break down the architecture across four layers: Client, API Gateway & Security, Core Engines, and the Persistence Layer.
1. Client & Authentication Layer:
The frontend is a React 19 SPA. We have two role-specific dashboardsβone for doctors and one for patients. Authentication uses stateless 24-hour JWTs. Patient onboarding uses a two-phase cryptographic invitation workflow: a doctor registers a patient, the backend generates a time-limited invitation token, and the patient activates their account and sets their password via email.2. API Gateway & RBAC Pipeline:
Every protected request flows through an Express middleware pipeline. Theauthenticatemiddleware extracts the JWT and verifies claims. Before any patient data or prescription is accessed, our authorization layer performs a relationship check (doctors: { some: { id: doctorId } }) to ensure unauthorized doctors cannot inspect other doctors' patients, preventing IDOR.3. The Two Core Engines:
- First, the Appointment Engine: We generate 8 hourly slots per day (9 AM to 5 PM). When a patient reserves a slot, we normalize the timestamp to the top of the hour. Instead of relying on vulnerable application-level
SELECT-then-INSERTchecks which fail under concurrent requests, we rely on a PostgreSQL partial unique index on(doctorId, slotStart) WHERE status <> 'cancelled'. Any collision immediately raises aP2002unique constraint violation from Postgres, which our controller maps to an HTTP 409.- Second, the Adherence Pipeline: When a prescription is created, we generate daily adherence records. A scheduled sweeper monitors transition windows (Morning, Afternoon, Evening) to detect unconfirmed doses, mark them
Missed, update the patient's adherence score, and dispatch Nodemailer email alerts.4. Real-Time Chat & Data Layer:
For live consultations, Socket.io orchestrates room-based messaging isolated bychatId. Messages are synchronously persisted to PostgreSQL and broadcasted to active room sockets.5. Engineering Learnings & Scale:
I validated the booking engine with a stress script firing 50 concurrent requests usingPromise.allβachieving exactly 1 success and 49 rejections. At 100x scale, our main bottleneck would be the in-process cron and single-instance WebSockets, which I would evolve by adding a Redis Pub/Sub adapter and BullMQ distributed worker queue."
3. End-to-End Workflow & User Journeys
[Doctor] ββRegisters PatientβββΊ [System sends Invitation Email with Token]
β
βΌ
[Patient] βββSets Password & Activates Account
β
βββΊ [Doctor writes Prescription (Dosage, Morning/Afternoon/Evening, Duration)]
β β
β βΌ
β [System generates daily MedicineAdherence entries]
β β
β βββΊ [Patient marks: Taken / Missed on Dashboard]
β βββΊ [node-cron sweeps at 8AM/1PM/8PM -> triggers email reminders]
β
βββΊ [Patient books 1-Hour Appointment Slot (e.g., 10:00 AM)]
β β
β βΌ
β [DB Partial Unique Index guarantees zero double-booking]
β
βββΊ [Real-Time Chat with Doctor via Socket.io Room Isolation]Detailed Lifecycle:
- Doctor Onboarding Flow: Doctor signs up $\rightarrow$ logs in $\rightarrow$ adds patient by email/phone $\rightarrow$ backend sends cryptographic activation link $\rightarrow$ patient sets password.
- Prescription Lifecycle: Doctor selects patient $\rightarrow$ searches Indian medicine database (autocomplete) $\rightarrow$ defines dosage & frequency $\rightarrow$ system writes
Prescriptionand childPrescribedMedicinerecords atomically. - Daily Adherence Tracking: Daily records appear on patient dashboard categorized into Morning, Afternoon, and Evening. Patient checks off medicine $\rightarrow$ status updates to
Taken. If unconfirmed past the window, background worker marks itMissed. - Appointment Reservation Flow: Patient views doctor's open slots $\rightarrow$ clicks slot $\rightarrow$ request hits database partial index $\rightarrow$ slot locked atomically $\rightarrow$ status set to
scheduled.
4. High-Level System Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER (Browser / SPA) β
β ββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββ β
β β Doctor Dashboard (React 19 + TailwindCSS) β β Patient Dashboard (React 19 + Radix) β β
β ββββββββββββββββββββββββ¬ββββββββββββββββββββ¬ββββ βββββ¬ββββββββββββββββββββ¬ββββββββββββββββ β
βββββββββββββββββββββββββββΌββββββββββββββββββββΌβββββββββββββΌββββββββββββββββββββΌβββββββββββββββββββ
β β β β
HTTPS / REST+JWT β WSS (WebSockets) β β HTTPS / REST+JWT β WSS (WebSockets)
βΌ β βΌ β
βββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββΌβββββββββββββββββββ
β API GATEWAY & APPLICATION SERVER (Node.js) β β β
β βΌ βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β JWT Authentication & RBAC Middleware (Role Verification) β β
β βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ β
β β β β
β βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββ β
β β Appointment Engine (Slot Normalizer) β β Prescription & Adherence Engine β β
β ββββββββββββββββββββββββ¬ββββββββββββββββββββββββ βββββββββββββββββββββ¬ββββββββββββββββββββ β
β β β β
β β ββββββββββββββββββββββββββββββββββββββββ β β
β β β Socket.io Real-Time Messaging Server ββββββ΄βββββββββββββββββββββββ
β β ββββββββββββββββββββ¬ββββββββββββββββββββ β
β β β β
β β ββββββββββββββββββββ΄ββββββββββββββββββββ β
β β β In-Process node-cron Worker Scheduler β β
β β ββββββββ¬ββββββββββββββββββββββββ¬ββββββββ β
βββββββββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ
β β β
β β Periodic Scan β Dispatch Overdue Alerts
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββ
β DATA & PERSISTENCE LAYER β β EXTERNAL INTEGRATIONS β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β β ββββββββββββββββββββββββββββββββ β
β β PostgreSQL Database (Prisma ORM) β β β β Nodemailer / SMTP Alerts β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β ββββββββββββββββββββββββββββββββ β
β β Partial Unique Index (Concurrency Protection): β β ββββββββββββββββββββββββββββββββββββββ
β β CREATE UNIQUE INDEX ON "Appointment" β β
β β (doctorId, slotStart) WHERE status <> 'cancelled' β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ5. Tech Stack & Justifications ("Why X over Y?")
| Component | Technology | Why Chosen? | Why Not Alternatives? |
|---|---|---|---|
| Backend Runtime | Node.js & Express | Asynchronous, non-blocking I/O is ideal for concurrent I/O-bound requests, WebSocket event loops, and scheduler triggers. | Python/Django: Slower raw I/O concurrency; multi-threaded WSGI introduces higher memory footprint per connection. |
| Database | PostgreSQL | Strict ACID compliance, relational integrity (Doctor $\leftrightarrow$ Patient $\leftrightarrow$ Prescription), and support for partial unique indexes. | MongoDB: Lacks flexible partial unique constraints across multi-tenant relationships; two-phase commits introduce high latency. |
| Data Access | Prisma ORM | Type-safe query building, declarative schema migrations, automated relation joining, and nested atomic writes. | TypeORM / Sequelize: Prone to impedance mismatch, weaker TypeScript type inference, and verbose boilerplate. |
| Real-Time Layer | Socket.io | Built-in room abstractions, automatic reconnection logic, and HTTP long-polling fallback. | Raw WebSockets: Requires building custom heartbeat, reconnect, and room orchestration from scratch. |
| Frontend Framework | React 19 & Vite 6 | Fast component rendering, concurrent transitions, instant Hot Module Replacement (HMR). | Next.js (SSR): Unnecessary SSR overhead for a dashboard behind an authentication wall. |
| Background Tasks | node-cron & Nodemailer | Zero-infrastructure operational overhead for periodic reminder cycles and status sweeps. | BullMQ / Celery (initial stage): Avoided introducing Redis infrastructure complexity for an MVP. |
6. Your Specific Contributions & Resume Bullet Points
Highlighted Resume Bullets:
- Engineered a concurrency-safe appointment reservation system using PostgreSQL partial unique indexes, eliminating double-booking under high concurrent loadβvalidated with a 50-request parallel load test resulting in exactly 1 reservation and 49 conflict rejections (
409 Conflict). - Architected an automated medication adherence pipeline with time-windowed state sweeps (8 AM, 1 PM, 8 PM), real-time WebSocket notifications, and automated email reminders, providing doctors with quantifiable adherence metrics.
- Implemented zero-trust Role-Based Access Control (RBAC) and doctor-patient relation checks across 25+ REST endpoints, safeguarding protected health records against Insecure Direct Object Reference (IDOR) exploits.
- Designed a real-time clinical consultation engine utilizing Socket.io with room isolation, synchronizing active doctor-patient messaging sessions with PostgreSQL persistence.
7. The 3 Core Technical Stories (STAR Method)
Story 1: Preventing Double-Booking Race Conditions Under High Concurrency
- Situation (S): In the appointment module, multiple patients could attempt to book the exact same 1-hour doctor slot at the same millisecond.
- Task (T): Ensure that under extreme parallel traffic, exactly one booking succeeds and all other conflicting requests fail gracefully without data corruption.
- Action (A):
- Rejected application-level checks (
findFirstfollowed bycreate) because of Time-Of-Check to Time-Of-Use (TOCTOU) race windows. - Rejected in-memory mutexes because they fail across multi-instance/clustered Node.js deployments.
- Created a PostgreSQL Partial Unique Index:
CREATE UNIQUE INDEX unique_active_doctor_slot ON "Appointment" ("doctorId", "slotStart") WHERE status <> 'cancelled'; - Built an error interceptor catching Prisma error code
P2002and returning HTTP409 Conflict. - Built an automated stress test (
scripts/concurrentBookingTest.js) launching 50 parallel requests viaPromise.all.
- Rejected application-level checks (
- Result (R): Exactly 1 request received HTTP 201 (
Created) and 49 received HTTP 409 (Conflict). Cancelled appointments immediately drop out of the partial index, making the slot instantly bookable again.
Story 2: Automated Medication Adherence & Cron Sweeper Pipeline
- Situation (S): Patients often forget afternoon or evening doses, and doctors lacked visibility into whether treatment plans were being followed.
- Task (T): Build a resilient, timezone-aware adherence tracking pipeline that automatically evaluates scheduled doses, notifies patients, and calculates adherence statistics.
- Action (A):
- Designed a deterministic state machine splitting daily prescription routines into Morning, Afternoon, and Evening buckets.
- Implemented
node-cronschedules running at 8:00 AM, 1:00 PM, and 8:00 PM with a grace period buffer. - Configured queries to fetch
Pendingdoses past their validity window, transition them toMissed, and emit WebSocket events + Nodemailer email alerts.
- Result (R): Doctors received live adherence scores (e.g., "85% on-time adherence over 14 days"), enabling informed clinical decisions during follow-up visits.
Story 3: Secure RBAC, Relationship Validation & Preventing IDOR
- Situation (S): Healthcare data is sensitive. If an API accepts
patientIdfrom request parameters without strict checks, a malicious user or another doctor could view records they do not own (IDOR vulnerability). - Task (T): Implement foolproof authorization ensuring users only ever access their own or their legitimately assigned records.
- Action (A):
- Built custom JWT authentication middleware decoding role (
doctorvspatient) and user ID. - On patient routes, enforced
req.user.id === requestedPatientId. - On doctor routes, added a relational query condition:
const isAssigned = await prisma.doctor.findFirst({ where: { id: req.user.id, patients: { some: { id: patientId } } } }); if (!isAssigned) return res.status(403).json({ error: "Access Denied: Patient not assigned to you" });
- Built custom JWT authentication middleware decoding role (
- Result (R): Completely eliminated IDOR vulnerabilities across all 25+ API endpoints with zero query overhead by leveraging indexed foreign key relations.
8. Concurrency & Thread Safety Deep Dive (Juspay / High-Bar Focus)
Why Node.js Single-Threaded Nature Does NOT Protect You from Concurrency Bugs:
Interview Question: "Node.js is single-threaded. Why did you have a race condition in the first place?"
The Exact Spoken Answer:
"Node.js runs single-threaded JavaScript execution on its event loop, but I/O operations are asynchronous and non-blocking.
When Request A callsawait prisma.appointment.findFirst(), Request A yields the thread to the event loop while waiting for the database response. In that exact millisecond window, Request B enters and also callsawait prisma.appointment.findFirst().
Both queries return 'Slot is Free' because neither has written to the database yet. Both then proceed to executeINSERT, resulting in a double-booking bug.
The concurrency problem exists at the database and I/O layer, not in JavaScript CPU memory. That is why concurrency control must be enforced at the database level using atomic constraints or locks."
Request A: [SELECT slot] ββ(waiting DB)βββββββββββΊ [Slot Free] βββΊ [INSERT slot] (Double Booking!)
β²
Request B: ββββββ[SELECT slot] βββ(waiting DB)βββΊ [Slot Free] βββΊ [INSERT slot] (Double Booking!)Deep Comparison of Concurrency Solutions:
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Mechanism β Pros β Cons / Why Rejected β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Application Check β Simple to write β Complete failure under concurrent traffic (TOCTOU bug) β
β In-Memory JS Mutex β No DB changes needed β Fails across multi-core clusters or multiple servers β
β DB Transactions (Read) β Standard SQL pattern β Requires Serializable isolation; high rollback rate β
β Redis Distributed Lock β Explicit lock TTL, fine-grained control β Extra infrastructure, Redis network round-trip overheadβ
β DB Partial Unique Index β Zero extra infra, zero network hops, guaranteed by DB WAL β Relies on Postgres feature (Optimal Choice for MVP) β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ9. Scaling, Bottlenecks & 10x/100x Evolution
Current System Limits (1x):
- Single Node Instance: ~500β1,000 HTTP RPS (I/O bound).
- Concurrent Sockets: ~5,000 active WebSockets per process.
- Database Connection Pool: Bound to 10β20 connections.
The 3 Bottlenecks at 10xβ100x Scale & The Solutions:
1. In-Process node-cron Bottleneck:
- Problem: If we scale horizontally to 5 Express instances behind an AWS ALB, the cron triggers 5 times simultaneously, sending duplicate emails and conflicting DB writes.
- Solution: Extract scheduled tasks into BullMQ with Redis. Use a dedicated background worker container with unique job IDs (
jobId: "reminder-patient-123-2026-09-08-0800"), guaranteeing exact-once execution.
2. Socket.io In-Memory Room Bottleneck:
- Problem: Doctor connected to Instance A cannot send a message to Patient connected to Instance B.
- Solution: Implement
@socket.io/redis-adapter(Redis Pub/Sub). Messages broadcast across all server instances automatically.
3. Database Connection Exhaustion & Table Growth:
- Problem: PostgreSQL runs out of connection sockets under burst traffic;
MedicineAdherencetable grows by millions of rows. - Solution:
- Add PgBouncer in transaction pooling mode.
- Implement PostgreSQL Table Partitioning on
MedicineAdherencepartitioned by month (RANGE (scheduledDate)). - Deploy Read Replicas for doctor analytics dashboards.
10. Engineering Trade-offs & What You Would Do Differently
1. Database Constraint vs Distributed Lock (Redis Redlock)
- Decision: Used PostgreSQL Partial Unique Index instead of Redis.
- Trade-off: We eliminated Redis infrastructure overhead and network hops, but tied our business constraint to PostgreSQL's indexing capabilities.
2. In-Process Cron vs Dedicated Worker Queue
- Decision: In-process
node-cronfor simplicity. - Trade-off: Quick to ship with zero extra services, but limits horizontal scaling until extracted to BullMQ.
3. Architecture Refactoring (What I would change if rebuilding):
- Add a Dedicated Service Layer: Currently, Express controllers combine input validation, business logic, and Prisma queries. A service layer (
AppointmentService,PrescriptionService) would allow pure unit testing without mocking HTTP request objects. - Standardize ID Types: Early schema design had Patients using integer IDs and Doctors using UUIDs. Standardizing everything to UUIDv7 would eliminate type conversions across the codebase.
- Database Full-Text Search for Medicines: Move the 32MB Indian medicine CSV into a PostgreSQL table with
tsvector/ GIN indexing rather than on-demand memory parsing.
11. Cross-Questioning Masterclass (15+ Exact Q&A Scripts)
Q1: "Why PostgreSQL over MongoDB?"
Answer: "Healthcare data is inherently relational with strict consistency requirements. Patients have multiple doctors, doctors issue prescriptions containing multi-item medicines, and appointments require strict atomicity. PostgreSQL gives us ACID transactions, referential foreign key integrity, and crucially, partial unique indexing (
WHERE status <> 'cancelled') which enforces slot uniqueness at the database engine level. In MongoDB, preventing double-booking requires complex multi-document transactions or distributed locks."
Q2: "What happens if a user cancels an appointment? How does the slot become available?"
Answer: "Because our index is a partial unique index defined with
WHERE status <> 'cancelled', updating an appointment's status tocancelledcauses that row to automatically drop out of the partial index. The(doctorId, slotStart)combination is immediately free to be indexed again by a newscheduledappointment without any manual cleanup."
Q3: "What happens if the database crashes or connection pool fills up?"
Answer: "Prisma throws connection timeout errors. Our centralized error middleware catches these and returns HTTP 503 (Service Unavailable) to prevent unhandled promise rejections from crashing the Node process. Health checks at
/signal the container orchestrator to divert traffic. To prevent pool exhaustion at scale, we use PgBouncer to multiplex hundreds of client requests into a lean pool of physical DB connections."
Q4: "How do you handle timezones for medication schedules?"
Answer: "All timestamps are normalized and stored in UTC in PostgreSQL. The adherence engine operates on discrete day boundaries (
YYYY-MM-DD) and relative time windows (morning,afternoon,evening). When presenting to the patient, the frontend converts UTC timestamps to the user's local browser timezone."
Q5: "How does your system prevent IDOR vulnerabilities?"
Answer: "We never trust client-provided IDs. On patient endpoints, we verify
req.user.id === requestedIdfrom the verified JWT payload. On doctor endpoints, we run a relational check:doctors: { some: { id: doctorId } }. If the patient is not explicitly assigned to that doctor, the API immediately halts with a 403 Forbidden."
Q6: "What is the time complexity of your critical database queries?"
Answer:
- Appointment Booking: $O(\log N)$ B-Tree index traversal on
(doctorId, slotStart).- Doctor Roster Fetch: $O(\log N + M)$ where $M$ is the count of assigned patients using the foreign key index.
- Daily Adherence Lookup: $O(K)$ where $K$ is the number of scheduled doses for the date (indexed on
patientIdandscheduledDate).- Chat Message Insert: $O(\log M)$ B-Tree insertion on
chatId+ $O(1)$ WebSocket broadcast.
Q7: "How did you test concurrency and race conditions?"
Answer: "I wrote an automated stress test script in Node.js using
Promise.allto fire 50 simultaneous HTTP POST requests targeting the exact same doctor, date, and 10:00 AM slot. The script asserted that exactly 1 request returned HTTP 201 (Created) and 49 requests returned HTTP 409 (Conflict)."
Q8: "How does real-time chat handle message ordering and delivery?"
Answer: "Each message is first persisted to PostgreSQL with an auto-generated timestamp and UUID. Only upon successful database commit does the server emit the message payload to the Socket.io room (
chatId). The client renders messages sorted by timestamp, guaranteeing consistent order."
Q9: "Why did you choose JWT over server-side session cookies?"
Answer: "JWTs keep the backend completely stateless, eliminating session lookups on Redis or database on every API request. This allows any backend instance behind a load balancer to verify the token independently. For security, tokens have a short 24-hour expiry."
Q10: "What happens if the cron job dies mid-execution?"
Answer: "Our cron queries search for
adherenceStatus: 'Pending'andreminderSent: false. Because state updates are committed per batch, a restarted worker simply picks up the remaining unprocessed rows on the next scan without duplicating sent emails. In production, BullMQ provides worker acknowledgments (ack) and automatic retry locks."
Q11: "How would you handle end-to-end encryption for chat messages?"
Answer: "We would implement client-side asymmetric encryption using the Web Crypto API. Each user generates a public/private keypair. The doctor's public key encrypts messages sent by the patient, and vice-versa. The server only stores encrypted ciphertext and cannot read message contents, satisfying HIPAA/GDPR standards."
Q12: "How would you implement pagination for medication history?"
Answer: "We use cursor-based pagination using the
scheduledDateandidas the cursor rather thanOFFSET/LIMIT. Cursor-based queries maintain $O(1)$ performance across deep pages and avoid shifting records when new adherence logs are created."
Q13: "What was the most difficult bug you encountered during development?"
Answer: "During early development, we noticed that after cancelling an appointment, the slot couldn't be rebooked because a standard unique constraint on
(doctorId, slotStart)blocked new inserts even for cancelled records. I researched database-level solutions and refactored the constraint into a PostgreSQL partial unique index filtered withWHERE status <> 'cancelled', which instantly solved the issue without requiring custom soft-delete table migrations."
Q14: "Why use Prisma Accelerate / Connection Poolers?"
Answer: "In serverless and containerized environments, every server instance spins up independent database connections, quickly hitting PostgreSQL's
max_connectionslimit. Prisma Accelerate / PgBouncer maintains an active pool of database connections and reuses them across incoming requests, reducing connection handshake latency."
Q15: "How do you ensure data integrity when a prescription with 5 medicines is created?"
Answer: "We use Prisma's nested write syntax (
prisma.prescription.create({ data: { medicines: { create: [...] } } })). Prisma wraps the entire operation in a single atomic database transaction (BEGIN ... COMMIT). If inserting the 4th medicine fails, the entire prescription creation rolls back, preventing orphaned records."
12. Provable Numbers & Metrics Sheet
Keep these exact numbers at your fingertips:
| Metric | Exact Value | Context / Proof |
|---|---|---|
| Concurrency Load Test | 50 simultaneous requests | Exactly 1 success (201), 49 conflict rejections (409) |
| Reminder Schedule | 8:00 AM, 1:00 PM, 8:00 PM | 3 daily node-cron transition sweeps |
| Daily Appointment Slots | 8 slots per doctor per day | Hourly slots from 9:00 AM to 5:00 PM |
| Medicine Dataset | 32 MB CSV dataset | Indian pharmaceutical dataset for prescription autocomplete |
| JWT Token Lifespan | 24 Hours | Configured in jsonwebtoken sign options |
| Database Schema | 10 Models | Relational models in prisma/schema.prisma |
| Protected Endpoints | 25+ Endpoints | Secured via JWT & RBAC middleware pipeline |
| Single-Instance Throughput | ~500β1,000 RPS | Node.js asynchronous I/O capacity |
[!TIP] Pro-Tip for Interviews: When asked a question, always lead with the architectural decision and reason (e.g., "We used a database-level partial unique index because application checks have race conditions"), then state the mechanism (Postgres partial index), and conclude with how you verified it (50 concurrent request stress test).