Time Series Database Write Path
Step through TSDB ingestion, WAL durability, MemTable buffering, flushes, and compaction pressure.
Time Series Database Write Path
Follow an IoT batch from sensor arrival to durable acknowledgement and background storage cleanup. Change workload shape, batch size, WAL policy, tag cardinality, and MemTable size to see why fast ingestion still needs careful storage management.
Batch arrives from IoT devices
A gateway groups timestamped readings so the TSDB can amortize protocol overhead and write the WAL sequentially.
Formula Trace
Teaching estimates use the selected workload. They are not vendor benchmarks.
Pressure Readouts
These signals show why a write path can accept data and still build background work.
Storage Outcome
SSTables are immutable. Compaction trades background I/O for fewer overlapping files and better read behavior.
Technical Accuracy Notes
- A durable write path normally appends to a write-ahead log before acknowledging the client. Some systems acknowledge before an immediate disk sync for lower latency, but that changes the failure window.
- The MemTable is an in-memory sorted or indexed buffer. It improves recent writes and reads, but it must eventually flush to immutable disk files or chunks.
- SSTable is an LSM-tree term. Real TSDBs may call these files segments, shards, chunks, or blocks, but the idea here is immutable time-organized storage plus background cleanup.
- Compaction does not make writes free. It shifts work into background I/O so reads scan fewer overlapping files and storage can reclaim duplicate, old, or expired records.
Formulas And Units
points_per_sec = devices / sample_interval_s. This assumes one point per device per interval.batches_per_sec = points_per_sec / batch_size. Large batches reduce write calls, but they add average batch-fill wait.ack_latency_ms ~= batch_wait_ms + wal_sync_ms + memtable_insert_ms. Network, replication, and product internals are outside this teaching estimate.flush_interval_s = memtable_limit_MB / memtable_growth_MBps. Small MemTables or high-cardinality metadata create more frequent flushes.physical_MB_per_hour ~= points_per_sec x bytes_per_point x compression_ratio x storage_amp x 3600 / 1e6.
Design Lessons
- Batch writes when the application can tolerate the added wait. Dashboards often benefit; alarms may need smaller batches or a separate fast path.
- Control tag cardinality. A unique request id, firmware hash, or free-form location label in the series key can create many series and large indexes.
- Measure compaction debt during load tests. A system can show low ingest latency while falling behind on background storage work.
- Separate observed time, receive time, and ingest time when late data or clock drift matters.
Practice Prompts
- Select Factory burst and reduce the MemTable to 16 MB. Explain why the SSTable count rises.
- Select Fleet labels drift and switch from high-cardinality labels to controlled tags. Compare active series and read amplification risk.
- Select Delayed backfill and turn compaction off. Identify which metric warns that future range queries will suffer.
- Change WAL sync from group commit to fsync each batch. Explain the durability and latency tradeoff.
Related Resources
Use these after the write-path lab to connect ingestion with modeling, queries, and compression.