Design canvas: pick a workload, ship a config
Every TSDB choice — scrape interval, label set, chunk size, retention, recording rules, downsampling — is a knob, and the right settings depend entirely on the workload's cardinality, write rate, and query range; some workloads have no honest TSDB configuration at all.
We have all the pieces. Now you build.
Scene 12
Design canvas: pick a workload, ship a config
- Watch
- Try it
- Predict
- Capture
Workload A is on the canvas: 1000-host fleet alerting, 50 metrics per target, 15s scrape. Default config loads — chunk samples 120 (scene 4), head retention 3h (scene 5), one recording rule (scene 9), two downsampling tiers (scene 9). The verifier turns it green: ~3 GB RAM, ~6 GB/day disk, ~50 ms typical query.
Highlighted lines are the ones running in the diagram right now.
def verify(workload, config):bomb = detectCardinalityBomb(workload, config)if bomb:return refuse(bomb.reason) # wrong toolram = projectRam(workload, config)disk = projectDisk(workload, config)latency = projectQueryLatency(config, queryRange)fits = ram.mb <= ram.budget and disk.okwarnings = ram.warnings + disk.warningsreturn Verdict(fits, ram, disk, latency, warnings)
def projectRam(workload, config):series_count = product(cardinality(label) for label in config.labelSet) * workload.metricsPerTargethead_bytes = series_count * BYTES_PER_HEAD_CHUNKindex_bytes = series_count * BYTES_PER_POSTINGS_ENTRYram_mb = (head_bytes + index_bytes) / MBif ram_mb > RAM_BUDGET_MB:return overshoot(ram_mb, RAM_BUDGET_MB)return ok(ram_mb)
UNBOUNDED = {'user_id', 'request_id', 'trace_id','session_id', 'email', 'ip',}def detectCardinalityBomb(workload, config):for label in config.labelSet:if label in UNBOUNDED:return Bomb(reason=f'{label} is unbounded — wrong tool',)return None
def projectQueryLatency(config, queryRange):tier = pickTier(config.downsamplingTiers, queryRange)points = queryRange.seconds / tier.resolutionSecondsreturn points * DECODE_COST_PER_POINT_MSdef pickTier(tiers, queryRange):# coarsest tier whose retention covers the rangefor t in sorted(tiers, by=resolution, desc=True):if t.retentionDays * DAY >= queryRange.seconds:return treturn tiers[0] # fall back to raw
Where this sits in Build a Prometheus-style time-series database
Scene 11 of 12. Capstone: alerting, tracing, or business KPIs — the verifier turns scrape interval, label set, retention, and rules into projected RAM, disk, and a fits/refuses verdict.
All 12 scenes in Build a Prometheus-style time-series database · Every curriculum