Case Study — Multi-tenant healthcare SaaS platform

MediPulse

A full-stack healthcare platform supporting appointments, live OPD queues, WebRTC consultations, hospital workflows, and AI-assisted triage — built with multi-tenant data boundaries and 7-role RBAC.

www.medipulse.live/
Screenshot of MediPulse
MERNFastAPIRedisKafkaSocket.IOWebRTCHuggingFaceRAG
01

Overview

MediPulse is a multi-tenant healthcare SaaS platform built to digitize end-to-end hospital workflows — from patient registration and appointment booking to live OPD queues, WebRTC video consultations, and AI-assisted triage. The platform supports 7 distinct roles across hospitals, clinics, patients, and administrators.

02

The Problem

Hospital digitization tools are often siloed — appointment software doesn't talk to queue management, and triage tools are disconnected from consultation history. The goal was a unified platform that handles the full patient journey, including real-time coordination between hospital staff, doctors, and patients.

03

My Contribution

Designed and implemented the full backend architecture including 125 REST APIs, 24 MongoDB data models, multi-tenant data isolation, RBAC using JWT and Google OAuth, real-time queues via Kafka and Socket.IO, WebRTC signaling for video consultations, and an AI triage pipeline integrating Gemini, Hugging Face Transformers, and a custom RAG system. Also built 34 React pages for the frontend.

04

Architecture

Multi-tenant Data Isolation

Each hospital's data is scoped by a tenantId field enforced at the application layer on every database query. RBAC middleware validates role membership before any cross-tenant operation.

Real-time OPD Queue

Kafka topics per OPD handle patient token generation and queue advancement. Socket.IO rooms broadcast queue state to waiting patients and reception staff in real time.

AI Triage Pipeline

Patient symptoms are preprocessed and classified using Hugging Face models. A custom RAG pipeline retrieves relevant medical context from a vector store. Gemini generates structured triage recommendations shown to the attending physician.

WebRTC Consultation

Signaling is handled via Socket.IO. STUN/TURN configuration manages NAT traversal. Sessions are time-bounded and tied to appointment records.

Financial Integrity

Virtual wallet operations use atomic MongoDB transactions. Distributed locks (Redis) prevent duplicate refund processing. Idempotency keys ensure at-most-once semantics for payment events.

05

Engineering Decisions & Tradeoffs

Kafka over direct Socket.IO for queue events

Rationale: Queue state changes need durability and replay capability — if a Socket.IO server restarts, Kafka retains the event log and consumers can recover.

Tradeoff: Adds operational complexity; justified for a healthcare context where queue ordering must be reliable.

MongoDB for primary storage with 24 models

Rationale: Flexible document schema suited the varied data shapes across hospital types (clinics vs. large hospitals have different workflow structures).

Tradeoff: Requires careful application-level enforcement of consistency that a relational DB would handle natively.

Redis distributed locks for wallet operations

Rationale: Prevents race conditions in concurrent refund and payment scenarios without requiring a separate queue per operation.

Tradeoff: Lock TTL must be tuned carefully; too short risks duplicate operations, too long blocks legitimate concurrent requests.

06

Challenges & Solutions

Challenge

Maintaining queue consistency across server restarts

Solution

Kafka consumer groups with explicit offset commits ensure each queue event is processed exactly once. Queue state is reconstructed from Kafka on startup.

Challenge

Cross-role access in a 7-role RBAC system

Solution

Role hierarchy is defined in a typed constants file. Middleware checks both role membership and resource ownership (tenantId scope) before forwarding requests.

Challenge

AI triage latency in a real-time context

Solution

Triage runs asynchronously — the initial consultation page loads immediately while triage results stream in. Heavy model inference runs on FastAPI workers with async processing.

07

Evidence & Results

  • ›125 REST APIs serving 7 user roles across a unified hospital workflow
  • ›Real-time OPD queue management with Kafka-backed durability
  • ›WebRTC video consultations integrated into the appointment flow
  • ›AI triage recommendations available before the physician enters the consultation
  • ›Atomic wallet operations with idempotent refund processing
All Projects View Repository Live Demo