KatInterview

Build a Multi-Tenant Time-Series Telemetry Backend

System DesignModel answer
MediumModel answerSystem Designtime-seriesingestiondownsampling

Last updated

Design a telemetry backend that ingests about 1M samples per second from many services, answers aggregate queries fast, runs alerts, and keeps data cheaply for months with tenant isolation.

Scenario

Your company runs many services across several data centers. Each service emits numeric telemetry: counters, gauges and histograms, each labeled with key/value tags. Design the backend that stores this telemetry and serves it to dashboards and alert rules. Several internal teams (tenants) share the platform.

Requirements

Functional

  • Accept tagged measurements, for example cpu_usage{host="web-01", env="prod"}.
  • Offer a query interface for aggregations such as sum, average and 99th percentile over a time window.
  • Support simple alert rules that fire when a query result crosses a threshold for some duration.

Non-functional

  • Writes must stay highly available.
  • Sustained ingest of about 1 million samples per second.
  • Data older than 30 days must be stored in a space-efficient way.
  • Tenants must be isolated: one tenant's heavy load or query must not degrade others.

What to cover

  1. API design: the write payload and the query interface.
  2. Data model: how tagged series are identified, indexed and laid out on disk.
  3. Storage strategy: choice of storage engine, retention and downsampling.
  4. Architecture: the path from a measurement leaving a service to a query result or an alert.

Example interaction

Write: POST /v1/write with body {"name": "http_requests", "tags": {"service": "auth"}, "value": 12, "ts": 1672531200}

Read: GET /v1/query?q=sum(http_requests{service='auth'})&start=1h&end=now

Discussion points to address

  • How do you cope with tags that have huge numbers of distinct values (e.g. user_id)?
  • How does the system absorb traffic spikes?
  • During a network partition, how do you trade consistency against availability?

Hints

Hint 1

Start with numbers: 1M samples/sec at a 10s reporting interval implies roughly 10M active series. Estimate bytes per sample before and after time-series compression to see which part (storage, index, query fan-out) is actually the bottleneck.

Hint 2

Treat each unique combination of name plus tags as one series, and use an inverted index (tag pair to sorted list of series IDs) so a selector becomes an intersection of lists. Think about what that implies when a tag has unbounded values.

Hint 3

For long retention, keep rollups that can be re-aggregated correctly (sum, count, min, max, or a mergeable sketch) rather than only averages or precomputed percentiles. Put a durable log in front of ingestion to absorb bursts.