Real-time applications carry several kinds of traffic, and a single transport choice can hide their different needs. A browser voice agent makes the tradeoffs concrete: microphone audio must stay timely, session commands need clear delivery rules, and a connected socket does not prove that the user can hear a reply. The choice between WebRTC and WebSocket starts with those requirements, then extends to network paths, security, scaling, and the points where a conversation can stall.
WebRTC vs WebSocket: the short answer
Choose WebRTC for interactive audio, video, screen sharing, or a data channel that needs configurable delivery behavior. Choose WebSocket for an ordered, persistent connection between a client and an application server. Use both when an app needs a WebSocket control plane and a WebRTC media path.
| Requirement | WebRTC | WebSocket |
|---|---|---|
| Primary job | Real-time media and peer data | Bidirectional client-server messages |
| Typical topology | Peer-to-peer, client-to-media-server, selective forwarding unit, or relay | Client-to-server |
| Browser payloads | Audio and video tracks, plus binary or text data channels | Binary or text messages |
| Delivery behavior | Media favors timeliness; data channels can be reliable or partially reliable, and independently ordered or unordered | Reliable and ordered within each WebSocket connection or mapped stream; loss can delay later bytes on that stream |
| Connection setup | Application signaling, offer/answer negotiation, and Interactive Connectivity Establishment (ICE) path discovery | HTTP/1.1 Upgrade in classic RFC 6455; standardized Extended CONNECT mappings for HTTP/2 and HTTP/3 |
| Network handling | Built for media negotiation, congestion response, jitter, and network address translation (NAT) traversal | Runs through a server endpoint, commonly over Transport Layer Security (TLS) on port 443 |
| Encryption | Required per peer-connection hop; end-to-end media protection through an intermediary needs an additional layer | Use wss:// for TLS; ws:// is unencrypted |
| Server role | Signaling is required; media may be direct, relayed, or server-terminated | The server terminates every connection and routes or processes every message |
| Best fit | Voice and video calls, browser voice AI, screen sharing, multi-party media | Chat, presence, notifications, collaborative state, live dashboards, server events |
For a browser-based voice AI agent, WebRTC is usually the stronger media path because it supplies the browser media stack as well as transport. WebSocket remains useful for signaling, transcripts, session events, and tool state. We built Dasha for technical teams that want the voice AI backend and operating layer managed together rather than assembling each real-time component themselves.
What WebSocket actually gives you
WebSocket is a message protocol and browser API for full-duplex communication between a client and a server. In the classic WebSocket protocol, an HTTP/1.1 Upgrade opens a WebSocket whose frames travel over Transmission Control Protocol (TCP). The standardized HTTP/2 mapping runs one WebSocket over a single HTTP/2 stream through Extended CONNECT. The HTTP/3 mapping applies the same model to an HTTP/3 stream over QUIC.
These mappings change connection sharing and loss isolation. They preserve the application-level invariant: each WebSocket delivers data reliably and in order within its connection or mapped stream. With classic TCP and HTTP/2, a lost TCP segment can delay delivery across the underlying connection. HTTP/3 uses QUIC to isolate that delay between independent streams. Later bytes on the affected WebSocket stream still wait for its missing data. That is per-stream head-of-line blocking.
The active transport handles ordinary packet-loss recovery. The application still owns the guarantees a transport cannot infer: whether a message was processed, how to fill a reconnect gap, whether a retried command may run twice, and how to resume after an outage. Message IDs, acknowledgements, idempotency, durable storage, and replay rules provide those semantics.
WebSocket also does not understand audio, video, codecs, or jitter. It moves bytes. If you send microphone audio through it, your application owns capture, encoding, framing, stale-media policy, buffering, and playback timing. A reliable stream can repair loss yet deliver an audio chunk too late to play. The application must timestamp and discard stale chunks instead of treating transport recovery as media recovery.
Flow control has two separate directions. In the classic browser API, bufferedAmount reports outbound data queued by send() that has not reached the network. It helps the sender stop adding work to a growing queue. The classic browser API provides no corresponding receive-side backpressure. If messages arrive faster than the handler can process them, the browser may buffer them until memory or CPU becomes the limit.
WebSocket is a good fit when the server is the authority. Chat history, document state, market events, agent status, and multiplayer game state often need server-side validation or persistence. Routing every message through that server is useful in those cases.
What WebRTC actually gives you
Web Real-Time Communication (WebRTC) is a suite of browser APIs and network protocols for real-time media and data. Its main browser interfaces are:
getUserMedia()to capture microphones and cameras;RTCPeerConnectionto negotiate and operate media and data paths;RTCDataChannelto exchange arbitrary application messages.
WebRTC has a media pipeline that WebSocket lacks. It negotiates codecs, secures each peer-connection hop, responds to changing bandwidth, manages jitter, reports connection statistics, and can use browser audio processing such as echo cancellation where the implementation supports it and the application enables it. Its protocol overview also separates signaling from the media and data paths.
The application must supply signaling. Peers need a way to exchange session descriptions and ICE candidates before WebRTC can establish a path. That channel can be WebSocket, HTTP, Session Initiation Protocol (SIP), or another application-defined mechanism.
ICE handles path discovery across firewalls and NAT. It commonly uses Session Traversal Utilities for NAT (STUN) to discover reachable address mappings. Traversal Using Relays around NAT (TURN) supplies a relay when a direct path cannot be established.
Two common descriptions of WebRTC need qualification:
- WebRTC is more than browser-to-browser peer-to-peer communication. A peer can be a media server, a selective forwarding unit (SFU), a gateway, or a voice AI service. Many production calls terminate at server infrastructure.
- WebRTC is more than a choice between User Datagram Protocol (UDP) and TCP. Media normally favors datagram transport, and ICE evaluates possible paths. A restrictive network may force traffic through a TURN relay, with the client-to-relay leg running over TCP or TLS. WebRTC data channels use Stream Control Transmission Protocol (SCTP) over Datagram Transport Layer Security (DTLS) and expose several delivery modes.
The data channel standard makes reliability and ordering separate dimensions. An RTCDataChannel can be reliable or partially reliable, and it can independently be ordered or unordered. That makes it useful for fast-changing game positions, where a late update has little value, and for reliable control messages inside the same peer connection.
The production differences that matter
Latency depends on what happens after packet loss
WebSocket data follows reliable ordering within its connection or mapped stream. TCP or QUIC handles ordinary transport loss, so the application does not reimplement packet retransmission. Later bytes on the affected stream remain unavailable until the missing data is recovered. With TCP-based WebSockets, that delay can also affect other streams sharing the same TCP connection. This head-of-line behavior preserves order, which is desirable for a sequence of financial commands or chat messages. It can make a live audio stream pause and then expose stale data that the application must drop.
WebRTC media favors the current moment. It can adapt bitrate, conceal some loss, use jitter buffers, and keep playback moving. A late audio packet may be discarded because playing it after newer speech would make the conversation worse.
This is why “WebRTC is faster” is too broad. WebRTC usually gives interactive media a better latency profile on an imperfect network. For small application messages on a healthy path, server distance, processing time, congestion, and topology may matter more than the protocol label.
Topology determines server cost and control
Every browser WebSocket connects to a server. That server can authenticate messages, persist them, fan them out, and enforce an authoritative state. It also holds the connections and carries the traffic.
A two-party WebRTC call may send media directly between endpoints. Direct media can reduce server bandwidth, but it is not guaranteed. NAT and firewall conditions may require a TURN relay. A small multi-party room can use a peer mesh. Larger or production multi-party rooms commonly use an SFU so each participant avoids uploading a separate stream to every other participant. A full peer mesh becomes expensive on client bandwidth and CPU as the room grows.
ICE uses host, server-reflexive, and relayed candidates to find a working path. The ICE specification defines that NAT traversal process. Your capacity plan therefore needs direct-path rate, TURN usage, room size, bitrate, and regional placement. “Peer-to-peer” alone is not a scaling plan.
Reliability needs an application definition
For WebSocket, the underlying reliable transport recovers lost data and preserves order within the connection or mapped stream. Once the connection breaks, the protocol does not restore missed application events by itself. A reconnect can also repeat a command if the client does not know whether the server completed it.
For WebRTC media, timely delivery takes priority over perfect delivery. For RTCDataChannel, the application chooses reliability and ordering separately. A control channel might be reliable and ordered. A transient-state channel might be partially reliable and unordered because a new value supersedes an old one.
Define reliability as a product requirement: must every event arrive, can it arrive late, can it arrive twice, and what happens across reconnects? Then implement the missing acknowledgement and recovery semantics above the transport.
Setup complexity moves to different layers
A WebSocket client needs a URL, authentication, message schemas, heartbeats, reconnect behavior, and server infrastructure that can keep long-lived connections open.
WebRTC adds media permissions, device handling, codec negotiation, offer/answer signaling, ICE gathering, STUN/TURN service, track lifecycle, and more connection states. Larger or production multi-party rooms commonly add an SFU or another media-server topology, while a small room may use a mesh.
WebRTC's larger setup cost buys media-specific behavior. Rebuilding only its transport with a WebSocket leaves the hard media problems in your application.
Security covers different boundaries
Production WebSockets should use wss://, authenticate the connection, authorize every message, validate the Origin header where relevant, and limit message size and rate. TLS secures the route between a client and the WebSocket server. It does not decide whether a connected user may perform an action.
WebRTC requires encrypted media and data channels. The security architecture requires Secure Real-time Transport Protocol (SRTP) for media and DTLS for data channels. That protection applies to each peer-connection hop. An SFU or a terminating media service can terminate the protected hop and access media. End-to-end media encryption through such an intermediary requires a separate design, including key management and a scheme such as Secure Frame (SFrame). Signaling remains a separate boundary. A protected media hop does not make an unauthenticated signaling service or an over-permissioned room safe.
Operations differ after launch
For WebSocket, track connection count, open and close reasons, round-trip time, send buffers, message lag, retries, and reconnect storms. Build replay behavior before a deployment disconnects thousands of clients at once.
For WebRTC, track selected candidate type, relay rate, packet loss, jitter, round-trip time, bitrate, codec, audio level, and connection-state changes. The standardized getStats() surface gives media-specific telemetry. These network measurements should connect to the rest of the voice latency budget, including speech processing, model response, tools, and synthesis.
When to choose WebRTC, WebSocket, or both
| Use case | Recommended choice | Why |
|---|---|---|
| One-to-one voice or video call | WebRTC | Native media capture, codec negotiation, loss handling, jitter management, and echo cancellation where available and enabled |
| Browser-based voice AI | WebRTC for audio, WebSocket or HTTP for control events | The browser leg needs media behavior; the application still needs authenticated session and business events |
| Text chat, presence, or notifications | WebSocket | Server-mediated messages are easy to validate, persist, route, and replay |
| Live dashboard or market feed | WebSocket | The source is a server and messages need ordered client delivery; use application-level recovery for gaps |
| Multi-party video room | WebRTC, often through an SFU as the room grows | A small mesh can work; an SFU forwards media more efficiently for larger or production rooms while signaling and room state stay server-controlled |
| Fast multiplayer game | Usually both | Use an authoritative server path for durable state and WebRTC data channels only where stale transient updates can be dropped |
| Browser-to-browser file transfer | WebRTC data channel | Direct transfer can avoid routing the file through your application server |
| Stored, scanned, or resumable file upload | HTTP or WebSocket control, not direct WebRTC alone | The server must own persistence, policy, resumption, or inspection |
| Collaborative document editing | WebSocket | The server usually owns ordering, conflict handling, persistence, and access control |
| Device telemetry to a backend | WebSocket | The communication is client-server and the backend needs to process or retain the stream |
The table is a starting point. A privacy policy, enterprise network, mobile background behavior, or regional media requirement can change the decision.
A browser voice-agent architecture using both
WebRTC and WebSocket frequently run together because media and application state have different needs. Consider a browser voice agent with an application backend and a separate voice runtime. This generic reference architecture separates the audio path from server-routed signaling and control.

Keep browser media separate from control
Browser microphone/speaker <== WebRTC audio, optionally via TURN ==> Voice/media endpoint | Agent runtime | Model, speech, tool services Browser app <== wss:// signaling/control ==> Application backend
The voice/media endpoint terminates the browser's peer connection and connects it to the runtime. It may share infrastructure with the application backend; the paths still have separate responsibilities.
- The browser client authenticates with the application backend.
- An authenticated
wss://channel creates the session. - The backend routes WebRTC offers, answers, and ICE candidates between the browser and voice/media endpoint.
- WebRTC carries microphone and response audio, directly to the endpoint or through a TURN relay when needed.
- WebSocket carries session events, transcripts, tool state, and other application messages.
- The backend persists the events that must survive a reconnect.
WebSocket is an application choice here. HTTP can carry signaling in another design, and an established data channel can carry suitable session events. The runtime coordinates turn-taking, model calls, tools, and response audio; those processing responsibilities remain regardless of the signaling transport.
Choose the backend audio leg separately
A backend or runtime can also act as a WebSocket client to an audio service:
Backend/runtime <== wss:// audio chunks ==> Audio service
That connection can sit behind the WebRTC endpoint or serve a non-browser audio source. Choosing WebSocket for this service-to-service leg does not require moving browser media onto WebSocket.
WebSocket permits binary message payloads. The service contract defines audio format, chunk boundaries, timestamps, and interruption events. Application queues need bounded growth and a stale-chunk policy. Audio from an interrupted response should not play merely because ordered transport eventually delivered it. WebSocket itself adds no codec negotiation, jitter buffer, or playback adaptation.
Locate failures and measure the full turn
Attach diagnostics to the boundaries in the flow:
- Capture and setup: Record microphone permission and device failures, control authentication, offer/answer completion, and ICE/media establishment separately. An open control socket does not establish that audio is flowing. The WebRTC connection states distinguish a transient
disconnectedstate from afailedpeer connection; recovery handling should reflect that difference. - Media path: Correlate connection state with selected candidate type, packet counts, loss, jitter, and jitter-buffer measurements from
getStats(), where exposed by the endpoint. Candidate-paircurrentRoundTripTimeis a connectivity-check round-trip time (RTT), not whole-agent response latency. The WebRTC statistics definitions distinguish these measurements. - Audio-service queue: Record queue age and enqueue/dequeue times, plus close and reconnect outcomes. In the browser API,
bufferedAmountcounts queued outbound application bytes and excludes operating-system and hardware buffers. It measures neither elapsed delay nor server processing time. The WebSocket buffer definition sets that boundary. - Runtime work: Time queueing, turn detection, model work, tools, and speech processing as separate local spans. Use phases that match the actual runtime, including speech-to-speech designs.
- Response output: Record first returned audio separately from scheduled output and estimated audible playout. Audio receipt alone does not establish that the user heard a reply.
Define the turn metric explicitly, for example from client-observed utterance end to first response audio output. Use a monotonic local clock for client durations and server-local clocks for server spans. Correlate them with session and turn IDs rather than subtracting unsynchronized client/server timestamps. Keep receipt, scheduled output, and estimated playout labeled as different endpoints.
A seven-question decision checklist
- What is the payload? Choose a media stack for live microphone, camera, or screen tracks. Choose messaging for application events.
- Where must data go? Direct endpoint-to-endpoint paths favor WebRTC. A server-authoritative workflow favors WebSocket.
- What may be late or lost? Write separate rules for media frames, transient state, commands, and durable events.
- What must the server do? Persistence, moderation, authorization, recording, AI processing, and fan-out often require server involvement regardless of transport.
- Which networks must work? Account for mobile networks, symmetric NAT, enterprise firewalls, proxies, and TURN relays in the network requirements.
- What happens after disconnection? Define reconnect, resume, replay, duplicate suppression, and user-visible failure states.
- Can your team operate the stack? Price signaling, gateways, SFUs, TURN, observability, deployment drains, incident response, and cross-browser testing along with bandwidth.
WebRTC vs WebSocket FAQ
Is WebRTC faster than WebSocket?
WebRTC usually handles interactive media better under loss because current audio or video can move ahead instead of waiting for retransmission and ordered delivery on a WebSocket stream. It is not automatically faster for every data workload. Network path, server location, payload size, congestion, and processing time can dominate.
Is WebRTC based on TCP or UDP?
WebRTC combines several protocols. Media commonly runs over SRTP on a datagram path. Data channels use SCTP over DTLS. ICE may select direct or relayed candidates, and restrictive networks can require the client-to-TURN relay leg to run over TCP or TLS.
Does WebRTC require WebSocket?
No. WebRTC requires signaling, but it does not prescribe WebSocket. Applications can exchange session descriptions and ICE candidates over WebSocket, HTTP, SIP, or another channel. WebSocket is common because it already supports bidirectional server messaging.
Can WebSocket carry live audio?
Yes. Binary WebSocket messages can carry encoded or raw audio, and the reliable transport handles ordinary packet-loss recovery. Your application still owns capture, codec and framing choices, outbound flow control, stale-chunk policy, receive buffering, playback timing, network adaptation, and echo control. WebSocket is reasonable on controlled server links. WebRTC is usually the better browser media path.
Are WebSockets outdated?
No. WebSocket remains a mature choice for bidirectional client-server messaging. Newer transports target different constraints. They do not remove the need for chat, control, presence, signaling, and state synchronization.
Put the voice experience ahead of the transport
A production voice agent needs more than a low-latency socket. It needs stable turn-taking, interruption handling, tools, testing, monitoring, call execution, and traceability across browser and phone channels. With Dasha, we package those concerns into a managed production platform for voice AI. Start a Dasha evaluation with one real conversation flow and measure the complete round trip.



