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.

See it run

One HTTP/3 session: how it opens, how streams and datagrams differ, what a loss does, and what happens when the network changes.

Operations

Open a session

From the first packet to the first stream.

Step 1 of 5

QUIC and TLS together

Our systemhelloBrowserWebTransport APIHTTP/3 serverQUIC, UDP 443Game serviceno session

The browser's first packet starts both the QUIC connection and the TLS 1.3 handshake.

Step 1: QUIC and TLS together

def accept(request, settings):    if not settings.webtransport:        return None            # client may not even ask    if request.origin not in ALLOWED:        return 403    if not valid(request.token):        return 401    return 200                 # the session exists
Time
About 2 round trips
You must build
Origin and token checks
WebSocket over TLS 1.3
about 3 round trips

Name the second round trip: the client needs the server's settings before CONNECT.

In the real world

The same webtransport doing real jobs. Pick one and step through it.

A server is replaced while players are connected.

Step 1 of 3

Drain

Our systemconn ID 7fPhoneaddress ALoad balancerUDPServer 1knows sessionServer 2does not know it

draining resolves in the browser

Server 1 sends the drain signal to its sessions. Players go on playing.

Step 1: Drain

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Reading a stream as messages

    critical

    A read returns whatever bytes are there: half a message or three.

    Wrong
    msg = json.loads(stream.read())
    Right
    size = read_exact(stream, 4)msg = json.loads(read_exact(stream, size))
  • Datagrams for what must arrive

    critical

    A lost match result is never sent again.

    Wrong
    send_datagram(match_result)
    Right
    stream.write(frame(match_result))
  • Accepting every Origin

    critical

    Any web page could open sessions with the visitor's network position.

    Wrong
    check_origin = lambda r: True
    Right
    check_origin = lambda r: r.origin in ALLOWED
  • No limit on the handshake

    major

    Where UDP is blocked the connection hangs and the page with it.

    Wrong
    t = await webtransport(url)
    Right
    t = await wait_for(webtransport(url), 3)
  • Applying old datagrams

    major

    Packets arrive out of order. A late one would move the player backwards.

    Wrong
    position = d.position
    Right
    if d.seq > last_seq:    last_seq, position = d.seq, d.position

Interview tips

  • How to explain it

    • One HTTP/3 session.
    • Independent reliable streams, plus lossy datagrams.
    • A loss delays only its own stream.
  • Memory trick

    • Boats must arrive, stones may sink.
    • One jetty per stream.
    • Fog: take the road.
  • Reach for it when

    • Updates expire quickly.
    • Unrelated data shares a connection.
    • The browser talks to your server.
  • Be careful with

    • Networks without UDP.
    • Balancers that route by address.
    • Datagram size and stream framing.