Prompt

How do I shard a time-series database for many devices?

Technology / Databases1 observationLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

Sharding a time-series database for many devices usually comes down to optimizing for two things:

  1. write throughput — lots of incoming device data
  2. query locality — most queries ask for data from a device or group of devices over a time range

A good sharding strategy for this kind of workload is usually device-based partitioning with time inside each shard.


Common sharding patterns

1. Shard by device ID

Use a hash of device_id to assign each device to a shard.

Example:

  • shard = hash(device_id) % N

Pros

  • Easy to distribute writes evenly
  • Queries for a single device hit only one shard
  • Simple to implement

Cons

  • If some devices are much “hotter” than others, one shard can still become overloaded
  • Time-range queries across many devices need fan-out to multiple shards

This is often the default starting point.


2. Shard by time

Partition by time windows like day, week, or month.

Pros

  • Efficient retention and archival
  • Easy to delete old data
  • Great for queries over recent data only

Cons

  • Very bad for write balancing if all new data goes into the latest partition
  • Not ideal if many devices write simultaneously
  • Can create a hot shard/partition problem

Usually time partitioning alone is not enough for a large multi-device system.


3. Composite sharding: device + time

This is often the best approach.

Typical design

  • First shard by device_id or tenant_id + device_id
  • Then within each shard, partition by time buckets

Example key

  • shard_key = hash(device_id) % N
  • storage layout inside shard: device_id / yyyy-mm-dd

Pros

  • Balances write load across shards
  • Keeps per-device queries local
  • Makes retention easier via time partitions
  • Avoids huge single partitions

Cons

  • More operational complexity
  • Cross-device queries may still fan out

Practical recommendations

If most queries are “get one device’s recent history”

Use:

  • hash(device_id) for shard assignment
  • time-based partitions inside each shard

This is usually the best fit.


If you have tenants/customers and many devices per tenant

Use:

  • hash(tenant_id + device_id) if you need balance across all devices
  • or hash(tenant_id) if you want tenant data isolated per shard

If large tenants exist, sharding only by tenant can create hotspots.

A safer pattern is often:

  • shard by tenant_id, then sub-shard by device_id for very large tenants

If some devices are extremely hot

Add a second level of sharding:

  • hash(device_id + salt) for writes
  • or split hot devices across multiple partitions

But only do this if needed, because it makes reads more complex.


Indexing and query design

Sharding alone is not enough. Make sure each shard can efficiently answer queries.

Inside each shard:

  • index by (device_id, timestamp)
  • store data clustered by time
  • use compression suitable for time-series data

This helps queries like:

  • SELECT ... WHERE device_id = ? AND timestamp BETWEEN ...

Retention and downsampling

For time-series data, plan for:

  • hot data: recent, frequently queried
  • warm data: older, less frequently queried
  • cold/archive data: long-term storage

A common setup:

  • raw data kept for 7–30 days
  • aggregated/downsampled data kept longer

Partitioning by time makes this easier.


Avoid these mistakes

  • Sharding only by time for high-write systems
  • Using too few shards early on
  • Using a shard count that is hard to change
  • Ignoring query patterns
  • Letting one shard own all recent writes
  • Not planning for rebalancing

Rebalancing strategy

Use consistent hashing or a virtual-node approach so you can add shards without moving everything.

Options:

  • consistent hashing
  • hash ring with virtual shards
  • range partitioning with split/merge

For many devices, consistent hashing is often the simplest operationally.


Simple rule of thumb

If you need one practical default:

  • Shard by hash(device_id)
  • Partition inside each shard by time
  • Index by (device_id, timestamp)
  • Use retention policies per time partition
  • Rebalance with consistent hashing or virtual shards

Example architecture

  • 64 logical shards
  • devices mapped by consistent hash
  • each shard stores monthly partitions
  • each partition indexed by device + timestamp
  • recent partitions on SSD, old partitions compressed or moved to object storage

If you want, I can also help with:

  1. a schema design for this,
  2. a sharding algorithm with examples,
  3. or advice for a specific database like Postgres, Cassandra, TimescaleDB, InfluxDB, or ClickHouse.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.