Dograh

WebRTC vs WebSocket: Which Fits Real-Time Voice Agents

WebRTC vs WebSocket: Which Fits Real-Time Voice Agents
ComparisonDecember 1, 2026·14 min read

WebRTC vs WebSocket: Which Fits Real-Time Voice Agents

Pritesh Kumar
Pritesh Kumar·Co-founder, Dograh AI

Building Dograh, the open-source alternative to Vapi. OSS and Voice AI. Exit founder and YC alum.

For a voice agent, WebRTC carries browser microphone audio and WebSocket carries phone audio streams, events and tool calls. WebRTC is a browser stack for live media between peers, while WebSocket is one persistent two-way channel to a server. Dograh, the open-source AI voice agent platform, runs both, and you can self-host it or run it on Dograh Cloud.

Key Takeaways

  • Transport usually adds tens of milliseconds, while speech and model steps add hundreds.
  • Open one WebRTC connection per session, since setup takes about 80 milliseconds.
  • Whoever runs the TURN relay decides where browser audio travels on fallback.

Teams often treat WebRTC as the automatic choice for real-time audio, yet for an AI voice agent the measured gap is usually small. We compare the two on latency, setup cost, relays and workload, give a benchmark plan, then show how Dograh splits the work between them.

WebRTC and WebSocket side by side

WebSocket is a persistent, full-duplex message channel between a client and a server, while WebRTC is a set of browser APIs and real-time protocols for audio, video and data between peers. The comparison, and most of the operating cost, follows from that split.

CriterionWebRTCWebSocket
Primary purposeReal-time audio, video and data between browsers or devicesPersistent two-way messaging between a client and a server
Connection modelPeer connection set up through signaling, ICE and DTLSOne HTTP upgrade into a persistent TCP connection
Transport layerUDP for media, SCTP for data channelsTCP, reliable and ordered
Native media supportYes, audio and video with codecs and jitter bufferingNo, audio is sent as encoded frames in binary messages
Browser supportAll major browsersAll major browsers
Standards statusW3C RecommendationIETF RFC 6455
Server infrastructureSignaling server plus STUN and TURN relaysAny backend that accepts HTTP upgrades

Read the infrastructure row before the media row. WebSocket needs only an HTTP upgrade on a backend you already run, while WebRTC adds a signaling server plus STUN and TURN servers. Whoever runs those relays decides where audio travels when a direct path fails, and for an AI voice agent that ownership question often matters more than the protocol name.

Standards age explains part of the build difference, though it says nothing about speed. The WebSocket protocol was published as IETF RFC 6455 in December 2011 after its drafts moved through the IETF HyBi working group, as the Edgepedia protocol reference sets out. WebRTC took a longer route through browser communications work and is now a W3C Recommendation.

On a voice agent the split is concrete. WebSocket is a plain application transport for text, events and control messages. WebRTC brings codec handling, jitter buffering and session statistics with the stack, which makes it the native fit for live microphone audio in a browser. Native media support and lower latency are separate claims, though. Signaling, ICE and DTLS all sit in front of the first audio packet, and a phone call arriving from a carrier may never need a browser peer connection at all. Encryption is another layer again, and E2EE versus transport encryption explained covers what each kind protects and what it leaves exposed.

What the latency numbers actually measure

Each published latency figure measures one stack on one network with one workload. A lower WebRTC number is a result under those conditions and tells you little about the protocol in general, so read the conditions before you quote the number.

TestWebRTCWebSocketConditions
Voice round trip with a chat model APIAbout 150 msAbout 200 msOrange Pi 3B edge device, 50 Mbps Ethernet
Network and CPU use, same studyLower, with near-zero jitterHigher bandwidth and CPU loadSame device and network
Average round-trip time, 100 pings1.54 ms (reliable mode 1.61 ms)4.1 msChrome on a local network

The first row is the one people quote. A 2025 comparative study of voice over WebRTC and WebSocket ran two-way voice with the ChatGPT API on an Orange Pi 3B over 50 Mbps Ethernet and measured about 150 ms for WebRTC against about 200 ms for WebSocket. That 50 ms gap is a quarter of the WebSocket figure. The same study recorded lower network and CPU use for WebRTC with near-zero jitter, while WebSocket used more bandwidth and loaded the CPU harder.

The ping row comes from a different kind of test. A Fraunhofer Institute protocol comparison averaged 100 pings in Chrome over a local network at 1.54 ms for WebRTC and 1.61 ms for reliable WebRTC, against 4.1 ms for WebSocket. The gap is real and tiny, measured with no carrier or codec in the path, so it describes transport round-trip time and says nothing about a spoken turn.

Production delay moves with ICE negotiation, NAT traversal, whether a TURN relay sits in the path, the distance to the server and the browser itself. A few tens of milliseconds of transport gap does matter for turn-taking, yet it is small next to speech recognition, the language model and speech synthesis. Treat any published gap as a direction to test on your own path. Interactive video runs on a different clock again, because delay shows up in how a person reviews the live stream, and the human-in-the-loop video monitoring guide covers that live video streaming chat workflow.

Dograh

Open Source Alternative to Vapi / Retell

Self-hosted voice agent platform — no per-minute fees

dograh-hq/dograh

Star on GitHub

Connection setup cost for short messages

Opening a WebRTC data channel took about 80 ms before the first byte moved in one browser benchmark, while a WebSocket opened in about 3 ms. For short messages that setup cost decides the design more than steady-state latency does.

MetricWebSocketWebRTC data channel
Connection setup, p502.2 to 2.9 ms79.6 to 83.4 ms
Time to first byte, p502.4 to 3.3 ms79.7 to 83.6 ms
Time to first byte, p993.3 to 6.3 ms90.6 to 145 ms

Those figures come from the ws-webrtc browser benchmark, which ran Chrome against a Go echo server on one machine, with cold connections and 512-byte messages. The cause is structural. A WebSocket is one HTTP upgrade, while a WebRTC data channel has to gather ICE candidates, complete the DTLS key exchange and bring up an SCTP association before any application data moves. That work is fine once per session and painful once per event.

Two panels of the same browser call between a caller on a laptop and an AI voice agent over three turns. On the left, a connection per utterance, a setup stopwatch sits before every turn, crossed out because every turn repeats the full negotiation. On the right, one peer connection per session, setup happens once before turn 1 and turns 2 and 3 run on the same channel. A line at the bottom says that for short messages the setup cost decides the design more than steady-state latency does.
A design that reconnects for each reply makes the caller sit through the handshake on every answer, and that wait shows up worst in the slow tail. Reuse one channel for the whole conversation.

So open one peer connection per session and keep it alive across turns, since a voice conversation can run dozens of exchanges and every new connection repeats the full negotiation inside the caller's wait. Send small JSON, presence updates and tool-call notices over a WebSocket, or over the data channel you already have if that keeps routing simpler. Before you commit to a design, count how many connections your app opens per session, because a reconnect loop or a connection per utterance usually shows up only after launch as bad tail latency. When the workload is mostly low-volume JSON or tool-call traffic, WebSocket wins on setup time and predictable routing, and no media optimization pays back an 80 ms handshake on a message that takes 3 ms to deliver.

Where the rest of a voice turn's delay comes from

WebRTC sends media over UDP, and that pays off clearly only when packets go missing. On a clean network the two transports can measure close together. WebRTC pulls ahead mainly under packet loss, where TCP's head-of-line blocking stalls the stream, and only when the application can live with audio that arrives out of order or not at all.

End-to-end delay in a voice agent is mostly everything else. Microphone capture and audio framing come first, then transport, speech-to-text, model inference, text-to-speech, buffering and playback, plus a telephony gateway wherever a call crosses a carrier. The pipeline shape matters too. A speech-to-speech model takes audio in and gives audio out in one hop, while a cascade of speech-to-text, a language model and text-to-speech runs three, so the same model speed gives very different turn times. This breakdown of speech latency in voice agents walks through where each stage adds time.

WebSocket is a sound choice for server-side audio when predictable routing, simpler observability and ordered delivery matter more than WebRTC's media features. WebRTC earns its extra parts in browser conversations, interruption-heavy turn-taking and lossy networks, a narrower set of cases than the usual advice suggests. When callers dial in from a phone, our WebRTC vs SIP guide explains where SIP trunking fits and how one agent takes browser and phone calls.

Operations belong in the same budget. WebRTC needs application signaling plus ICE, STUN and TURN, and often a media server, while a WebSocket runs over an ordinary HTTPS connection. Relay provisioning, TURN capacity and failure handling all sit between a caller's first word and the agent's reply, and the Cartesia analysis of WebRTC and WebSocket trade-offs counts that operating work as part of the choice. Treating transport as one stage in a longer data pipeline gives better answers than a single protocol vote, and MakeAutomation on real-time data pipelines is a useful reference for the surrounding architecture.

Join the Dograh Community

Dograh is an OSS alternative to Vapi. Join our Slack community for queries, releases, best practices & community interactions.

Relays, encryption and where the audio travels

For regulated teams the deciding question is where the audio physically goes. WebRTC's relays turn that into a design decision, while a WebSocket path goes straight to your backend.

ConcernWebRTC pathWebSocket path
EncryptionDTLS and SRTP requiredDepends on TLS configuration
Relay locationTURN may relay media, so relay ownership must be definedDirect to your backend endpoint
Audit and loggingNeeds a designed capture point for mediaCentralized at the server
Failure modesICE, NAT and TURN failuresStandard TCP and TLS failure handling
Data residencyConfirm whether audio crosses the agreed perimeterEasier to keep inside a private network

WebRTC requires DTLS and SRTP encryption on every session, while a WebSocket is only as secure as its TLS setup. The part generic comparisons skip is NAT traversal. When no direct path works, WebRTC media flows through a TURN relay, so relay ownership, data residency, logging and inspection become design decisions rather than implementation details.

For banking, healthcare, government and other regulated deployments this often settles the choice. A WebSocket path is easier to centralize for auditing and controlled egress. WebRTC may trim media delay, but it adds ICE and TURN failure modes and servers your team has to run and monitor. This analysis of WebRTC versus WebSocket for real-time features adds a practical warning, since published millisecond figures rarely state a method, so time messages yourself, on a lossy connection too.

Two designs tend to pass an audit. The first uses WebRTC at the browser edge for microphone audio, then connects to backend services over an authenticated WebSocket, so media stays close to the user and business logic stays inside your perimeter. The second runs WebSocket end to end where private routing and inspection come first, with fewer moving parts and one place to log. Before committing to either, check relay region, retention window, audit trail, failover behavior and whether customer audio ever leaves the agreed perimeter. This voice AI data residency checklist turns those questions into a review you can hand to a security team.

Matching the transport to the workload

Start with WebSocket when the product is mostly text, events, tool calls and phone audio handled by a provider. Add WebRTC when browser microphone audio and interruptions dominate and your team can run STUN and TURN.

WorkloadRecommended pathWhy
Browser voice agent with interruptionsWebRTC for audio, WebSocket for control eventsNative media timing and barge-in at the browser edge
Inbound or outbound phone callsProvider media stream over WebSocketCarrier audio arrives as a simple two-way stream
Text chat and workflow eventsWebSocketSmall ordered messages with low setup cost
Tool calls, CRM updates and webhooksWebSocketPredictable server routing and easy logging
Regulated, audit-heavy deploymentWebSocket end to end, or WebRTC only at the browser edgeControlled egress and inspectable paths
Live audio on lossy mobile networksWebRTCBetter tolerance of loss and jitter

A hybrid design is the usual outcome for voice agents, and usually the right one. Picture a dental clinic whose website voice widget needs WebRTC, because the browser holds the microphone and patients interrupt mid-sentence, while its phone line arrives from the carrier as a media stream over WebSocket. One product runs two transports, with one shared speech and language pipeline behind them.

A benchmark plan for your own network

The only benchmark that settles the choice runs both transports through the same speech, model and voice pipeline on your own network. Everything else stays fixed, so the transport is the one thing that changes.

Measure time to first audio from the end of the user's speech, since that is the number callers feel, and test interruption recovery by talking over the agent mid-reply and timing how fast it stops and picks up again. Run both paths under variable packet loss as well as on a clean network, because that is where they diverge most. Log TURN relay usage and relay locations, since a high share of relayed sessions means your media path is longer than the diagram shows. Record CPU and bandwidth per concurrent call, because the faster transport can cost more capacity, and compare p99 latency across regions and devices rather than averages, since the slow tail is where a conversation feels broken.

Holding the pipeline constant is the step teams skip most often, and it is the one that gives a usable answer within a day. Once a path wins, instrument it properly. This guide to voice AI observability metrics covers the metrics worth tracking once both paths are live, including the ones that expose a regression before a caller complains.

How Dograh splits browser and phone audio

Dograh is the orchestration layer that runs the call flow, tools and telephony, and the speech and language models are a separate layer you choose. It follows the hybrid pattern above. Browser calls, including the website voice widget, run over WebRTC, set up through a WebSocket signaling channel that passes ICE candidates as they are found. Phone calls on Twilio arrive through Media Streams as a two-way WebSocket stream carrying 8 kHz phone audio, so the transport choice is already made for each path.

Relay ownership is yours when you self-host Dograh. The install can run its own coturn TURN server beside the rest of the stack, so browser audio that needs a relay passes through a server you run, and the Docker deployment guide shows how to turn it on and force every browser call through the relay to prove it works before launch. Dograh does not ask Twilio to record calls. It saves its own recording and transcript of each call, so the capture point sits inside your deployment instead of being split across two vendors.

The code is open under the BSD 2-Clause license, so your team can read the signaling and transport code before trusting it. Running it yourself means no per-minute platform fee, though servers, model keys and phone minutes still cost money and your team looks after the database and upgrades. Support comes from the open-source community, and Enterprise adds custom SLAs. Dograh Cloud runs it for you for a 1¢-a-minute platform fee. Start at Dograh and benchmark the pipeline on your own network.

Glossary

ICE
Interactive Connectivity Establishment. The WebRTC step that tests candidate network paths between two endpoints and picks one that works.
TURN server
A relay that carries WebRTC media when no direct path gets through. Whoever runs it decides where that audio travels.
Head-of-line blocking
A TCP stall where one lost packet holds back every later packet until it is resent, which turns packet loss into delay.
Time to first audio
The time from the end of a caller's speech to the first sound of the agent's reply. It is the delay a caller actually feels.

Frequently Asked Questions

Built with Outrank tool

Get started with Dograh

Build, deploy, and scale AI agents with Dograh. Join the community of developers building the future.