Streaming Replay of Recorded Vehicle Telemetry in a 3D Viewer
System DesignModel answerLast updated
Design a browser-based 3D replay viewer that streams time-indexed vehicle logs from object storage, with prefetching, fast seeking, and aligned playback.
Problem
Design a system that replays recorded vehicle drives as an interactive 3D scene. Each drive is a collection of time-stamped logs stored in object storage (for example, an S3 bucket). An engineer opens a drive in a viewer and watches the vehicle and its recorded signals move through the scene, with play, pause, and a timeline for seeking.
Playback has to begin quickly and stay smooth, even though a single drive is often too large to download before the first frame can appear.
Constraints
- The log files already exist in object storage when playback is requested. Your system reads them but does not control how they were recorded.
- Every recorded message carries a timestamp, so all data in a drive can be placed on one shared timeline.
Clarifying questions you should ask
- What does a log contain? Only vehicle pose over time, or also heavy sensor data such as point clouds and camera frames? At what rates?
- How large is one drive, and what file format is it stored in?
- Does "real time" mean smooth playback at recorded speed, or must the viewer also follow a drive that is still being uploaded?
- How many engineers use the viewer at once, and how often do they open the same drives?
- Do you need speeds other than 1x, frame stepping, or reverse playback?
- Must the viewer run in a web browser?
What we expect
Describe the architecture end to end: the preprocessing step, the chunk and manifest format, the client buffer and cache, the playback clock, handling of heavy data, and how the system fails and is measured. Call out the trade-offs you make.
Hints
Hint 1
Split each drive into time-indexed chunks and publish a small manifest, so the client can request just the window around the playhead instead of the whole file.
Hint 2
Use one playback clock on the client. For each frame, interpolate pose and sample each sensor stream at that clock time, rather than letting every stream drive its own timing.
Hint 3
Keep chunks immutable so they can be cached at a CDN edge. Decide how to handle a seek that lands outside the prefetched window and how to degrade when a chunk is slow or missing.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Overview
The core idea is to treat a drive as a time-indexed dataset, not a file. A preprocessing job converts raw logs into immutable, time-bounded chunks plus a manifest. The browser fetches only the chunks near the playhead, keeps a small cache around it, and renders every frame from one playback clock. The design is built around three goals: fast time to first frame, seeks that feel immediate, and no stalls during normal playback.
1. Preprocessing into chunks
Raw logs are usually stored in a sequential, record-oriented format that is hard to seek into. A batch job runs once per drive, or once per upload, and rewrites the data:
- Split each stream (pose, CAN signals, lidar, camera) into chunks of fixed duration, for example 2 to 5 seconds of wall time. Use the same boundaries for every stream so that chunk N covers the same window across all of them.
- Store each chunk as a separate object with a stable key, such as
drive/{id}/{stream}/{chunk_index}.bin. Mark chunks as immutable, which makes them safe to cache indefinitely. - Write a manifest per drive. It lists the start and end timestamps of every chunk, the stream rates, the coordinate frame, and the byte ranges. The manifest is small, so the client fetches it first and can compute the chunk for any timestamp with a binary search.
The chunk size is a trade-off. Smaller chunks make seeks cheaper and reduce wasted bandwidth, but they create more requests and more per-object overhead. Larger chunks are more efficient on the network but cause slower first frames and more memory use. A 2 to 5 second window with a few hundred kilobytes to a few megabytes per chunk is a reasonable starting point. Measure it against real drives.
For heavy sensor data, the preprocessing job also builds levels of detail. Point clouds can be decimated (voxel downsampling or random subsampling) to produce a coarse level for scrubbing and a full-resolution level for close inspection. Camera frames can be stored as thumbnails and full images. The viewer picks the level based on zoom and playback state. Scrubbing uses coarse data, and paused, zoomed-in views use fine data.
2. Client buffer and cache
The client keeps three regions:
- Playhead buffer: a few seconds ahead of the current time, fully decoded and ready to render. This is what keeps playback smooth.
- Behind-cache: a small window of recent chunks, so brief reverse steps or small backward seeks do not refetch.
- Prefetch queue: chunks further ahead, requested with lower priority. Prefetch speed depends on the observed bandwidth and the current playback speed.
Fetches are issued as HTTP range or object requests, in parallel across streams, and with a bounded concurrency limit so the viewer does not flood the network. The cache is an LRU keyed by chunk, with a memory budget. Decoded data is much larger than compressed data, so the budget applies to decoded bytes.
On a seek, the viewer computes the target chunk from the manifest. It immediately drops or deprioritizes queued fetches that are no longer relevant, requests the target chunk and its neighbors at high priority, and shows the nearest available frame (a coarse level or the last rendered pose) until the full data arrives. Making the seek feel instant matters more than making it exact in the first few hundred milliseconds. Seeks that jump far from the current position should be treated as a fresh start, not a continuation of prefetching.
3. One playback clock and alignment
Streams arrive at different rates. Pose might be 100 Hz, CAN signals 20 to 50 Hz, lidar 10 Hz, and camera 10 to 30 Hz. Do not let each stream drive its own timing. Instead, a single clock advances with the render loop, scaled by the playback speed. Each frame, the viewer asks every stream for its value at that clock time:
- For continuous quantities like pose, interpolate between the two surrounding samples. Use linear interpolation for position and spherical interpolation (slerp) for orientation.
- For discrete or event data, hold the most recent value (zero-order hold) and do not interpolate.
- For lidar and camera, select the frame whose timestamp is closest to the clock time without going past it, so the displayed data never comes from the future.
This keeps the scene consistent when streams fall out of step, and it makes pause, resume, and seek all reduce to setting the clock.
4. Failure handling
- Missing chunk: retry with backoff, then fall back to the coarse level or hold the last valid value. Show a visible indicator instead of silently rendering stale data.
- Slow chunk: if the buffer drops below a threshold, pause the clock briefly (a stall) instead of skipping ahead. Engineers would rather wait a moment than miss data.
- Corrupt chunk: verify a checksum stored in the manifest, then refetch once and report the drive for reprocessing.
- Preprocessing not yet done: for drives still being uploaded (if that is in scope), publish provisional chunks as they finish and mark the manifest as open-ended. Real-time following needs a different path with polling or push notifications.
5. Scale and caching
Chunks are immutable, so a CDN can cache them with long TTLs, and popular drives are served from edge nodes. Object storage handles origin load. The manifest is the only mutable object per drive and can have a short TTL or be versioned. For many concurrent viewers on the same drive, the CDN absorbs most of the traffic and the origin sees only cache misses.
6. Metrics
- Time to first frame: time from opening the drive to the first rendered frame. Target around 1 to 2 seconds. This is mostly manifest plus first chunks.
- Seek latency: time from the seek to a correct (full-resolution) frame. Measure p50 and p95 separately from the coarse frame time.
- Stall rate: stalls per minute of playback, and total stalled time as a fraction of playback time.
- Cache hit rate at the client and at the CDN, and bytes fetched per minute of playback.
Common mistakes
- Downloading the full log before playing, which fails for large drives.
- Using one fixed clock per stream, which causes drift between pose and sensor data.
- Interpolating discrete events, which produces meaningless values.
- Caching mutable objects at the edge, which causes stale data after reprocessing.
- Ignoring decoded memory size, which leads to browser crashes on long drives.
- Prefetching at full rate after a large seek, which wastes bandwidth on chunks the engineer will never view.