Multi-Sensor Data Replay System for Autonomous Vehicle Scenarios
System DesignModel answerLast updated
Design a scalable system to store, index, and stream synchronized sensor recordings from autonomous vehicles, supporting variable-speed playback and metadata filtering.
Problem Context
You're building a platform that enables engineers to review and analyze recorded driving scenarios from an autonomous vehicle fleet. Each recording contains synchronized streams from multiple sensors—cameras capturing video, LiDAR producing point clouds, and telemetry providing vehicle state information.
Your Task
Design a system that allows engineers to:
- Browse and filter recordings by attributes (weather conditions, scenario duration, geographic area, etc.)
- Stream sensor data at adjustable speeds (0.5×, 1×, 2×)
- Jump to specific moments within a recording with minimal delay
- Access recordings from multiple workstations simultaneously
System Parameters
- Dataset size: 100,000 hours of recordings
- Storage per hour: approximately 100 GB (combining all sensors and metadata)
- Expected concurrent users: up to 1,000 engineers accessing different recordings
- Latency requirements: frame seeking should complete within 300ms; metadata queries within 1 second
What to Address
Design and justify your choices for:
- Storage schema: How you'll organize sensor data, timestamps, and searchable attributes
- API contracts: Key endpoints for discovering recordings and retrieving sensor streams
- Architecture: Component layout, including storage systems, caching layers, and delivery mechanisms
- Synchronization strategy: How you'll maintain alignment between sensors that capture data at different rates
- Scale handling: Approaches to serve thousands of concurrent streams while managing bandwidth and storage costs
Consider the trade-offs between preprocessing strategies versus runtime transformation, and explain how your design would handle both interactive viewing and programmatic access for automated testing.
Hints
Hint 1
Think about separating lightweight metadata (searchable attributes) from heavy sensor data (video, point clouds) into different storage tiers
Hint 2
Consider how video streaming services handle seeking—chunking data and maintaining keyframe indices enables fast random access
Hint 3
Pre-generating multiple quality levels lets clients choose bandwidth-appropriate streams, dramatically reducing concurrent load
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Multi-Sensor Replay System Design
1. Requirements Analysis and Scale Calculations
First, let's quantify the constraints to drive our architectural decisions.
Storage math:
- Total data: 100,000 hours × 100 GB/hour = 10 petabytes
- This volume immediately eliminates traditional databases for raw data storage
Bandwidth requirements:
- Single stream at 1×: 100 GB ÷ 3,600 seconds ≈ 28 MB/s per user
- 1,000 concurrent users: 28 GB/s aggregate throughput
- This calculation reveals the critical insight: serving raw full-resolution data to all clients is infeasible
Key questions to clarify:
- Will this serve only human reviewers, or also automated testing pipelines?
- Are recordings accessed uniformly, or do certain scenarios get repeated views?
- What sensors must stay synchronized, and what's the acceptable drift?
2. Data Organization Strategy
The solution involves three distinct storage layers, each optimized for its access pattern.
Layer 1: Searchable Metadata (PostgreSQL + Elasticsearch)
Store lightweight attributes enabling discovery:
recordings:
- id, vehicle_id, captured_timestamp
- duration_seconds, geographic_bounds
- weather_condition, time_of_day
- scenario_tags (array: "left_turn", "pedestrian_present")
- storage_location_reference
significant_events:
- recording_id, timestamp_ns
- event_type (e.g., "maneuver_start", "sudden_brake")
- event_metadata (JSON)
PostgreSQL handles structured queries while Elasticsearch enables full-text search across tags and free-form annotations. This tier is small—even a million recordings with associated events fits comfortably.
Layer 2: Chunk Index (DynamoDB or per-recording manifests)
This layer maps time ranges to storage locations. Each sensor stream is divided into 2-second chunks:
chunks:
- recording_id, sensor_name, quality_variant
- start_time_ns, end_time_ns
- storage_path, byte_offset, byte_length
- keyframe_offsets (for video chunks)
For a camera at 30 fps, one chunk contains 60 frames. Videos are encoded with keyframes every second, ensuring any seek requires decoding at most one second of data.
Alternative approach: Instead of a database, store a single manifest JSON file per recording. When a client opens a recording, it downloads this manifest (typically <1 MB) and performs local lookups. This eliminates database queries during playback.
Layer 3: Blob Storage (S3 with Intelligent-Tiering)
Raw chunks live in object storage with this layout:
s3://recordings/{recording_id}/{sensor}/{quality}/{chunk_index}
Quality variants dramatically reduce bandwidth:
- Camera:
raw-4k,hd-1080p,preview-480p - LiDAR:
full-density,sparse-10pct - Telemetry: stored separately in TimescaleDB for ad-hoc time-series queries
Older recordings automatically migrate to cheaper storage tiers (Infrequent Access, then Glacier) based on access patterns.
3. Sensor Synchronization Approach
All sensors timestamp their data against a single vehicle master clock (GPS-disciplined) at capture time. During ingestion, the system:
- Normalizes all timestamps to nanoseconds since epoch
- Records per-sensor latency offsets from calibration data
- Stores calibration parameters with each recording
At playback, a virtual playback clock advances at the requested speed. For each tick, the system:
- Queries each sensor for the most recent sample with
timestamp ≤ current_playback_time - Uses sample-and-hold for discrete sensors (LiDAR, images)
- Interpolates continuous signals (steering angle, velocity)
This approach handles sensors with different rates (camera: 30 Hz, LiDAR: 10 Hz, CAN bus: 100 Hz) without forcing artificial alignment.
4. API Design
Discovery and Metadata (REST):
GET /api/v1/recordings?weather=rain&duration_min=5®ion=bbox(...)
→ Returns paginated list with metadata
GET /api/v1/recordings/{id}
→ Full metadata including sensor list, duration, events
GET /api/v1/recordings/{id}/manifest
→ Chunk index for all sensors and quality levels
Streaming Data:
POST /api/v1/playback/sessions
Body: {recording_id, sensors: ["front_camera", "lidar"], quality: "hd"}
→ Returns {session_id, signed_chunk_urls[]}
GET /cdn/chunks/{recording}/{sensor}/{quality}/{chunk_id}
→ Serves actual data chunks (cacheable, immutable)
For Programmatic Access (gRPC streaming):
service ReplayService {
rpc StreamRecording(StreamRequest) returns (stream SensorFrame);
}
StreamRequest: {recording_id, start_time, speed, sensors[]}
SensorFrame: {playback_timestamp, sensor_data_map}
The gRPC approach gives servers control over synchronization and pacing, essential for deterministic simulation pipelines.
5. Architecture Overview
┌─────────────┐
│ Clients │ (Web UI, Jupyter notebooks, test harnesses)
└──────┬──────┘
│
┌───┴────────────────────────┐
│ │
┌──▼─────────┐ ┌──────▼──────┐
│ Query API │ │ Playback API │
│ (metadata) │ │ (sessions) │
└──┬─────────┘ └──────┬───────┘
│ │
┌──▼──────────┐ ┌────────▼─────────┐
│ PostgreSQL │ │ Manifest Cache │
│ Elasticsearch│ │ (Redis) │
└─────────────┘ └────────┬─────────┘
│
┌────────▼─────────┐
│ CDN + Edge │
│ Cache (NVMe) │
└────────┬─────────┘
│
┌────────▼─────────┐
│ S3 Storage │
│ (10 PB chunks) │
└──────────────────┘
Data flow:
- Client queries metadata to find relevant recordings
- Client requests a playback session, specifying sensors and quality
- API returns a manifest with signed CDN URLs for chunks
- Client fetches chunks directly from CDN, buffering 5–10 seconds ahead
- Client-side decoder maintains playback clock and synchronizes sensors
6. Scaling Strategies
Bandwidth optimization:
- Default all clients to preview quality (480p + sparse LiDAR) ≈ 3 MB/s
- At 1,000 concurrent users: 3 GB/s total—easily handled by modern CDNs
- Reserve full-resolution access for automated pipelines with regional data access
Caching hierarchy:
- CDN edge: Popular chunks (80/20 rule—20% of scenarios get 80% of views)
- Regional cache: Recent session chunks on NVMe SSDs (hot data)
- Manifest cache: All recording manifests in Redis (collectively ~100 GB)
Predictive prefetching:
- On session start, prefetch chunks around significant events (e.g., "maneuver initiated")
- When playback reaches 80% of a chunk, fetch the next chunk in background
- At 2× speed, double the prefetch distance
Cost optimization:
- Lifecycle policy: recordings untouched for 90 days → Infrequent Access tier
- After 1 year with no access → Glacier Deep Archive
- Only generate preview variants for all recordings; create HD variants on-demand and cache
7. Preprocessing Trade-offs
| Aspect | Eager Transcoding | Lazy On-Demand |
|---|---|---|
| Initial cost | High (transcode all 10 PB) | Low (transcode only what's viewed) |
| Seek latency | <300ms (pre-chunked, keyframes aligned) | Variable (may need transcoding) |
| Storage overhead | +30% for multiple quality levels | Minimal (cache popular variants) |
| Operational complexity | Simpler playback pipeline | Requires transcoding workers |
Recommended hybrid approach:
- Immediately generate preview quality for all new recordings during ingestion
- Create HD variants lazily when first requested
- Cache generated variants, treating them as authoritative once created
- Reserve raw data for archival and reprocessing
Common Pitfalls
- Attempting to synchronize by frame indices instead of absolute timestamps—sensors with different rates will drift
- Storing all data in a monolithic database—relational databases can't scale to petabyte blob storage
- Ignoring quality variants—serving raw 4K video to every client exhausts bandwidth budgets
- Stateful streaming servers—pushing data through WebSocket connections prevents CDN caching
- Not chunking data—without chunks and keyframes, seeking requires scanning from the beginning
This design balances interactivity (low-latency seeks), scale (thousands of concurrent users), and cost (tiered storage, quality variants, caching) while maintaining precise multi-sensor synchronization.