Prompt
How do I choose time-series database architecture for multi-device ingestion?
Latest observation
Choosing a time-series database architecture for multi-device ingestion depends mostly on your write rate, query patterns, retention needs, and operational constraints. The right design is usually less about the database brand and more about the ingest path + storage layout + downsampling + scale strategy.
1) Start with the main workload questions
Ask these first:
- How many devices?
- Hundreds, thousands, millions?
- How often do devices write?
- Every second, every minute, bursts?
- How large is each event?
- A few numeric fields vs. large payloads
- What queries matter most?
- Latest reading per device?
- Range queries over time?
- Aggregations across device groups?
- Alerts on streaming data?
- How long do you retain raw data?
- Days, months, years?
- Do you need strong consistency or is eventual consistency okay?
- Is data mostly append-only?
- Most time-series systems work best that way.
- What operational level can you support?
- Single node, replicated cluster, managed cloud service?
2) Common architecture patterns
A. Single-node or single-shard architecture
Best for:
- Small to medium ingest
- Simple ops
- Proof of concept
Typical setup:
- Devices → API ingestion service → TSDB
- Maybe a queue in front if bursts occur
Pros:
- Simple
- Low operational overhead
Cons:
- Limited horizontal scale
- Single point of failure if not replicated
Use when:
- You have modest write volume and simple querying.
B. Queue/buffered ingest architecture
Best for:
- Bursty device traffic
- Unreliable device connections
- Need to smooth spikes
Typical setup:
- Devices → load balancer / ingestion API → Kafka / Pulsar / Kinesis → TSDB writers
Pros:
- Absorbs spikes
- Decouples device traffic from storage
- Easier retries and backpressure
Cons:
- More moving parts
- Added latency
- More operational complexity
Use when:
- Multi-device ingestion is variable or spiky.
C. Horizontally scaled distributed TSDB
Best for:
- High cardinality
- Large device fleets
- High write throughput
- Large retention windows
Typical setup:
- Devices → ingest layer → partitioned distributed storage
Important design choice:
- Partition by device ID or tenant + device ID
- Sometimes partition by time bucket + device hash
Pros:
- Scales out
- Handles large fleets better
- Fault-tolerant if replicated
Cons:
- More complex schema/partitioning
- Rebalancing/sharding can be tricky
- Cross-partition queries cost more
Use when:
- You expect large-scale ingestion or multi-tenant growth.
3) Partitioning: the most important decision
For multi-device time-series data, choose a partition key that supports both ingest and query patterns.
Good options:
- device_id
- tenant_id + device_id
- device_group + device_id
Time-based partitioning:
Often use time partitions too:
- Daily, weekly, or monthly partitions
- Helps with retention and pruning old data
Best practice:
Use both:
- Hash/device-based partitioning for write distribution
- Time-based bucketing for pruning and retention
Example:
- Partition by
hash(tenant_id, device_id) - Within that, store data in daily partitions or chunks
This helps:
- Even write load
- Fast queries for a time window
- Easy deletion/TTL
4) Schema design for time-series data
Typical dimensions:
timestampdevice_idtenant_id- metrics/fields
- tags/labels
Avoid:
- Too many high-cardinality tags unless the DB handles them well
- Overloading the primary key with unnecessary dimensions
- Storing huge JSON blobs if you need analytical queries
Prefer:
- Narrow rows for numeric readings
- Separate metadata dimension table for device info
- Tags for query filtering, but keep them controlled
5) Handle high cardinality carefully
Multi-device systems often create high cardinality:
- many devices
- many labels
- many unique metric series
This can stress TSDBs.
Mitigations:
- Avoid unlimited tag explosion
- Limit dynamic labels
- Normalize device metadata outside the hot path
- Use indexing selectively
- Consider series cardinality limits and quotas
6) Write path design
A robust write path usually looks like this:
- Device sends data
- Ingestion service authenticates and validates
- Data is batch-accepted
- Optional queue buffers writes
- Writer service batches inserts into TSDB
- ACK only after durable acceptance
Best practices:
- Batch writes per device or partition
- Use idempotency keys if duplicates are possible
- Compress payloads
- Validate timestamps
- Reject obviously bad data early
- Apply backpressure when overloaded
7) Query path design
Think about the common query types:
Latest value per device
- Requires efficient “last value” access
- May benefit from materialized views or cache
Range queries
- Time partitioning is very helpful
- Chunking and compression matter
Aggregations
- Precompute rollups or downsampled tables
- Use continuous aggregates/materialized views
Fleet-wide monitoring
- Use indices/labels for device group, region, tenant
8) Retention and downsampling
A good TSDB architecture usually has multiple data tiers:
- Raw hot data: 1s or sub-second granularity, short retention
- Downsampled data: 1m/5m/1h aggregates, longer retention
- Archive: cheap object storage or cold storage
This reduces storage cost and query load.
Example:
- Raw: 30 days
- 1-minute aggregates: 1 year
- Archive: 5 years
9) Choose between relational extensions and purpose-built TSDBs
Use PostgreSQL + TimescaleDB or similar if:
- You need SQL
- Moderate scale
- Simpler operations
- Strong relational joins with device metadata
Use purpose-built TSDBs if:
- Very high ingest
- Very high cardinality
- Large-scale fleet
- Heavy time-series optimization needed
Use log/analytics systems if:
- Data is more event-oriented than metric-oriented
- You need flexible schema and analytics at scale
10) Reliability features to include
For multi-device ingestion, design for failure:
- Retry-safe ingestion
- Duplicate detection or deduplication
- Dead-letter queue for malformed data
- Per-device rate limiting
- Multi-AZ replication
- Backup and restore
- Schema evolution handling
- Clock skew handling
11) Practical decision guide
Choose a simpler architecture if:
- Under ~10k devices
- Moderate write rate
- Mostly dashboard queries
- Small team/ops budget
Choose buffered distributed architecture if:
- Bursty or unreliable devices
- Need durability before ingest commit
- High concurrency
- Multiple consumers of the stream
Choose distributed TSDB if:
- Millions of series
- Very high write throughput
- Large retention
- Need horizontal scale
12) A good default reference architecture
If you’re unsure, start with:
- Devices → API gateway/load balancer
- Ingestion service with auth + validation
- Message queue/stream for buffering
- Writer workers batching into TSDB
- Time-based partitions + device hashing
- Raw retention + downsampling pipeline
- Metadata store for device info
- Monitoring for lag, cardinality, write latency, and dropped points
That’s a strong baseline for multi-device ingestion.
13) Metrics to watch while designing
- Write ingestion rate
- End-to-end ingest latency
- Queue lag
- Storage growth rate
- Series cardinality
- Query latency by type
- Compaction/flush overhead
- Duplicate/write error rate
- Hot partitions / shard imbalance
If you want, I can also help you choose an architecture based on your exact situation if you share:
- number of devices
- event rate per device
- data size
- retention requirements
- query patterns
- cloud/on-prem preference