Delivered remotely for a business based in Riyadh, Saudi Arabia. Names withheld by agreement.
Project Overview
Virtual care only works when a patient moving from symptom intake to a live physician conversation experiences zero technical friction. Many early telehealth rollouts stitched together generic consumer video links with separate booking forms, leaving doctors without patient history during the call and forcing patients to rejoin broken rooms whenever cellular reception fluctuated.
Working around regional clinical delivery requirements in Riyadh, we built an end-to-end online doctor consultation platform spanning Flutter mobile applications on iOS and Android, a browser-based physician console, Node.js real-time services, and WebRTC media infrastructure. Patients select specialties, complete structured bilingual triage, wait in a live virtual queue, conduct encrypted video consultations, and receive verifiable digital prescriptions inside a single continuous experience.
Telemedicine Friction Points
Building reliable remote consultations across heterogeneous home broadband and cellular networks surfaced four recurring engineering obstacles:
- Carrier NAT and firewall drops: Direct peer-to-peer WebRTC handshakes routinely failed behind restrictive mobile carrier gateways, causing black-screen calls right as clinicians joined.
- Volatile bandwidth on mobile devices: Fixed-resolution video streams froze completely when patients moved between Wi-Fi and LTE, interrupting clinical assessments.
- Disjointed waiting room state: Naive database polling left patients unsure of their queue position and failed to reassign rooms promptly when a specialist ran long or went offline.
- Split charting and video windows: Physicians toggling between standalone video apps and separate EHR tabs lost eye contact and missed uploaded lab attachments during short consult windows.
Architectural Strategy
We decoupled the control and signaling plane from the real-time media plane. Node.js and TypeScript manage authenticated consultation lifecycles, Redis-backed waiting room queues, and Socket.IO WebRTC signaling, while dedicated Selective Forwarding Unit (SFU) media servers handle DTLS-SRTP media packets and adaptive simulcast streams.
Inside Flutter, native platform channels manage camera permissions, CallKit/ConnectionService incoming-call screens, and audio routing (Bluetooth headsets vs speakerphone) so virtual visits behave with the reliability of native telephony rather than fragile embedded webviews.
Core Capabilities
- Bilingual Smart Intake & Triage: Captures chief complaints, vital measurements, allergies, and encrypted lab photo attachments in full Arabic RTL and English LTR layouts before the call begins.
- Live Virtual Waiting Room: Uses Redis-backed priority queues to display real-time queue placement, accommodate urgent triage escalations, and notify patients via push alerts moments before entry.
- Adaptive WebRTC Video & Audio Fallback: Employs simulcast video layers and TURN/TCP fallback relays so consultations hold steady across fluctuating mobile data connections.
- Unified Clinician Charting Workspace: Presents intake history, past visit timelines, live video, structured SOAP note templates, and diagnostic ordering side by side.
- Signed E-Prescriptions & Follow-Up Orders: Generates tamper-evident digital prescriptions and lab referrals routed directly to patient wallets and partner pharmacy verification endpoints.
Technical Architecture
Patients authenticate via mobile OTP and initiate either an on-demand triage request or a scheduled specialist slot. Node.js places the encounter in a Redis queue and allocates a scoped room token. When the clinician accepts the patient, Socket.IO orchestrates SDP offers and ICE negotiation toward the nearest SFU node, while consultation state transitions and clinical notes persist durably to PostgreSQL.
Flow: Flutter / Web Client → Node.js API & Socket.IO Signaling → Redis Waiting Queue → WebRTC SFU + TURN Media Plane → Clinician SOAP & E-Prescription Commit → PostgreSQL + Signed Artifact Store
Keeping media forwarding completely outside Node.js ensures signaling servers stay lean and horizontally scalable across multiple cluster workers synchronized via Redis Pub/Sub.
Technology Stack
| Category | Technology detail |
|---|---|
| Patient Mobile Apps | Flutter codebase delivering native iOS and Android experiences with full RTL/LTR support |
| Signaling & API Tier | Node.js with TypeScript orchestrating appointments, triage states, and consultation lifecycles |
| Real-Time Media Plane | WebRTC SFU media routers with TURN/STUN relays supporting adaptive bitrate video |
| WebSocket Signaling | Socket.IO over Redis Pub/Sub coordinating room joins, ICE candidates, and queue events |
| Clinical & Billing Store | PostgreSQL persisting encrypted patient intake forms, SOAP notes, and e-prescriptions |
| Queue & Presence Engine | Redis sorted sets managing live triage queues, doctor availability, and session heartbeats |
| Clinician Web Console | Browser-based video consultation workspace with side-by-side patient chart and prescribing |
| Artifact Storage | Encrypted object storage holding lab uploads, diagnostic images, and signed PDF prescriptions |
| Push & SMS Notifications | APNs, FCM, and regional SMS gateways delivering queue-turn alerts and OTP verification |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Peer-to-peer WebRTC breaks on multi-party interpreter calls and strict NATs | Standardized on an SFU + TURN relay topology; adds modest server bandwidth overhead in exchange for predictable traversal and smooth multi-participant joins. |
| Mid-call network switches between Wi-Fi and LTE drop standard WebSockets | Implemented Socket.IO heartbeat recovery paired with automated WebRTC ICE restarts in Flutter, preserving room identity without forcing the patient to re-enter the queue. |
| Clinicians need instant queue updates without hammering PostgreSQL | Modeled active waiting rooms and doctor presence inside Redis sorted sets, syncing only durable state transitions (entered, started, completed) back to PostgreSQL. |
| Embedded HTML5 WebViews on mobile suffer inconsistent microphone and Bluetooth routing | Built native Flutter WebRTC bindings integrated with iOS CallKit and Android audio focus APIs, increasing native platform testing scope while eliminating audio glitches. |
Clinical Privacy & Session Integrity
Virtual healthcare consultations carry sensitive personal health disclosures, identity documents, and clinical imagery that demand regional data residency and end-to-end transport protection. All consultation signaling runs over TLS, and WebRTC audio/video streams use mandatory DTLS-SRTP encryption so media packets remain protected across public wireless networks.
Room join tokens are short-lived, bound strictly to the authenticated patient, assigned physician, and an optionally invited interpreter or caregiver. Uploaded laboratory photos and prescription PDFs never reside in public object buckets; clients retrieve them exclusively via audited, time-limited pre-signed URLs after backend encounter ownership verification. Complete clinical audit logs track every chart view, consultation join/leave timestamp, and prescription signature inside PostgreSQL.
Network Resilience & Media Scale
Telemedicine demand surges sharply during evening hours and seasonal respiratory waves, when hundreds of concurrent consultations open simultaneously across mobile devices with uneven uplink speeds. To keep video sessions clear under congestion, the WebRTC SFU subscribes publishers to multiple simulcast encodings and dynamically downscales incoming video tiers for bandwidth-constrained participants while prioritizing audio packet continuity.
On the orchestration layer, stateless Node.js signaling instances scale horizontally behind sticky-free load balancing using Redis Pub/Sub adapters, allowing any node to relay room events reliably. Automated stale-session sweepers detect orphaned rooms from dead batteries or dropped connections and gracefully pause billing timers until the patient reconnects within the grace window.
Operational Outcomes
Unifying mobile triage, resilient WebRTC streaming, and structured digital prescribing inside one architecture transformed virtual care delivery for both patients and clinicians:
- Dependable mobile consultation quality: SFU routing and automated ICE recovery keep doctor-patient visits connected across everyday cellular handoffs and low-bandwidth connections.
- Streamlined specialist throughput: Real-time virtual waiting rooms and pre-populated bilingual intake summaries allow clinicians to focus consultation minutes on diagnosis rather than manual data gathering.
- Continuous care handoffs: Integrated SOAP charting, attachment viewing, and verifiable e-prescriptions close the loop between remote assessment and pharmacy fulfillment.
- Unified cross-platform maintenance: Sharing business rules across a single Flutter mobile codebase and TypeScript backend accelerates clinical feature releases across iOS, Android, and web.