Stream Processing Pipeline for High-Velocity Robot Sensor Data
System DesignModel answerLast updated
Design a fault-tolerant ingestion pipeline that sustains 2 GB/s of mixed telemetry from a distributed robot fleet with zero data loss and dual real-time and batch consumers.
Background
You are building the data backbone for a company that operates a large fleet of autonomous robots. Each robot continuously emits sensor readings, operational state changes, and occasional image captures. Your job is to design the platform that receives all of this data reliably, routes it to the right consumers, and stores it in a way that supports both real-time operations and long-term analysis.
What the System Must Do
- Throughput: Sustain 2 GB/s of inbound data under normal conditions. Bursts up to 3 GB/s must not cause data loss.
- Durability: A robot must not discard a batch until the platform has confirmed it was safely written. No silent drops.
- Scalability: Adding more robots to the fleet should not require manual capacity changes to the platform.
- Dual consumers: A real-time path must fire operational alerts within seconds. A separate batch path feeds analytical storage and machine learning workloads.
- Schema flexibility: Robot firmware updates change sensor payloads frequently. Downstream consumers must not break when new fields appear or old ones are retired.
Scale Assumptions
- Typical event size: 1 KB
- Daily ingest volume: approximately 170 TB
- Hot storage retention: 30 days
- Cold storage retention: indefinite
What Your Answer Should Cover
- Data path — trace the journey of a single event from robot to final storage
- Component choices — name the technologies you would use at each stage and explain why
- Flow control — describe how each layer handles backpressure, spikes, and downstream outages without losing data
- Storage and schema design — explain how you model the data for efficient querying and how you manage schema changes over time
You are not expected to write code. A clear architectural narrative with concrete technology choices, sizing rationale, and trade-off reasoning is what a strong answer looks like.
Hints
Hint 1
Before naming any technology, convert the throughput numbers into something you can reason about: events per second, broker disk write rate, daily bytes, and compressed storage at rest. Interviewers use your sizing math to judge whether your component choices are grounded.
Hint 2
Zero data loss end-to-end requires durability at the edge, not just in the cloud. Think about what happens when the network between a robot and the ingestion layer goes down for 30 minutes.
Hint 3
Real-time alerting and batch analytics have very different latency and throughput profiles. Sharing a single storage system for both usually means sacrificing one for the other. How do you serve both without coupling them?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Step 1: Turn Requirements into Numbers
Before picking any component, size the problem. This math drives every capacity decision that follows.
| Quantity | Calculation | Result |
|---|---|---|
| Sustained event rate | 2 GB/s ÷ 1 KB | ~2 M events/s |
| Peak event rate | 3 GB/s ÷ 1 KB | ~3 M events/s |
| Daily raw volume | 2 GB/s × 86,400 s | ~173 TB/day |
| 30-day hot storage (compressed) | 173 TB × 30 ÷ 7 (Parquet+zstd) | ~750 TB |
| Kafka disk write rate at RF=3 | 3 GB/s × 3 replicas | ~9 GB/s at peak |
Clarifying questions worth asking: What is the p99 alert latency target? (Assume 5 s.) Are images common or rare? (Assume rare but large, 100 KB–2 MB each.) Does per-robot event ordering matter? (Yes; global ordering does not.)
Step 2: Edge-to-Cloud Data Path
Robot
local disk spool (bounded ring buffer, hours of capacity)
│ gRPC/HTTP2, TLS, mTLS device identity, zstd-compressed batches
▼
L4 Load Balancer
▼
Stateless Ingestion Gateways (Go/Rust, autoscaled)
validate, quota-check, produce with acks=all
│
▼
Kafka Cluster (RF=3, min.insync.replicas=2, tiered storage)
├── telemetry.critical (faults, e-stops)
├── telemetry.sensor (bulk readings)
├── telemetry.state
└── telemetry.dlq
│
├──► Flink — real-time path
│ decode schema, evaluate alert rules, windowed aggregates
│ → alerting / ops dashboards
│
├──► Flink / Kafka Connect — lake sink
│ row→Parquet conversion, Iceberg tables on S3
│ → Spark, Trino, ML workloads
│
└──► ClickHouse — hot query layer (30-day window)
Durability contract. The gateway acknowledges a batch only after Kafka returns acks=all. The robot removes a batch from its local spool only after receiving that acknowledgment. Every batch carries a (robot_id, boot_id, sequence_number) key, making producer retries idempotent. The result is at-least-once delivery with downstream deduplication, which in practice gives you exactly-once data.
Image handling. Large image blobs bypass Kafka entirely using the claim-check pattern. The robot uploads directly to object storage via a presigned URL, then sends a small image_ref event containing the URI, hash, and size. This keeps Kafka tuned for small records.
Step 3: Component Sizing
Kafka brokers. Each broker handles roughly 150–200 MB/s of producer traffic once replication and consumer fan-out are counted. At 9 GB/s peak write rate, you need approximately 50–60 brokers with headroom. Provision around 1,024 partitions (assuming ~10 MB/s per partition at peak), keyed on robot_id to preserve per-robot ordering. Keep 24 hours on local disk and extend to 3–7 days with tiered storage (S3-backed) for replay.
Pulsar trade-off. Pulsar separates compute from storage and rebalances partitions more gracefully. Kafka wins on ecosystem maturity and operational tooling. Pick one and justify the call.
Ingestion gateways. Stateless services, each handling 200–300 MB/s. You need roughly 15–20 instances at peak, scaling on CPU and connection count.
Flink. Use event-time semantics with checkpoints to S3. Exactly-once writes to Iceberg use two-phase commits tied to snapshot commits. Scale consumers on Kafka consumer lag.
Storage tiers. ClickHouse holds the 30-day hot window (~750 TB compressed), sharded by robot_id. Iceberg on S3 is the permanent system of record; after 30 days, objects lifecycle to S3 Infrequent Access or Glacier Instant Retrieval.
Step 4: Backpressure and Flow Control
Handle backpressure at every layer so no single point can cause data loss.
-
Edge spool. Each robot maintains a bounded ring buffer on local disk sized for several hours of production. When the network or gateway is unreachable, the robot buffers and retries with exponential backoff plus jitter. This is the primary mechanism that makes zero loss achievable during cloud-side outages.
-
Gateway pushback. When the Kafka producer buffer fills or produce latency spikes, gateways return
429 / RESOURCE_EXHAUSTEDwith aRetry-Afterheader. Robots hold data locally and do not drop it. gRPC flow-control windows bound in-flight bytes per connection. The gateway never silently discards. -
Kafka as a shock absorber. Consumers (Flink, ClickHouse sink) are fully decoupled from producers. If the lake sink or ClickHouse goes down, data accumulates as consumer lag. Kafka retention must exceed worst-case outage plus catch-up time. An outage in one consumer path does not affect alerting.
-
Priority lanes. The
criticaltopic has dedicated partitions, consumers, and broker quotas. Robots drain critical events first from their spool. During bursts, alerts stay fast while bulk sensor data waits. -
Consumer autoscaling. Scale Flink task managers on lag metrics. Provision consumer throughput at roughly 2× ingest rate so a backlog clears in an acceptable window.
Step 5: Data Modeling and Schema Evolution
Schema registry. Use Confluent Schema Registry or Apicurio with Protobuf or Avro, enforcing BACKWARD_TRANSITIVE compatibility. New fields must be optional or carry defaults; fields are never renamed or retyped in place. Run compatibility checks in robot firmware CI so an incompatible schema cannot reach the fleet. Every record carries a schema_id so consumers decode with the writer's schema and project onto their own reader schema.
Wire vs. storage format. Use row-oriented Avro or Protobuf on the wire and in Kafka — cheap to produce per record and schema-aware. Use columnar Parquet in the lake. Parquet gives column pruning, predicate pushdown, and 5–10× compression on repetitive sensor data. Flink handles the row-to-columnar conversion.
Iceberg table design.
| Table | Content |
|---|---|
sensor_readings | High-volume numeric readings |
state_logs | Discrete state transitions |
image_index | URIs and image metadata |
- Partitioning:
days(event_time),bucket(64, robot_id) - Sort order:
(robot_id, event_time)to cluster reads by robot - Schema evolution: Iceberg tracks columns by ID rather than name, so adding or dropping columns never rewrites existing data files
Common Mistakes to Avoid
- Skipping edge buffering. Claiming zero data loss without a local spool on the robot means any network blip causes loss. Durability must start at the source.
- Single storage layer. Sending real-time alert consumers and analytical batch jobs to the same ClickHouse or database almost always creates contention. Separate them early.
- Storing images in Kafka. Multi-MB blobs destroy Kafka throughput and hit the default message size limit quickly. Always use claim-check for large payloads.
- Ignoring schema compatibility in firmware CI. Schema breaks discovered at runtime affect the entire fleet simultaneously. Catch them before deployment.
- Under-provisioning Kafka retention. If retention is shorter than a realistic downstream outage plus catch-up time, you will lose data during incidents.