We want many people to watch one race while it airs. A viewer’s browser should not run the submitted programs. It should show only what happened in the race, even when its connection is slow.
So the host records the race, and viewers play the recording. The host saves the recording in Vercel Blob, one piece at a time, while the race is still running. We keep that store private. Vercel Functions give each browser the schedule, the list of pieces and the pieces themselves.
The browser checks every piece before it draws from it. The host also sends out a clock that says how far viewers may play. That clock cannot run past the part of the race that is already recorded.
The host saves the race in sealed chunks
A race on the host produces frames, which are samples of the cars. A frame holds the state needed for motion, cameras and the minimap. It does not store what the drivers observed.
Simulation time runs at 60 ticks per second, and the recorder takes a sample every three ticks. That gives 20 regular frames per second, 50 ms apart. A chunk is a batch of at most 30 of those frames, in order. The recording becomes available one chunk at a time.
The host seals each chunk. It writes the chunk out as JSON and hashes those exact bytes with SHA-256. Then it stores the chunk in Blob under that hash, with overwriting turned off.
The list of chunks only grows
A manifest is the list of the chunks saved so far. It holds the identity of the recording, a descriptor for each chunk in order, and the results once there are any. A descriptor is the manifest’s entry for one chunk: its tick range, size and hash.
The host stores each new chunk before it lists the chunk’s descriptor. Each new revision of the manifest keeps every entry that was already listed, so a viewer can keep the chunks it has verified while the race continues.
The browser rejects a revision that removes or replaces a descriptor, or that changes the plan. A recording can have at most 512 chunks, and its final tick is at most 36,000, which is 600 s.
Vercel Functions answer three kinds of read
The browser needs to know which race is selected now, and it needs the recording as it grows. Vercel Functions give it both, through three kinds of read:
- The schedule returns the current phase, race plan, attempt and host time. During racing it also includes the playhead.
- The manifest returns the chunk descriptors in order and how far the recording reaches.
- A chunk returns one numbered batch of frames.
These reads cannot start a race or move it to another phase. They serve only the current race, so a viewer cannot use them to select an old one.
While a race runs, the browser reads the schedule and the manifest about every 1.5 s. It downloads at most four chunks at a time. It checks each chunk’s exact byte count and hash, and appends the chunks in order, so a later chunk waits for the ones before it.
When a chunk is late, the playhead waits
Showing a tick takes two things: permission from the host, and the poses for that tick. A pose says where a car is and which way it points. The permission is the playhead, the host’s clock for playback.
The playhead advances at 60 ticks/s and stops at the last tick of the recording that is available. After the host saves more of the recording, the playhead continues from the tick it had reached. So when a chunk is late, all viewers wait together, and playback does not jump when the recording catches up.
Live playback runs 11 seconds behind the playhead
A browser that follows the newest playhead tick has no time left to cover a slow download. So we delay live playback by 11 s, and the browser requests the recording up to 12 s ahead of its cursor, its own position in the recording.
In a throttled test with the final chunk 4 s late, an 8 s delay ran out of frames for 1.52 s. We use 11 s to allow for that gap and for polling.
When the buffer runs empty, the cursor waits until 3 s of verified frames lie ahead. Then it advances at normal speed and does not speed up to make up for the delay. If the cursor is more than 20 s behind the playhead, playback fails. It does not jump ahead to the result.
A viewer who joins late first verifies the recording from its start, with no gaps, and only then shows its first tick.
The browser fills in the poses between samples
Regular samples are 50 ms apart, and we do not simulate the steps in between. For the picture, the browser interpolates, which means it blends between the two nearest samples.
Position, controls and attitude blend linearly. Heading turns through the smallest angle between the two samples. Flags, lap and status keep the value of the earlier sample until the cursor reaches the next one.
Results appear after the whole recording is verified
The results must not contradict the frames sampled earlier. So the host reads and verifies every chunk again before it commits a complete manifest. The browser holds back the results until all the chunks it has verified agree with that manifest.
After both the recording and the playhead have reached the final tick, the host opens a replay phase. It is a window of 25 s for the finish, not another playback as long as the race. A viewer that is already playing uses it to play the delayed last part.