# Time-Series Databases

> Store and query timestamped measurements efficiently with TimescaleDB or InfluxDB. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/time-series-databases
Last updated: 2026-11-28

Store and query timestamped measurements efficiently with TimescaleDB or InfluxDB.

Advanced · about 3 hours · difficulty 3/5

Learn first: [NoSQL Families and When to Use Them](https://www.internhack.in/roadmaps/tracks/backend/nosql-fundamentals), [Writing SQL Queries](https://www.internhack.in/roadmaps/tracks/backend/sql-querying)

Metrics, sensor readings, stock ticks and application events share a shape: an ever-growing stream of **timestamped values** that are written once, rarely updated, and queried by time range with aggregation ("average CPU per 5 minutes over the last day").

### Why a specialized store

A plain table works at first, but at millions of rows per day you want:

- **Time-based partitioning** (chunks per day or hour) so queries only touch relevant data.
- **Compression** tuned for sequential numbers, often 10x or more.
- **Retention policies** that drop old raw data automatically.
- **Downsampling** or continuous aggregates that keep hourly rollups after raw data expires.

### Common options

- **TimescaleDB**: a PostgreSQL extension. You keep SQL, joins and your existing tooling, and gain hypertables, compression and continuous aggregates. The easiest step for teams already on Postgres.
- **InfluxDB**: a purpose-built time-series database with its own ingestion protocol, popular for IoT and monitoring.
- **Prometheus**: specialized for application metrics scraping, covered in observability.
- **ClickHouse**: a columnar analytics database often used for large event and log analytics.

### Modeling tips

Separate **tags/labels** (low-cardinality dimensions like region or device type) from **fields** (the measured numbers). High-cardinality labels such as user ids can explode index size in some engines.

You are ready to move on when you can ingest a simulated sensor stream, query 5-minute averages over a day, and configure a retention policy.

## Key concepts

- **Time-based partitioning**
- **Retention and downsampling**
- **TimescaleDB hypertables**
- **InfluxDB**
- **Tags vs fields and cardinality**
- **Columnar analytics (ClickHouse)**

## Mini project

Build a small IoT ingest API that writes readings into TimescaleDB, exposes a time-bucketed chart endpoint and drops raw data older than 7 days.

## Check yourself

Why is using a user id as a tag a potential problem in a time-series database?

## Free resources

- [Timescale documentation](https://docs.timescale.com/) (Timescale)
- [InfluxData documentation](https://docs.influxdata.com/) (InfluxData)

Previous: [Graph Databases with Neo4j](https://www.internhack.in/roadmaps/tracks/backend/graph-databases) · Next: [Full-Text Search Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/full-text-search-basics)

## More in Beyond Relational: NoSQL and Search

- [NoSQL Families and When to Use Them](https://www.internhack.in/roadmaps/tracks/backend/nosql-fundamentals)
- [Document Databases with MongoDB](https://www.internhack.in/roadmaps/tracks/backend/mongodb)
- [Key-Value Stores and DynamoDB](https://www.internhack.in/roadmaps/tracks/backend/key-value-dynamodb)
- [Wide-Column Stores: Cassandra and ScyllaDB](https://www.internhack.in/roadmaps/tracks/backend/cassandra-wide-column)
- [Graph Databases with Neo4j](https://www.internhack.in/roadmaps/tracks/backend/graph-databases)
- [Time-Series Databases](https://www.internhack.in/roadmaps/tracks/backend/time-series-databases)
- [Full-Text Search Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/full-text-search-basics)
- [Search Engines: Elasticsearch and OpenSearch](https://www.internhack.in/roadmaps/tracks/backend/elasticsearch-opensearch)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
