Hardware Metrics Pipeline: Ingest, Store, and Query at Scale
System DesignModel answerLast updated
Design an end-to-end telemetry platform that collects per-device metrics at two resolutions, serves trend dashboards, supports raw drilldowns, and safely exposes a natural-language query interface.
Hardware Metrics Pipeline: Ingest, Store, and Query at Scale
You are asked to design a platform that continuously collects performance metrics from a large fleet of compute accelerators and makes those metrics available for both long-range trend analysis and deep per-device investigation.
Requirements
- A collection agent must produce two streams: one sample every 30 seconds and one sample every 1 second.
- Operations staff need a dashboard showing three months of trend data.
- During incidents, staff must be able to drill down to raw one-second detail for a single device.
- The analytics layer may later be extended with a natural-language SQL interface. That interface must respect per-user data permissions and must not allow generated queries to read data the user cannot see or to trigger runaway scans.
Constraints and Assumptions
- Treat this as an observability platform, not a model-training or feature-store problem.
- You may assume: collection agents on each host, a message broker, a durable data lake or warehouse, and an internal dashboard frontend.
- State your own scale assumptions; keep them approximate unless numbers are given.
- Optimize for data correctness, operational simplicity, and cost control.
Good Clarifying Questions
- How many hosts and devices are in scope today, and what is the expected growth rate?
- Which metrics are required (utilization, memory, thermals, error counters, power, job/tenant ownership)?
- How long must one-second raw data be retained versus the coarser aggregates?
- Are dashboards internal-only, customer-facing, or subject to compliance requirements?
- What identity and access-control system already exists across teams and tenants?
Part 1 — Collection and Ingestion
Explain how metrics travel from the device to durable storage. Cover: agent design, local buffering and retry, schema evolution, deduplication, and how the system behaves when a host or the network fails.
Part 2 — Storage Layout and Query Serving
Design the storage tiers and query path that support both three-month trend dashboards and per-second incident investigation. Address partitioning, precomputed rollups, query routing, and how late-arriving data is handled.
Part 3 — Access-Controlled Natural-Language Query Interface
Describe how you would extend the platform with a natural-language-to-SQL assistant. Focus on enforcing data access rules, preventing the model from generating dangerous or expensive queries, and where each control must live.
Hints
Hint 1
Estimate the raw data rate before designing anything else — the volume gap between 1-second and 30-second data drives almost every storage and cost decision downstream.
Hint 2
The 1-second stream and the trend stream have opposite access patterns: raw data is written constantly but read rarely, while rollups are read constantly but written infrequently. Design them as separate physical tiers rather than filtering a single table.
Hint 3
For the SQL assistant, never rely on a prompt to enforce access control. The warehouse engine must enforce permissions independently of whatever SQL the model generates.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This problem has three distinct sub-problems that share a data pipeline: high-throughput ingestion, tiered storage with precomputation, and LLM-as-an-untrusted-client safety. Address them in order, but let the size estimate drive every architectural choice.
Clarify and Size First
State assumptions up front and flag that the interviewer can adjust them.
- Fleet: ~100k devices across ~12,500 hosts (8 devices per host), growing up to 3x.
- Metrics: ~30 per device (utilization, clock speed, memory used/free, power draw, temperature, error counters, network throughput). Every sample is labeled with
host,device_id,cluster,tenant, andjob_id. - 1-second write rate: 100k × 30 = 3 million samples/second. At ~100 bytes uncompressed, that is ~300 MB/s, or ~26 TB/day. With columnar compression (10–20x), storage cost falls to roughly 1.5–2.5 TB/day.
- 30-second rate: 1/30 of the above. Three months of 30-second data is only a few TB total.
- Retention targets: 1-second raw for 14–30 days; 30-second for 90+ days; hourly rollups for years.
Key design insight: one-second data is 30x more expensive to store than the aggregate stream and is almost never read except during active incidents. Treat the two resolutions as separate tiers from the start.
Part 1 — Collection and Ingestion
Agent design
Run one agent per host as a system service (DaemonSet or systemd unit). It reads device metrics via the vendor management library directly — not by shelling out to a command-line tool once per second, which is too slow and too expensive.
The agent produces two outputs locally:
- The raw 1-second stream, one row per device per metric.
- A 30-second aggregate computed in-process: min, max, mean, last, and count per window. Computing aggregates locally means the 30-second series is intact even if the 1-second data is dropped during high pressure.
Each sample is enriched at the source with job and tenant metadata pulled from the scheduler. This must happen at collection time because job ownership is ephemeral and cannot be reconstructed later.
Buffering and retry
The agent writes batches every 1–5 seconds (compressed, e.g., protobuf + zstd) to a bounded on-disk ring buffer before forwarding to the broker. The buffer should hold several hours of data per host (~1 GB is reasonable).
- The agent advances its write cursor only after the broker acknowledges the batch (at-least-once delivery).
- On buffer overflow, drop 1-second data first; preserve 30-second aggregates and error events. Emit a visible "samples dropped" counter.
- Retries use exponential backoff with jitter to prevent a thundering herd when a network partition heals.
The broker (Kafka or Pulsar) partitions by cluster/host to preserve per-host ordering, with replication factor 3 and acks=all.
Deduplication
Every batch carries an idempotency key: (host_id, agent_boot_id, sequence_number). The natural key for each sample is (device_id, metric_name, timestamp). Stream consumers deduplicate within a sliding window; lake compaction deduplicates by natural key on write. Together, these give effectively-once semantics from at-least-once delivery.
Schema evolution
Register schemas in a central registry with a backward-compatibility rule: add optional fields only, never repurpose existing ones. Each record carries a schema_version field. New metrics arrive as new columns or as rows in a long/narrow (metric_name, value) side table for sparse signals. Unknown fields pass through to a raw landing zone rather than being silently dropped.
Failure modes summary
| Failure | Outcome |
|---|---|
| Host crash | On-disk buffer survives; at worst, seconds of in-memory data are lost |
| Network partition | Buffer absorbs outage; drains at a controlled rate-limit on recovery |
| Broker outage | Agents buffer locally; stateless gateways scale horizontally |
Send heartbeat events on a separate topic so the platform can distinguish "device is silent" from "data pipeline is broken."
Part 2 — Storage Layout and Query Serving
Three physical tiers
1. Hot store (1-second raw, last 24–72 hours)
A columnar real-time OLAP store (ClickHouse, Apache Druid/Pinot, or a TSDB such as VictoriaMetrics). Ordered by (cluster, device_id, timestamp). This tier serves live dashboards and active incident investigation. It is expensive per byte but fast to query.
2. Data lake (durable source of truth)
Iceberg or Delta Lake on object storage, written by a streaming job. Partitioned by date/hour and cluster, sorted by (device_id, timestamp). A compaction job merges small files into ~512 MB Parquet files. 1-second raw data expires via table-level retention after N days. This is cheap per byte and is the source for all rollup recomputation.
3. Rollup tables (30-second, 5-minute, 1-hour)
Precomputed by streaming jobs keyed on event time. Each rollup stores mergeable statistics: sum, count, min, max, and a quantile sketch (t-digest or DDSketch) for p95/p99. Never store plain averages — averaging averages across time windows is mathematically wrong. Rollups are also pre-grouped by cluster, tenant, and device model so common dashboard filters are free.
Query routing
A thin query-routing layer picks the coarsest table that satisfies the requested time range and granularity:
- 3-month trend: hourly rollup — 2,160 points per series, millisecond response.
- Last week, one cluster: 5-minute rollup.
- Incident drilldown (one device, a few hours): hot store or lake Parquet with partition pruning on
device_idandtimestamp. This scans one device's slice, not the whole fleet.
Handling late data
Late samples (from a host that buffered during an outage) trigger recomputation of affected rollup windows from the lake. A scheduled backfill job scans only the touched partitions. Dashboards show a data-completeness indicator (samples received vs. expected) so operators know when a rollup is still catching up.
Part 3 — Access-Controlled Natural-Language Query Interface
The core principle: treat the LLM as an untrusted query author. Every access control and safety check must be enforced by the platform independently of whatever the model generates. A carefully worded prompt is not a security boundary.
Access control
Queries execute under the end user's identity, never a shared service account. The warehouse enforces row-level security policies (e.g., tenant IN current_user_tenants()) and column masking at the engine level. Even if the model generates SELECT * FROM raw_metrics, the engine silently filters to the rows the user can see. Prompt injection cannot widen access.
Constrained schema context
The model is given a curated semantic layer: documented views, approved join paths, and metric definitions. The context is filtered to tables and columns the requesting user can access, so schema metadata for other tenants is never visible to the model. This also reduces hallucination because the model sees fewer irrelevant objects.
Static SQL validation
Parse the generated SQL into an AST (e.g., with sqlglot) before execution and enforce:
- Single
SELECTonly — no DDL, DML, multi-statements, stored procedure calls, or external table functions. - Only allowlisted views and tables.
- A mandatory time-range predicate must be present.
- Queries against 1-second raw tables must also include a
device_idor host filter and a window under a configurable maximum (e.g., 6 hours). Queries that do not satisfy this are rewritten to the appropriate rollup table, or rejected with an explanation. - Inject a
LIMITclause on all results.
If any rule fails, return the violation to the LLM with a structured error and ask it to regenerate — do not silently drop the query.
Cost gate
Run EXPLAIN (or the warehouse equivalent) to estimate bytes scanned before execution. Reject or prompt for user confirmation above a threshold (e.g., >100 GB). Offer a reformulation suggestion: "This query would scan 3 months of raw data. Would you like to use the hourly rollup instead?"
Common mistakes to avoid
- Relying on prompt-level instructions like "only query data you are allowed to see" — the model can be bypassed or confused.
- Using a shared service account that has broader access than the end user.
- Skipping the cost gate and allowing a naive
SELECT *over months of 1-second data to run to completion. - Storing averages in rollups instead of mergeable sketches, then surfacing wrong p99 numbers in the dashboard.