Prometheus takes 20 minutes to restart after a crash. Why, and how do you reduce it?
AdvancedScenarioPrometheus and PromQL at Scale
Answer
Situation read → On start, Prometheus replays the WAL and loads the head block. A large head and a large WAL slow this down.
What I'd do →
- Check logs:
msg="WAL replay completed"with duration,Replaying WAL, this may take a while. - Reduce series count (see cardinality fixes). Less head data means a shorter replay.
- Keep the WAL on fast disk (NVMe/gp3 with enough IOPS).
- Enable
--storage.tsdb.wal-compression(default on in recent versions) to shrink the WAL. - Run two replicas so one stays up while the other restarts, and use a readiness gate on
/-/ready. - Shard if a single instance is too large.
Why → Replay time is proportional to the WAL size, which is proportional to ingested samples since the last head compaction.
Interview tip → Do not use kill -9 or OOM-kill loops: they leave long WALs to replay.
More on Prometheus and PromQL at Scale
Prometheus memory has grown to 60 GB and keeps climbing. How do you find the cause?IntermediateA developer added `user_id` as a metric label. What is the problem and what do you advise?BeginnerYour dashboard shows the average of per-pod p99 latencies. Why is it wrong, and how do you compute a correct fleet-wide p99?IntermediateChoose histogram bucket boundaries for a service with a 300 ms latency SLO.AdvancedYou have 500 short-lived batch jobs that finish before Prometheus can scrape them. How do you capture their metrics?IntermediateYour EC2 fleet autoscales constantly. How do you keep Prometheus targets up to date?Intermediate