Dev tools
Time Series Database: What It Is and When to Use One
A time series database stores data points indexed by time, like metrics and sensor readings. How it works, when to use one, and the main options compared.
A time series database (TSDB) is a database built for data points that are each stamped with a time, such as server metrics every ten seconds, sensor readings every minute, or stock prices every millisecond. It's optimized for writing huge numbers of new points quickly, compressing them well, and answering questions over time ranges, like "average CPU per hour over the last week". You need one when time-stamped data arrives constantly and your main queries are about trends over time; for ordinary business records, a regular relational database is usually enough.
This guide explains what makes time series data different, how a time series database works, when to use one (and when not to), how a time series database vs relational database compares, and the best time series database options, including how TimescaleDB vs InfluxDB differ.
What Is Time Series Data?
Time series data is a sequence of measurements of the same thing over time. Each data point usually has:
- A timestamp: when the measurement was taken.
- One or more values: the measurement itself (temperature 21.4, CPU 63%, price 102.15).
- Labels or tags: what was measured (sensor ID, server name, region, stock symbol).
Common examples:
| Area | Time series data |
|---|---|
| Infrastructure monitoring | CPU, memory, request rates and latency for every server and container |
| Application monitoring | Errors, response times, queue lengths |
| Internet of things | Temperature, pressure, location and energy use from devices |
| Finance | Prices, trades and order book changes |
| Business analytics | Sign-ups, revenue and usage per hour or day |
| AI and LLM apps | Token usage, latency and cost per request |
Time series data has a recognizable pattern: it's written constantly, almost never updated, usually read in time ranges, and becomes less valuable as it gets older. A time series database is designed around exactly those habits.
How a Time Series Database Works
Most time series databases share a few design choices:
- Fast appends: new points are written to memory and a write-ahead log, then flushed to disk in batches. Prometheus, for example, groups incoming samples into two-hour blocks.
- Organized by time: data is partitioned into time chunks, so a query for "the last 24 hours" only reads the chunks for those hours.
- Heavy compression: consecutive values from the same series are similar, so compression techniques for timestamps and values shrink storage dramatically compared with storing each row separately.
- Time functions: built-in functions group data into time buckets (per minute, hour or day), fill gaps, and calculate rates and moving averages.
- Downsampling and retention: older data can be rolled up into averages (keep per-second data for a week, per-hour data for a year) and deleted automatically after a set period.
- High-cardinality handling: each unique combination of labels is a separate series; good TSDBs index labels so queries can filter millions of series quickly.
Here's what this looks like in TimescaleDB, which adds time series features to PostgreSQL. The table is created as a hypertable, and the query uses time_bucket to compute hourly averages (both from TimescaleDB's own documentation):
CREATE TABLE sensor_data (
time TIMESTAMPTZ NOT NULL,
sensor_id TEXT NOT NULL,
temperature DOUBLE PRECISION
) WITH (tsdb.hypertable);
SELECT time_bucket('1 hour', time) AS hour,
sensor_id,
AVG(temperature) AS avg_temp
FROM sensor_data
WHERE time > NOW() - INTERVAL '24 hours'
GROUP BY hour, sensor_id
ORDER BY hour DESC;Time Series Database vs Relational Database
A regular relational database such as PostgreSQL or MySQL can store time-stamped rows perfectly well. The difference shows up at scale:
| Relational database | Time series database | |
|---|---|---|
| Built for | Records that are created, updated and joined | Measurements appended over time |
| Typical writes | Mixed inserts and updates | Constant high-volume inserts, rarely updated |
| Typical reads | Look up and join individual records | Aggregate ranges of time across many series |
| Storage | Row by row; less compression | Columnar or time-chunked with heavy compression |
| Data lifecycle | Keep everything unless deleted | Built-in retention policies and downsampling |
| Time functions | Possible with SQL, but manual | Built in (time buckets, rates, gap filling) |
| Best for | Orders, users, invoices, application state | Metrics, events, sensor and market data |
The time series database vs relational database choice isn't all-or-nothing. If you already run PostgreSQL and your time series data is modest, a well-indexed table may be enough. If you're writing millions of points a minute or need months of history to stay fast and cheap, a TSDB pays off. Extensions like TimescaleDB sit in between: they keep PostgreSQL and its SQL, joins and tools, and add time series storage. Our comparison of Postgres vs MySQL covers the relational side.
When to Use a Time Series Database
If you're wondering when to use time series database software instead of your existing database, use one when most of these are true:
- Data arrives continuously, from many sources, at high volume.
- Nearly every query filters or groups by time.
- You need dashboards and alerts on recent data with fast responses.
- Old data can be summarized or deleted after a while.
- Storage costs matter and compression would help.
Stick with your existing relational database when:
- Data volume is small (thousands of points per minute, not millions).
- You need frequent updates, transactions across tables, or complex joins with business data.
- Time is just one column among many in records that represent things (orders, users), not measurements.
Best Time Series Database Options
There's no single best time series database; the right one depends on your workload, your team's skills and whether you want to manage it yourself. The main options:
| Database | Type | Query language | Strengths | Watch out for |
|---|---|---|---|---|
| InfluxDB 3 Core | Purpose-built TSDB, open source | SQL and InfluxQL | Real-time ingest, Parquet files, object storage support, fast queries on recent data | Historical querying, high availability and read replicas are Enterprise features |
| TimescaleDB (Tiger Data) | PostgreSQL extension | Full PostgreSQL SQL | Joins with business data, Postgres tools and ecosystem, hypertables and columnstore | Some features use the Timescale License rather than Apache 2.0 |
| Prometheus | Metrics system with built-in TSDB | PromQL | Standard for Kubernetes and infrastructure monitoring, alerting | Local storage is meant for recent data; long-term storage needs a remote backend |
| ClickHouse | Columnar analytics database | SQL | Very fast aggregations on huge data, also handles logs and events | General-purpose analytics engine rather than a dedicated TSDB |
| QuestDB | Purpose-built TSDB, open source | SQL with time extensions | High ingest speed, finance and market data | Smaller ecosystem |
| VictoriaMetrics | Prometheus-compatible TSDB | PromQL-compatible | Efficient long-term storage for Prometheus metrics | Focused on metrics monitoring |
| Cloud services (Amazon Timestream and others) | Managed | Varies | No servers to run | Vendor lock-in, costs grow with volume |
According to InfluxData's documentation, InfluxDB 3 Core is the open-source release of InfluxDB 3, with a diskless architecture that can use object storage, Parquet file persistence, an embedded Python engine for plugins, and query times under 10 ms for last-value queries. Prometheus's documentation describes its local storage as a time series database that can optionally integrate with remote storage systems for longer retention.
TimescaleDB vs InfluxDB
TimescaleDB vs InfluxDB is the most common head-to-head:
- Pick TimescaleDB if you already use PostgreSQL, want to join time series with relational data (users, devices, accounts) in plain SQL, and value Postgres tools, backups and extensions.
- Pick InfluxDB if you want a dedicated time series engine with its own ecosystem (such as the Telegraf collection agent), object-storage-based architecture, and a focus on real-time ingest and dashboards.
Both handle typical monitoring and IoT workloads well; the deciding factor is usually whether your team wants to stay inside PostgreSQL.
Open Source Time Series Database Choices
If you want an open source time series database you can self-host, InfluxDB 3 Core, TimescaleDB, Prometheus, QuestDB and VictoriaMetrics all have open-source editions, and ClickHouse is open source as well. Check each license before you build a commercial product on top: some projects use permissive licenses (Apache 2.0, MIT), while others keep certain features under source-available licenses or in paid editions.
For a small setup, such as monitoring a home lab or a few servers, Prometheus with Grafana is the most common starting point. For an app that already runs on PostgreSQL, adding TimescaleDB avoids running a second database.
Time Series Data in AI Applications
AI products generate a lot of time series data: tokens per request, latency, cost per user, error rates and GPU utilization. Storing these metrics over time is how you spot cost spikes, slow models and regressions after a prompt change. Many LLM observability tools use time series storage behind their dashboards; our guide to LLM observability explains which signals to track.
Time series also feed machine learning directly: forecasting demand, detecting anomalies in sensor data, and predicting failures all start from well-organized time-stamped history. And when you need similarity search over embeddings rather than ranges over time, that's a different specialized store; our explainer on vector databases covers it.
How to Choose: A Short Checklist
- Volume: how many points per second, and how many unique series (label combinations)?
- Queries: mostly recent dashboards, long-range analytics, or both?
- Joins: do you need to combine measurements with business data?
- Retention: how long must raw data stay, and can older data be summarized?
- Operations: will you run it yourself, or pay for a managed service?
- Ecosystem: does it work with your collectors, dashboards and alerting tools?
- License: is the license compatible with how you'll use it?
FAQ
What is a time series database used for?
It's used to store and analyze measurements taken over time, such as server metrics, application performance data, IoT sensor readings, financial prices and usage statistics. It powers monitoring dashboards, alerts, forecasting and trend analysis.
What is the best time series database?
It depends on the job. Prometheus is the standard for infrastructure metrics, TimescaleDB suits teams already using PostgreSQL, InfluxDB is a popular dedicated option for real-time data, and ClickHouse or QuestDB fit very large analytical or financial workloads.
Can PostgreSQL be used as a time series database?
Yes. Plain PostgreSQL handles moderate time series data with good indexing, and the TimescaleDB extension adds time-based partitioning, compression and time functions so it performs like a dedicated time series database at larger scale.
Is a time series database a NoSQL database?
Some are and some aren't. Several purpose-built TSDBs use their own storage engines and query languages, while others, like TimescaleDB, are built on relational databases and use SQL. Many modern TSDBs, including InfluxDB 3 and QuestDB, support SQL queries.
What is the difference between a time series database and a data warehouse?
A time series database is optimized for continuous, high-volume writes and fast queries over recent time ranges, such as live dashboards. A data warehouse is built for broad analytical queries across many kinds of business data, usually loaded in batches. Many companies use both.