~/blog/f1-live_
F1 Live: replaying real races as a shared live broadcast
4 min readwebsocketsredistypescript
The problem
I wanted to understand how live-data systems (sports scores, trading feeds, multiplayer games) push the same changing state to many people at once, and what breaks when you do. Live F1 timing data is paid, but every past race is free from OpenF1. So I built a system that treats a recording exactly like a live feed, and made it hold up under load, slow networks and restarts.
The result is F1 Live: cars moving on the track, a live leaderboard, race-control highlights, team radio and the start lights, all in sync for everyone watching.
Goals: everyone sees the same moment of the same race (a shared watch party, not a video player), motion is smooth on any connection, a new viewer joins mid-race instantly, one bad client can't hurt the others, and it runs for free.
Non-goals: each viewer picking their own race or speed, accounts and logins, and any commercial use.
The architecture
- Record once, replay forever. A race (about 650,000 events, 17 MB) is downloaded once, normalised into a single time-sorted timeline, and replayed against a wall clock at 1x to 50x.
- Batching. About 80 events a second become one message every 250 ms, so the message rate stays constant at any speed.
- Redis in the middle. The replay publishes each tick to a pub/sub channel and keeps the latest full snapshot in a key. It doesn't know how many gateways exist.
- Fan-out. Each WebSocket gateway subscribes to Redis once and sends the same encoded bytes to every socket. Gateways share nothing, so you scale by running more of them.
- Commands go the other way. Changing race or speed travels from the browser through the gateway and Redis to the replay, and is validated at every hop.
- One small server. Everything runs in Docker on one free Oracle Cloud VM. Caddy is the only part with public ports and handles HTTPS.
What happens when a viewer joins
- Deltas plus snapshots. Each tick carries only what changed. A new viewer first gets one full snapshot, then the deltas.
- Sequence numbers, plus an epoch for each replay run, let every gateway and browser detect a missed or stale message.
- The browser draws the race 600 ms in the past, moving each car at constant speed between real samples. Multiplayer games use the same trick, called an interpolation buffer.
Key decisions
| Decision | Why |
|---|---|
| Serialize each message once and reuse the bytes | ~50 ms → ~0.1 ms per tick at 10,000 clients |
| Skip ticks for a slow client, catch it up with one snapshot, drop it after 10 s behind | Live data is superseded anyway; this protects everyone else |
| Subscribe first, then read the snapshot | A duplicate is recoverable; a lost message isn't |
| One shared broadcast with a single Controller | One stream, cheap fan-out, and it feels like watching together |
| Track viewers as small per-server summaries that expire | ~100 bytes at any viewer count; a crashed server disappears in 6 s |
| Stream team radio from F1 instead of storing it | A small library and nothing extra to serve |
| Download races atomically, and cache the race list | Never half a race on disk; 20 simultaneous requests → 1 upstream call |
Results
- 10,000 concurrent WebSocket viewers on one gateway process: p50 latency 58 ms, p99 298 ms, zero gaps, about half of one CPU core and 240 MB of memory. The load generator ran out of CPU before the gateway did.
- Deployed for $0 on an Oracle Cloud Always Free ARM VM, with Docker Compose and Caddy for automatic HTTPS. Only HTTPS and SSH are open; Redis and the gateway stay private.
- Features: live leaderboard, overtakes, Safety Car / VSC / yellow-flag status, start lights with synced beeps, team radio, a race picker covering 2023–2026 with on-demand download, and a mobile layout.
What went wrong (and the fix)
- Redis pub/sub ignores the database number. My "isolated" tests on a separate database leaked into the live broadcast. Fix: prefix every key and channel with a namespace.
- A restarted replay started counting from 1 again, and the gateway dropped every message as a duplicate and froze. Fix: an epoch for every run, with sequence numbers compared only within one epoch.
- The canvas grew in a feedback loop on Retina screens, because its pixel size fed back into the CSS layout. Fix: absolute positioning, and resizing only when the size actually changes.
- The admin link returned 404, because static files were matched including the query string. And browser extensions logged the secret in that URL. Fix: match on the path only, rotate the secret, and treat URLs as public.
- Oracle's firewall rule landed after its own REJECT rule, so the ports stayed closed. Fix: insert the rule at the REJECT's position.
What's next
Rewinding 10–20 seconds for everyone (a shared "seek"), and possibly limiting race downloads to the admin on the public site.
Race data from OpenF1 (CC BY-NC-SA). Team radio © Formula 1. A non-commercial learning project.