LearnSystem design

Real-time speech-recognition API

Design a multi-language streaming transcription service with partial and final transcripts and a configurable latency/accuracy trade-off.

ML engineering8 parts

Contents

Constraints

  • 50k concurrent streams
  • partial results every ~300 ms
  • finals within ~1 s
  • 50 languages

What to cover

Sketch your own design first. A complete answer has these parts; the notes say what each should settle.

  1. RequirementsDesign a multi-language streaming transcription service with partial and final transcripts and a configurable latency/accuracy trade-off.
  2. Estimates50k concurrent streams; partial results every ~300 ms; finals within ~1 s; 50 languages.
  3. API
  4. Data model
  5. ArchitectureWebSocket ingestion; voice-activity detection; streaming encoder (conformer with chunked attention) plus transducer or CTC decoding with beam search.; Optional LM fusion, custom vocabulary, punctuation and diarisation post-processing.; GPU batching across streams; language ID; self-supervised pre-training for low-resource languages.; Model registry per language.
  6. Deep dives
  7. Trade-offslook-ahead vs latency (a max-delay knob); model size vs cost per audio hour; partial-result stability (flicker) vs speed; on-prem vs cloud deployment.
  8. EvaluationOffline: WER by language, accent and domain, on held-out sets free of benchmark contamination (public test sets may have leaked into training data).; Latency percentiles and partial-to-final edit rate.; Online: customer error reports, cost per hour.

Reference design

One way to answer it, part by part. Open a part once you have your own version of it.

Requirements

Functional: clients stream audio over a WebSocket and receive partial transcripts (fast, may change) and final transcripts (stable) with word timings and confidences; 50 languages plus automatic language identification; optional diarisation, punctuation, number formatting and custom vocabulary; a configurable latency/accuracy knob (max_delay).

Non-functional: 50k concurrent streams at peak; partials every ~300 ms; finals within ~1 s of the word being spoken at the default setting; regional processing (UK/EU/US) and an on-prem container option; availability ≥ 99.9%, with graceful reconnection.

Quality: WER competitive per language, robust across accents and domains (call centres, media, meetings), strong on names and numbers.

Assumptions to confirm: input formats (16 kHz PCM, 8 kHz telephony, Opus); a long tail of low-resource languages with little labelled data; enterprise customers need custom vocabulary and data not used for training without consent; billing per audio second.

Estimates

Stack · 6 layersLatency budget to a stable partial

  1. Audio chunk 160 ms

  2. Right-context lookahead ~320 ms

  3. Queueing to the next batch tick ≤ 100 ms

  4. Compute ~30 ms

  5. Network ~50 ms

  6. ≈ 660 ms to a stable partial; finals at endpoint or when max_delay (e.g. 1 s) expires

The default latency budget adds the audio chunk, right-context lookahead, queueing, compute and network to reach a stable partial in about 660 ms, with finals emitted at endpoint or when max_delay expires.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.

CalculatorCost per audio hour at 50k streams

Fleet cost = GPUs × Cost per GPU

Audio-hours per hour = Concurrent streams × 1000 × Average utilisation ÷ 100

Cost per audio hour (full) = GPUs × Cost per GPU ÷ (Concurrent streams × 1000)

Cost per audio hour (avg) = GPUs × Cost per GPU ÷ (Concurrent streams × 1000 × Average utilisation ÷ 100)

Worked cases
CaseConcurrent streams (k)GPUs (GPUs)Cost per GPU ($/h)Average utilisation (%)Fleet costAudio-hours per hourCost per audio hour (full)Cost per audio hour (avg)
Full load502202100440 $/h50,000 audio-h/h0.009 $/audio hour0.009 $/audio hour
~40% average utilisation50220240440 $/h20,000 audio-h/h0.009 $/audio hour0.022 $/audio hour
At 220 GPUs and ~$2/h each, the fleet costs ~$440/h, about $0.009 per audio hour at full load and ~$0.02 at 40% average utilisation.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
  • Streams: 50k concurrent. Partials every 0.3 s → 50k / 0.3 ≈ 167k partial messages/s.
  • Ingress: 16 kHz × 16-bit = 32 KB/s per stream → 1.6 GB/s (~13 Gbps) if all raw PCM; Opus at ~32 kbps cuts that ~8×.
  • GPU fleet: a mid-size chunked conformer-transducer serves ~300 streams per GPU with batching → 50k / 300 ≈ 170 GPUs, ~220 with headroom, split by region and language group.
  • Per-stream state: cached left context, e.g. 18 layers × 64 frames × 512 dims × 2 (K and V) × 2 bytes ≈ 2.4 MB → 300 streams ≈ 0.7 GB per GPU — small next to model weights.
  • Cost: 220 GPUs × ~$2/h ≈ $440/h. At full load that is 50k audio-hours per hour ≈ $0.009 per audio hour; at ~40% average utilisation ≈ $0.02 per audio hour of compute, far below typical list prices.
  • Latency budget (default): audio chunk 160 ms + right-context lookahead ~320 ms + queueing to the next batch tick ≤ 100 ms + compute ~30 ms + network ~50 ms ≈ 660 ms to a stable partial; finals are emitted at endpoint or when max_delay (e.g. 1 s) expires.
  • 50 languages: if each had its own model, many would be under-utilised; a few multilingual models plus dedicated models for the top ~10 languages keeps pools large enough to batch well.

API

WS /v1/realtime
  client → {"message": "StartSession", "audio_format": {"type": "raw", "encoding": "pcm_s16le",
            "sample_rate": 16000}, "config": {"language": "en" | "auto", "max_delay": 1.0,
            "enable_partials": true, "diarisation": "speaker", "domain": "finance",
            "additional_vocab": [{"content": "Vodafone", "sounds_like": ["voda phone"]}]}}
  client → binary audio frames … {"message": "EndOfAudio", "last_seq_no": 812}
  server → {"message": "SessionStarted", "id"}
           {"message": "PartialTranscript", "results": [{word, start, end, confidence}]}
           {"message": "FinalTranscript", "results": [...], "speaker": "S1"}
           {"message": "EndOfUtterance"} · {"message": "Warning"|"Error", "reason"}
POST /v1/jobs  (batch file transcription, same config)

Sequence numbers on audio frames let a reconnecting client resume without losing or duplicating audio; usage is metered per audio second.

Data model

  • Session: id, tenant, region, config, language (requested and detected), model version, worker id, start/end, audio seconds, finals count, error codes.
  • TranscriptSegment (only if the tenant opts in to storage): session, start, end, words with timings and confidences, speaker.
  • Vocabulary: tenant, terms, sounds-like hints, compiled biasing artefact per model version.
  • ModelRegistry: language or language group → model versions, size tier (fast | accurate), WER per evaluation set, latency profile, status (canary | live).
  • UsageRecord: tenant, session, audio seconds, model tier, region → billing.
  • EvalSet: language, accent, domain, audio, verified reference transcripts, provenance (to keep held-out data out of training).

Architecture

Flow · 4 stepsHow audio flows through the real-time speech-recognition API

How audio flows through the real-time speech-recognition APIA client streams audio to a regional gateway, then a session manager, pre-processing and language ID, a stream scheduler and a GPU worker. The worker batches chunks on a ~100 ms tick, the partial stabiliser emits only the stable prefix, and post-processing returns results over the same WebSocket.Clientstreams audio over WebSocketRegional gatewayTLS, auth, sticky session routingSession managerconfig, vocabulary compilation,meteringPre-processingdecode/resample, VADLanguage IDfirst ~2–3 s when language = autoStream schedulerassigns GPU worker by languagegroupGPU worker~100 ms tick; batched forwardPartial stabiliseremit only the stable prefixPost-processingpunctuation, inverse textnormalisationWS1234IngressComputeOutput
  1. Ingress Client streams audio over WebSocket; the gateway applies TLS, auth and sticky routing; the session manager handles config, vocabulary and metering.
  2. Pre-process and identify Pre-processing decodes and resamples and runs VAD; language ID runs on the first ~2–3 s when language = auto.
  3. Schedule and batch The scheduler assigns the stream to a GPU worker for its language group and size tier; the worker batches chunks every ~100 ms tick.
  4. Stabilise and return The partial stabiliser emits only the stable prefix; post-processing adds punctuation and inverse text normalisation; results return over the same WebSocket.

Audio enters over a WebSocket, passes through gateway, session, pre-processing, language-ID, scheduling and GPU batching, then returns as stabilised and post-processed results.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1IngressClient streams audio over WebSocket; the gateway applies TLS, auth and sticky routing; the session manager handles config, vocabulary and metering.
2Pre-process and identifyPre-processing decodes and resamples and runs VAD; language ID runs on the first ~2–3 s when language = auto.
3Schedule and batchThe scheduler assigns the stream to a GPU worker for its language group and size tier; the worker batches chunks every ~100 ms tick.
4Stabilise and returnThe partial stabiliser emits only the stable prefix; post-processing adds punctuation and inverse text normalisation; results return over the same WebSocket.

Source: This page's text

Boxes
BoxGroupDetail
ClientIngressstreams audio over WebSocket
Regional gatewayIngressTLS, auth, sticky session routing
Session managerIngressconfig, vocabulary compilation, metering
Pre-processingComputedecode/resample, VAD
Language IDComputefirst ~2–3 s when language = auto
Stream schedulerComputeassigns GPU worker by language group
GPU workerCompute~100 ms tick; batched forward
Partial stabiliserOutputemit only the stable prefix
Post-processingOutputpunctuation, inverse text normalisation

Source: This page's text

Client ─WS─► Regional gateway (TLS, auth, sticky session routing)
  ─► Session manager: config, vocabulary compilation, metering
  ─► Pre-processing: decode/resample, VAD (skip silence, endpoint hints)
  ─► Language ID on the first ~2–3 s when language = auto
  ─► Stream scheduler: assigns the stream to a GPU worker for that language
     group and size tier; balances by active streams
  ─► GPU worker: every ~100 ms tick, batch new chunks from all its streams
        streaming encoder (chunked-attention conformer, cached left context)
        + transducer/CTC beam search with contextual biasing (custom vocab)
        + optional external LM fusion per domain
  ─► Partial stabiliser (emit only the stable prefix; tail may change)
  ─► Post-processing: punctuation, inverse text normalisation, diarisation
  ─► results back over the same WebSocket
Model registry per language ─► canary deploys per pool
Self-supervised pre-training on unlabelled audio ─► fine-tune per language,
   critical for low-resource languages

Deep dives

Flow · 4 stepsHow partial transcripts are stabilised

How partial transcripts are stabilisedA client streams audio over a WebSocket to a GPU worker, where the streaming encoder and transducer/CTC beam search produce partial results. The partial stabiliser commits only the stable prefix and lets the tail change, then sends the PartialTranscript back over the same WebSocket.Clientstreams audio over WebSocketStreaming encoderchunked-attention conformer,cached left contextTransducer / CTC decoderbeam search with contextualbiasingPartial stabiliseremit only the stable prefixPartialTranscriptfast, may changeaudio frameschunkspartial resultsstable prefix1234InputComputeOutput
  1. Audio arrives The client streams audio frames over the WebSocket to the GPU worker.
  2. Encode and decode The chunked-attention conformer encodes with cached left context, and the transducer/CTC decoder runs beam search.
  3. Stabilise the prefix The stabiliser commits only the prefix stable across consecutive decodes; the tail may still change.
  4. Emit the partial A PartialTranscript is sent back over the same WebSocket every ~300 ms; stabilising adds a few hundred ms.

Partials are emitted every ~300 ms, but only the prefix stable across consecutive decodes is committed; the tail may still change.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Audio arrivesThe client streams audio frames over the WebSocket to the GPU worker.
2Encode and decodeThe chunked-attention conformer encodes with cached left context, and the transducer/CTC decoder runs beam search.
3Stabilise the prefixThe stabiliser commits only the prefix stable across consecutive decodes; the tail may still change.
4Emit the partialA PartialTranscript is sent back over the same WebSocket every ~300 ms; stabilising adds a few hundred ms.

Source: This page's text

Boxes
BoxGroupDetail
ClientInputstreams audio over WebSocket
Streaming encoderComputechunked-attention conformer, cached left context
Transducer / CTC decoderComputebeam search with contextual biasing
Partial stabiliserComputeemit only the stable prefix
PartialTranscriptOutputfast, may change

Source: This page's text

The max-delay knob. Streaming accuracy depends on how much future audio (right context) the model sees before committing a word. max_delay bounds that: small values (0.7 s) give fast finals with higher WER; larger values (2–4 s) let the model use more context and endpointing patience, lowering WER. Implement it as both the encoder’s lookahead and a forced-finalisation timer, and publish WER vs delay curves per language so customers can choose.

Partial stability. Partials that flicker (“their” → “there” → “they’re”) annoy captions users and break downstream agents. Commit only a prefix that has been stable across consecutive decodes; measure the partial-to-final edit rate and trade it against partial latency.

Batching streams on GPUs. Streams arrive asynchronously, but GPUs need batches. A fixed tick (~100 ms) collects whatever chunks are ready, runs one batched forward, and returns results; the tick length trades latency against utilisation. Keep per-stream caches resident on the worker, which is why sessions are sticky; on worker failure, the client reconnects and the new worker rebuilds context from a short replay buffer.

Trade-offs

  • Look-ahead vs latency (max-delay knob): more right context, better accuracy, slower finals; per-use-case defaults (captions vs analytics) exposed to customers.
  • Model size vs cost per audio hour: a larger model cuts WER but serves fewer streams per GPU, multiplying cost; offer fast and accurate tiers and price them accordingly.
  • Partial-result stability (flicker) vs speed: stabilising partials adds a few hundred ms; let clients opt out if they only need finals.
  • On-prem vs cloud deployment: on-prem satisfies data-sovereignty customers but loses fleet-wide batching efficiency and slows updates; ship the same containers with a smaller model tier and a clear update cadence.
  • Multilingual vs per-language models: shared models help low-resource languages through transfer and pool capacity; dedicated models win on top languages where data is plentiful.

Evaluation

  • Offline: WER by language, accent and domain on held-out sets with verified references, checked free of benchmark contamination — public test sets may have leaked into training data, so maintain private, recently collected sets; entity accuracy (names, numbers); language-ID accuracy including code-switching.
  • Latency: partial and final latency percentiles (time from the end of a word in the audio to its emission), measured with synthetic clients per region; partial-to-final edit rate.
  • Load and resilience: 50k-stream load tests, worker-kill tests, reconnect correctness.
  • Online: customer error reports and correction rates, cost per audio hour per tier, GPU utilisation, sessions dropped; per-language WER on consented sampled audio after model releases, with canary comparison before full rollout.

What a strong design shows

  • Builds on streaming-specific models (chunked attention, cached context, transducer decoding) and explains the max-delay latency/accuracy knob.
  • Sizes the fleet and cost per audio hour from streams per GPU and batching ticks.
  • Handles partial stability, sticky sessions and reconnection, not only model accuracy.
  • Serves 50 languages sensibly with multilingual models, language ID and self-supervised pre-training for low-resource languages.
  • Evaluates WER by slice on contamination-free private sets alongside latency percentiles and flicker.

Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.