AlgoViz

WebTransport

medium 30 min

WebTransport gives a browser and a server one encrypted HTTP/3 session that carries many independent reliable streams and also datagrams that may be lost.

Video lesson · Chapter 1 of 5

Enter a live match over HTTP/3

0:00 / 4:43

Theory

Read or listen first. About 2 min.

What it is

WebTransport is a browser API and a protocol for two-way communication between a client and a server. It runs over HTTP/3, and HTTP/3 runs over QUIC, a transport built on UDP with encryption included.

One session offers three kinds of channel. A bidirectional stream carries bytes both ways. A unidirectional stream carries bytes one way. Both are reliable and ordered. A datagram is one small packet that is sent once: it may be lost, and it may arrive out of order.

Why it exists

A WebSocket is one ordered pipe over TCP. If a packet is lost, everything behind it waits for the resend, even a message that has nothing to do with the lost one. For a player's position sent 60 times a second, the resent position is already out of date.

Applications that needed lossy delivery in a browser used WebRTC data channels, which bring a peer-to-peer connection setup that a plain client and server do not need. WebTransport offers the same two choices, reliable or latest, to an ordinary HTTPS server.

A short history

  1. May 2021

    QUIC is published as RFC 9000: encrypted, multiplexed streams over UDP, with connections identified by an ID instead of by addresses alone.

  2. January 2022

    Chrome 97 ships the WebTransport API in a stable release.

  3. March 2022

    RFC 9221 adds unreliable DATAGRAM frames to QUIC.

  4. June 2022

    HTTP/3 is published as RFC 9114. Two months later RFC 9297 defines HTTP datagrams and the capsule protocol that WebTransport builds on.

  5. June 2023

    Firefox 114 adds WebTransport.

  6. March 2026

    Safari 26.4 adds it, and MDN marks the API as Baseline: newly available in the latest versions of all major browsers.

Words to know

Session
One WebTransport connection to one URL. It lives as long as the HTTP/3 CONNECT stream that opened it.
Stream
A reliable, ordered sequence of bytes inside the session. Streams do not wait for one another.
Datagram
One small packet, sent once, not resent, not ordered, and too small to be split.
Head-of-line blocking
Data that has arrived waits because something sent earlier has not.
Extended CONNECT
The HTTP request that turns one HTTP/3 stream into a WebTransport session.
Draining
The server asks the client to finish its work and reconnect elsewhere.
Connection ID
The label QUIC uses to recognise a connection after the client's address changes.

How it works

Step through the idea, or press Play.

Step 1 of 3

Open one session. QUIC handshake, then an extended CONNECT to an HTTPS URL

Understand it

Start here

The ferry landing

Picture a lake with a village on one shore and a fair on the other. The village has several jetties, and there are flat stones for skipping across the water.

Many jetties and a few skipping stones

One landing, many ways across, and each load takes the one that suits it.

The layers

What it is built on

One session, two kinds of delivery

A browser sends player events over a reliable stream and positions as datagrams to one game server. Both enter the server through its HTTP/3 and QUIC part over UDP port 443. The game server saves results to a database outside its box.
Both arrows travel in the same encrypted QUIC connection. The thick border is one server.

From the wire up

LayerWhat it gives you
UDPPackets between two addresses, with no promises
QUICTLS 1.3 encryption, streams, datagrams, loss recovery, congestion control, connection IDs
HTTP/3URLs, headers, status codes, and the CONNECT request
WebTransportA session with streams and datagrams, and the browser's security rules
Your protocolMessage boundaries, types, acknowledgements, reconnect
The ideas below HTTP/3 are in HTTP/2 and HTTP/3.

The specification of the wire format is still an IETF draft: version 17, dated 2 November 2026, is in working group last call. The browser API is a W3C document. Server libraries implement particular drafts, so check that your library and your browsers meet on one.

Connecting

How a session opens

Handshake and first data

The client must see the server's settings before it may ask for a session. The server checks the path, the Origin and the credentials before it answers 200.

Round trips before the session is ready

TWebTransport≈1⏟QUIC + TLS+1⏟CONNECT=2 RTTTWebSocket≈1⏟TCP+1⏟TLS 1.3+1⏟upgrade=3 RTTT_{\text{WebTransport}} \approx \underbrace{1}_{\text{QUIC + TLS}} + \underbrace{1}_{\text{CONNECT}} = 2\,\text{RTT} \qquad T_{\text{WebSocket}} \approx \underbrace{1}_{\text{TCP}} + \underbrace{1}_{\text{TLS 1.3}} + \underbrace{1}_{\text{upgrade}} = 3\,\text{RTT}
With an 80 ms round trip: about 160 ms against 240 ms. New connections, no loss. A session may not be requested in QUIC's zero round trip data, because CONNECT is not a safe method to replay.

Channels

Streams and datagrams

  • Bidirectional stream

    Reliable and ordered, both ways. Either side may open it. Chat, requests and replies, game events.

  • Unidirectional stream

    Reliable and ordered, one way. Server news and leaderboards, client uploads and telemetry batches.

  • Datagram

    Sent once. May be lost, late or out of order. Positions, cursors, live sensor values.

  • Stream per message

    Streams are cheap to open. One stream per message makes each message independent, and a late one can be cancelled.

What each channel promises

StreamDatagram
DeliveryResent until it arrives, or the stream is resetOnce, may be lost
OrderInside the stream onlyNone
SizeAny number of bytesOne packet, read maxDatagramSize
BoundariesNone: a byte streamKept: one write, one datagram
Flow controlPer stream and per sessionNone, but queues drop
Congestion controlYesYes, shared with streams

Loss

Why independence matters

One lost packet, three designs

Inside one stream, order still holds: a gap blocks the rest of that stream. Put unrelated data on different streams.

How many updates get stuck behind one loss

n≈RTTinterval=80 ms1000/60 ms≈4.8n \approx \frac{\text{RTT}}{\text{interval}} = \frac{80\ \text{ms}}{1000/60\ \text{ms}} \approx 4.8
At 60 updates a second and an 80 ms round trip, one resend holds back about five newer updates on an ordered pipe. With datagrams the next update arrives 16.7 ms later and replaces the lost one.

With 2% independent loss, 60 datagrams a second lose about 60×0.02=1.260 \times 0.02 = 1.2 a second. Two losses in a row happen for about 0.022=0.04%0.02^2 = 0.04\% of pairs. Real loss comes in bursts, so measure yours, and send the last few inputs in each datagram if a short gap must not be noticed.

Choosing

Which channel for which data?

Pick a channel

A video frame is larger than a datagram. Either split it and accept gaps, or give each frame its own stream and cancel the ones that are too late.

Use it when

  • Multiplayer games that mix events and positions
  • Low-latency video or audio to and from your own servers
  • Live collaboration with edits and cursors
  • You need reliable and lossy channels together
  • Clients move between networks
  • Updates come 60 or more times a second

Avoid it when

  • A simple chat: WebSocket is simpler
  • You must support browsers from before March 2026 without a fallback
  • Your servers or load balancers cannot speak HTTP/3
  • Data only flows from server to client: Server-Sent Events
  • Client networks block UDP
  • Calls between browsers: WebRTC

Against the alternatives

StrengthCostBest for
WebTransportStreams and datagrams to a serverHTTP/3 servers, your own framing, a fallbackGames, live media, dense updates
WebSocketSimple messages, available everywhereOne ordered pipe over TCPChat, notifications, dashboards
Server-Sent EventsPlain HTTP, reconnects by itselfOne way, textFeeds, progress
WebRTCPeer to peer, media codecs, echo cancellingICE, STUN and TURN setupVideo calls, file sharing between peers
gRPC-WebTyped calls from generated codeA proxy, no client streaming in browsersStructured APIs
All of them are compared as ideas in real-time APIs.

The API

Using it in a browser

TypeScript
const transport = new WebTransport("https://game.example.com:443/match", {  requireUnreliable: true,          // refuse a fallback to HTTP/2  congestionControl: "low-latency", // a hint, the browser may ignore it});await transport.ready;              // rejects if the session is refused// Must arrive: one stream, with our own framingconst stream = await transport.createBidirectionalStream();const events = stream.writable.getWriter();await events.write(frame({ type: "join", player: "p-123" }));// Only the newest mattersconst out = transport.datagrams.createWritable  ? transport.datagrams.createWritable()  : transport.datagrams.writable;    // older Chrome and Firefoxconst positions = out.getWriter();positions.write(encodePosition(seq++, x, y)).catch(() => {});// Streams the server opensfor await (const s of transport.incomingUnidirectionalStreams) readNews(s);
Check for support, set a deadline for the handshake, and read maxDatagramSize before writing.

datagrams.writable is deprecated and Safari never had it; createWritable() is the current form (Chrome 159, Firefox 155, Safari 26.4). Iterating a stream with for await is also newer than the API itself, so read with getReader() if you support older versions.

A session's life

  1. 1

    Create

    new WebTransport(url) with an HTTPS URL that names the port. options.protocols offers application protocol names, and the server picks one.

  2. 2

    Ready

    transport.ready resolves when the server accepts. Streams opened by the server show up in incomingBidirectionalStreams and incomingUnidirectionalStreams.

  3. 3

    Draining

    transport.draining resolves when the server asks you to leave. Open a new session, move over, then close the old one.

  4. 4

    Closed

    transport.closed resolves after a clean close and rejects after a failure. Either way all streams of the session are gone.

Networks

Moving, blocking and falling back

QUIC recognises a connection by its connection ID, so a connection can go on when a phone moves from Wi-Fi to mobile data and gets a new address. The client probes the new path and the server checks that it answers before sending much. This works only if every box in front of the server also routes by connection ID. Treat it as a bonus: your client must still be able to reconnect and resume.

Connect with a fallback

The 3 seconds are our choice. Remember for a while that a network blocked you, so the next start is quick.

Running it

Servers, limits and operations

Two session servers behind one address

Browsers reach a layer 4 load balancer over UDP port 443. It keeps each connection on one of two session servers. Both session servers publish to and read from a shared message bus.
The balancer must keep one QUIC connection on one server. The bus carries messages between players who are on different servers.

What to decide before launch

TopicDecideWhy
Load balancingUDP, by connection ID if you canAn address change must not land on a server that does not know the session
DeploysSend drain, wait, then closeSessions are long; a hard restart drops everyone at once
ReconnectsBackoff with jitterThousands of clients returning together is a thundering herd
StateResume token and last sequence numberAll streams die with the session
LimitsStreams per session, bytes per second, sessions per userAn open session is cheap for the sender and not for you
SecurityCheck Origin, authenticate, validate every datagramThe browser sends Origin; the server must check it
MonitoringShare of fallback, handshake failures, datagram loss, round tripThey tell you which networks block UDP

Certificates are the normal HTTPS ones. For test servers and short-lived machines, serverCertificateHashes accepts a certificate by its hash if it is valid for less than two weeks and uses an ECDSA key. For credentials, prefer a short-lived token in the first message or in the headers option where supported; a token in the URL ends up in logs.

Costs: no licence is involved, the protocol and the common libraries are open. You pay in CPU (QUIC encryption runs in your process), in memory per open session, and in the work of a second transport for the fallback.

Trade-offs

Pros and cons

Pros

  • Multiple streams in one connection
  • Datagrams for data that expires
  • No blocking between streams when a packet is lost
  • Connection migration where the path supports it
  • Short setup: encryption is part of the first round trip
  • Always encrypted: TLS 1.3 is part of QUIC

Cons

  • New in Safari: only since 26.4
  • Server needs HTTP/3 and so does every proxy in the path
  • More to write: framing, sequence numbers, reconnect
  • UDP may be blocked by firewalls
  • No practical fallback built in
  • Young ecosystem: the wire format is still a draft

Summary

The whole topic in one minute.

WebTransport is for data with different needs on one connection: messages that must arrive go on streams, and updates that are replaced by the next one go in datagrams. A loss on one stream never delays another.

It needs an HTTP/3 server, a path that lets UDP through, and your own framing, reconnect and fallback. If one ordered pipe is enough, a WebSocket is simpler and reaches more places.

  • One HTTP/3 session: many independent reliable streams, plus datagrams that may be lost.
  • Streams for what must arrive, datagrams for what the next one replaces.
  • Streams are bytes: add message lengths. Datagrams are small and unordered: add sequence numbers.
  • About 2 round trips to ready, against about 3 for a WebSocket.
  • Plan for blocked UDP, drains, reconnects and checks of Origin.

Sources