Sign in to keep reading
“Time-Series Metrics Ingestion” is free with an account. Your progress and bookmarks follow you across devices.
Sign in to continueNEW: ML Mock & Coaching with a 20+ year experience coach. Save $20 on sessions for Premium.ML Mock & Coaching now available
NEW: ML Mock & Coaching with a 20+ year experience coach. Save $20 on sessions for Premium.ML Mock & Coaching now available
Ingest, store, and query millions of time-stamped data points per second using agent-based collection, Kafka buffering, and multi-resolution rollups.
“Time-Series Metrics Ingestion” is free with an account. Your progress and bookmarks follow you across devices.
Sign in to continueEvery system you build generates metrics. Request latency, CPU usage, error rates, business events like signups or purchases -- they all share the same shape: a value, a timestamp, and some labels describing what was measured. Monitoring, analytics, and IoT systems all revolve around ingesting these time-stamped data points at massive scale, storing them efficiently, and supporting both real-time dashboards and historical range queries.
Traditional relational databases are poorly suited for this workload. They lack the write throughput for high-frequency inserts and the query optimization for time-range scans. A PostgreSQL instance that comfortably handles your application's CRUD operations will buckle under a million metrics per second. That is why purpose-built time-series databases (TSDBs) exist -- and understanding how they work will show up in many system design interviews.
A typical time-series metrics system has four stages, each solving a specific problem in the data flow:
Metrics sources emit data points. Every service, server, and device in your infrastructure produces metrics -- request latency histograms, CPU utilization gauges, business event counters.
Collection agents run on each host. An agent (like Prometheus Node Exporter, Telegraf, or a custom sidecar) buffers metrics locally, aggregates where possible, and forwards them in compressed batches. This is important: without a local agent, every service would need to handle network failures, retries, and batching itself. The agent centralizes all that delivery logic.
Kafka acts as an ingestion buffer. This is the same pattern you see in Scaling Writes -- Kafka decouples the rate at which producers emit metrics from the rate at which the TSDB can consume them. During traffic spikes, Kafka absorbs the burst. If the ingestion service falls behind, messages are retained (hours or days) until the consumer catches up. Partitioning by metric name or source ensures ordered processing within each partition.
The TSDB stores and indexes the data for both real-time queries and historical analysis. InfluxDB, TimescaleDB, Prometheus, and ClickHouse are all optimized for this: append-heavy writes, time-range scans, and aggressive compression. Each database makes different architectural trade-offs -- see Choosing a TSDB below for a comparison framework.
See it in practice: The Ad Click Aggregator question is the canonical time-series ingestion problem -- you design a pipeline that ingests millions of click events per second, stores them in time-series format, and produces real-time and historical aggregations. The Webhook question also uses Kafka buffering to absorb delivery-result writes. The Pub/Sub Messaging pattern covers Kafka internals (topics, partitions, consumer groups) in depth.
Before data reaches your pipeline, you need to decide how agents collect it. There are two fundamentally different approaches, and many production systems use both.
| Push vs Pull Collection | |||
|---|---|---|---|
| Model | How It Works | Best For | Example Tools |
| Push | Each app/agent sends metrics to a central collector as events happen | High-frequency events, logs, short-lived jobs that may disappear before a scraper visits | StatsD, Telegraf, OpenTelemetry Collector |
| Pull | A central scraper periodically fetches metrics from each target's /metrics endpoint | Infrastructure monitoring, long-running services with stable endpoints | Prometheus, Thanos |
Push gives you flexibility -- applications can emit metrics at any frequency, and you can collect from ephemeral containers or serverless functions that might not exist long enough to be scraped. The downside is that the collector becomes a potential bottleneck and single point of failure.
Pull gives you control -- the scraper decides the collection interval, which prevents a misbehaving service from flooding the system with metrics. It also makes service discovery straightforward: register targets, and Prometheus will find them. The downside is that pull doesn't work well for short-lived processes or when you need sub-second granularity.
Most production monitoring stacks combine both: Prometheus pull-scraping for infrastructure and service metrics, plus a push gateway or OpenTelemetry pipeline for events and traces.
See it in practice: In Uber, driver location updates are pushed at high frequency since vehicles are constantly moving and you cannot wait for a scraper. In the CI/CD Pipeline question, build metrics from short-lived CI runners must be pushed because the runners terminate after the job completes. The Stream Processing and Real-Time Aggregation pattern covers how push-based event streams feed real-time computation.