⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Observability & Monitoring Interview Questions Scenario 88 of 116 in Observability & Monitoring
Senior DevOps / SRE Observability Prometheus & Metrics Core Concept
🎯 Target Role / Context: Senior Observability & SRE Interview Classic

Q: What is the difference between a Gauge and a Counter in Prometheus? When should you use each, how do rate() and irate() work on counters, and what happens when a process restarts?

Mastering Gauge vs Counter in Prometheus: cumulative monotonically increasing counters vs fluctuating gauges, how rate() handles server restarts and resets, and when to choose each metric type.

#gauge vs counter prometheus #counter vs gauge metric #Prometheus #PromQL #Metrics #rate() #irate() #Observability #SRE #Comparisons
🎙️ Candidate Opening & Architectural Context
"In production telemetry, choosing the wrong Prometheus metric type between a Counter and a Gauge undermines all alerting and SLO accuracy. A Counter only increases (or resets to 0 on crash), whereas a Gauge can go up or down arbitrarily."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? The Linux Foundation's Prometheus Certified Associate (PCA) & Monitoring Labs covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: In production telemetry, choosing the wrong Prometheus metric type between a Counter and a Gauge undermines all alerting and SLO accuracy. A Counter only increases (or resets to 0 on crash), whereas a Gauge can go up or down arbitrarily.

1️⃣

Fundamental Architectural Differences

Differentiating Counters and Gauges at the data collection level:

  • Counter: A cumulative metric that represents a single monotonically increasing counter. Its value can only increase or reset to zero upon process restart. Examples: http_requests_total, system_cpu_seconds_total, errors_total.
  • Gauge: A metric that represents a single numerical value that can arbitrarily go up and down. It captures a snapshot in time. Examples: node_memory_MemAvailable_bytes, jvm_threads_current, temperature_celsius, queue_depth.
Pro Tip: Never use a Gauge for counting events (like HTTP requests or errors) because Prometheus scrapes at intervals (e.g., every 15s) and any events occurring between scrape intervals will be permanently lost.
2️⃣

PromQL Query Functions & Counter Reset Compensation

How Prometheus mathematical operators interact with each type:

  • rate(v[range]): Calculates the per-second average rate of increase across a range vector. Critically, rate() automatically detects and compensates for counter resets (when a pod restarts and resets to 0).
  • irate(v[range]): Instant rate based on the last two data points in the range window. Ideal for fast-moving spikes, but sensitive to scrape jitter.
  • delta(v[range]) / deriv(v[range]): Used exclusively on Gauges to calculate differences or slopes. Never apply rate() to a Gauge because counter-reset compensation will corrupt the results when a gauge drops naturally!
Advertisement
3️⃣

Practical PromQL Query Patterns

Real-world queries used by SRE teams for alerts and dashboards:

  • Counter rule: Always pass a counter through rate() before applying aggregations like sum() or avg(). Running sum(http_requests_total) without rate causes artificial step jumps whenever pods restart.
  • Gauge rule: Can be directly aggregated with sum(queue_length) or avg(cpu_temperature).
4️⃣

Decision Matrix: Counter vs Gauge

Fast reference for instrumentation design:

  • Requests / Orders / Errors: Always Counter (use _total suffix per Prometheus naming conventions).
  • Memory / CPU % / Connections: Always Gauge.
  • Queue Size / In-Flight Requests: Gauge (track active requests via gauge increment on start, decrement on finish).
  • Duration / Latency: Histogram or Summary (which under the hood exposes a counter for _count and _sum).
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Counters measure rate of occurrence over time with automatic crash-reset compensation. Gauges measure instantaneous state at the moment of scrape. Never apply rate() to a Gauge, and never aggregate raw counters before calculating rate()."
⚡ 60-Second Elevator Pitch Talking Points
  • A Counter is a cumulative monotonically increasing metric used for countable events like requests and errors; it only goes up or resets to 0 on restart.
  • A Gauge represents snapshot values that fluctuate up and down arbitrarily, such as memory usage, disk space, or current active connections.
  • In PromQL, counters are queried with rate() to calculate per-second frequency while automatically smoothing over process restarts, whereas gauges use raw values or delta().
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Injecting high-cardinality label dimensions (such as user IDs or request UUIDs) into Prometheus metrics when configuring Gauge Counter Prometheus High-cardinality label values cause exponential time-series growth, consuming gigabytes of TSDB memory and crashing Prometheus servers.
  2. Evaluating application performance solely through arithmetic mean or p50 latency while ignoring tail latency (p99) when configuring Gauge Counter Prometheus Averages hide catastrophic tail latency outages where 1% of high-value user transactions suffer severe timeouts.
  3. Failing to inject and extract W3C distributed trace context across message brokers and RPC calls when configuring Gauge Counter Prometheus Breaking distributed trace context propagation fragments end-to-end transaction waterfalls into disconnected, un-correlatable trace segments.
  4. Configuring alert rule evaluation intervals without sufficient duration damping (for: 5m), inducing alert flap when configuring Gauge Counter Prometheus Instant alerts triggered by transient sub-second CPU or latency blips page on-call engineers unnecessarily and dilute response urgency.
Advertisement
Want more Observability & Monitoring scenarios?
Explore our complete collection of scenario-based Observability & Monitoring interview runbooks.
Browse All Observability & Monitoring Questions →