Building a Pipeline for Fleet-Captured Panoramic Imagery
System DesignModel answerLast updated
Design a system that receives huge volumes of geotagged panoramic photos from a vehicle fleet, stores raw and processed versions durably, and serves location-based tiles quickly.
Scenario
A mapping company runs a fleet of vehicles, each carrying a multi-camera rig that takes high-resolution panoramic photos of streets. Every photo comes with telemetry: GPS position, timestamp, heading/orientation, and the ID of the capturing device. Vehicles store data locally and send it in batches.
Design the backend that receives, stores, processes, and serves this imagery.
Requirements
Functional
- Upload: an authenticated API that lets vehicles send images plus telemetry.
- Storage: keep the original files for long-term archival, and keep processed versions suitable for public display.
- Processing: extract metadata and produce optimized thumbnails and tiles for fast delivery.
- Lookup: answer location queries such as "return the panorama nearest to latitude X, longitude Y".
Non-functional
- Volume: roughly 50 TB of new data per day; tile retrieval must feel instant (sub-second).
- Durability: no data loss; uploads must tolerate retries and be able to resume after interruption.
- Security: only legitimate devices may upload, and file integrity must be verifiable.
What to deliver
- A text description of the high-level architecture and data flow.
- API design for both upload and retrieval.
- A data model for image metadata, including how you index it spatially.
- How the system copes with sudden surges of uploads (for example, many vehicles returning to depots at once) and how you reason about eventual consistency.
Start by converting the daily volume into throughput numbers, and state any assumptions you make.
Hints
Hint 1
Convert 50 TB/day into MB/s, then assume a peak multiple (fleets often return at the same time). Estimate captures per day from an assumed file size, and notice that metadata is tiny compared with the image bytes.
Hint 2
Keep the control plane and data plane apart: let the API hand out signed, resumable upload destinations so the image bytes go straight to object storage, and use a queue between upload and processing.
Hint 3
For spatial lookup, think of a hierarchical cell grid (S2, geohash) used as a row-key prefix, with a covering of the search circle scanned and filtered by exact distance. For consistency, make every pipeline step idempotent and publish tiles before the metadata row that references them.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Sizing first
- 50 TB/day is about 580 MB/s on average (roughly 4.6 Gbps). Fleets tend to return in the evening, so plan for a 3-5x peak, around 2-3 GB/s.
- If one multi-camera capture is about 25 MB, that is about 2M captures/day: ~25/s average and ~120/s at peak.
- Metadata is ~1-2 KB per capture, so ~4 GB/day. This is negligible next to the binaries.
- Raw data grows by about 18 PB/year before replication, so storage cost dominates the design.
Assumptions I would state: vehicles can buffer locally for hours or days (upload is not real time); publication delay of hours to days is acceptable; faces and license plates must be blurred before anything is public.
2. Architecture
- The vehicle client authenticates to the Ingestion API (per-device mTLS certificate plus a short-lived token) and registers a batch manifest: file names, sizes, SHA-256 checksums.
- The API returns signed resumable upload URLs. The vehicle uploads directly to a raw object-storage bucket; image bytes never touch API servers.
- Object finalization emits an event to a durable queue (Kafka or Pub/Sub).
- Validation workers check checksums against the manifest and confirm the image decodes. Failures go to a quarantine bucket.
- Valid items go to a processing queue. Processing workers fuse pose data, stitch, blur faces/plates, and generate a tile pyramid.
- Outputs are written to a tile bucket behind a CDN, and metadata is written to a distributed DB with a spatial index.
- The Retrieval API resolves a location to a panorama via the index and returns tile URLs; clients fetch tiles from the CDN.
Why this shape:
- Separating control and data planes removes the hardest scaling problem; object storage absorbs the bandwidth.
- The queue converts bursts into backlog. A deep backlog means delay, not loss.
- Bytes live in cheap object storage; small queryable records live in a database.
3. APIs
POST /v1/upload-sessions
{ device_id, run_id, manifest:[{capture_id, file_name, size, sha256}], manifest_signature }
-> 201 { session_id, files:[{capture_id, upload_url, expires_at}] }
PUT <upload_url> # chunked, Content-Range, per-chunk CRC32C
GET /v1/upload-sessions/{id} # per-file status and committed offsets
POST /v1/upload-sessions/{id}:complete -> 202
capture_idis deterministic (hash of device, sensor, capture time), so a retried session maps to the same objects. That is the idempotency key.- When overloaded, return
429/503withRetry-After; vehicles keep data on local disk and back off with jitter. - Resume works by asking the session for committed offsets and continuing from there; 8-16 MB chunks are a reasonable size.
GET /v1/panoramas:nearest?lat=&lng=&radius_m=50
-> { pano_id, lat, lng, heading, captured_at, tile_url_template, zoom_levels, neighbors }
GET /v1/panoramas/{pano_id}/tiles/{z}/{x}/{y}.webp # CDN-served, immutable
4. Data model and spatial index
Captures (one row per capture, source of truth): capture_id (PK), device/vehicle/run IDs, timestamp, lat/lng/alt, heading/pitch/roll, leaf S2 cell ID, raw_uri, sha256, size_bytes, status (UPLOADING, VALIDATED, PROCESSED, PUBLISHED, or QUARANTINED), pipeline_version, quality_score.
Spatial index (read-optimized): row key s2_cell_L16 | reverse(captured_at) | pano_id. Level-16 cells are about 150 m wide, which fits street segments, and the reversed timestamp puts the newest imagery first in a scan.
Published table: keyed by cell, pointing to the currently live pano_id and its tile base URI.
Nearest query: compute the S2 covering of the search circle (a few cells), range-scan each, filter by true distance and freshness, return the best. Cell-prefixed keys spread load geographically; dense city cells can be split to a finer level.
Tile paths: tiles/{pano_id}/{pipeline_version}/{z}/{x}/{y}.webp. Paths are immutable, so CDN caching is simple and invalidation is never needed.
5. Spikes and consistency
Spikes
- Object storage scales horizontally for writes; the API is stateless with session state in the DB, so it autoscales on QPS.
- Workers autoscale on backlog age, not CPU.
- Admission control: per-device and per-depot token buckets, plus priority lanes (for example, retries of failed files before new runs). The vehicle's disk is the final buffer.
Eventual consistency
- The pipeline is at-least-once, so every stage is idempotent: deterministic tile paths, upserts keyed by
capture_id, and status transitions that only move forward via compare-and-set. - Publish order: write all tiles first, then commit the metadata row that references them. Readers never see a panorama with missing tiles.
- A reconciliation job re-enqueues captures stuck beyond an SLA and expires abandoned sessions.
- Processing failures retry with backoff, then go to a dead-letter queue with alerts. Raw data is never deleted because processing failed.
6. Trade-offs
- Direct-to-storage upload vs. proxying: direct saves enormous compute and bandwidth, but requires smarter clients and post-hoc validation.
- Bigtable-style vs. Spanner-style store: the first is cheaper with very high write throughput; the second gives transactional publish swaps and global consistency. A reasonable split is a wide-column store for the capture log and index, and a transactional store for the small "what is published" table.
- Cold storage for raw data: tier raw files to archival classes after processing to control the dominant cost, accepting slower reprocessing.
- Tile precomputation vs. on-demand: precompute the pyramid for fast reads at the cost of storage; lazily generate rarely viewed zoom levels if cost becomes a concern.
7. Common mistakes
- Streaming image bytes through application servers.
- Sizing from "millions of images" without converting to bytes per second and peak.
- Scaling workers on CPU rather than backlog.
- Mutating tile paths in place, which forces CDN invalidation.
- Publishing metadata before tiles exist.
- Using raw lat/lng range queries instead of a cell-based index.
- Omitting privacy blurring, checksum verification, or a quarantine path.