JioDoctor — Voice-First AI Triage with Live Doctor Handover
JioHealth · Backend architecture & delivery ownershipThe problem
A patient should be able to describe symptoms out loud in the app and be triaged conversationally — speech in, speech out, in real time, over a mobile network that drops. And when the AI reaches the limit of what it should decide, the patient needs to reach a real doctor without repeating themselves. That second half is the hard part: the escalation creates an appointment and pages a clinician, so it can never fire twice because a phone retried a request.
What I did
Built the stateful edge service that owns the conversation while the model layer stays stateless. A WebSocket protocol with numeric message codes and a handler registry keeps the client contract explicit and versionable; auth is validated during the HTTP handshake before the socket is ever accepted. Speech synthesis streams back as Opus chunks so the patient hears a reply forming rather than waiting for a complete file, with a buffered fallback for weaker clients.
State is deliberately two-tier: Redis holds liveness, Postgres holds truth. A sliding-window TTL manager batches expiry refreshes into a periodic pipelined flush instead of writing on every message, and a reconciliation job closes exactly the sessions Redis has forgotten. Server-driven ping/pong detects dead sockets; reconnects resume a conversation rather than restarting it; undelivered critical messages are replayed; and a Redis-backed queue routes messages across pods so a horizontally scaled deployment can still reach a socket pinned elsewhere.
The doctor handover is guarded by a Redis SET NX lock keyed to the
session, so duplicate requests from client retries or reconnects cannot produce two
clinician pages or two appointments — with a deliberate fail-open policy and lock release
on failure so a genuine retry still works. Failures in the speech or model chain degrade
into product behaviour rather than an error state: the conversation preserves what it has
and offers the human doctor instead of a dead end. Latency-sensitive extras — pre-consult
note generation, record upload, appointment cancellation — run off the critical path.
Outcome
A patient speaks to the app, gets triaged, and is handed to a clinician who already has an AI-generated pre-consult note in hand. Dropped connections and device switches resume instead of restarting, and the duplicate-escalation class of bug is closed by design rather than by monitoring.