📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Your team runs .NET 10 services on AKS and has to choose between Prometheus with Grafana and Azure Monitor (Application Insights metrics, Azure Monitor managed Prometheus) for metrics. Explain scraping versus pushing, how each stores and queries metrics, how cardinality drives cost in each, and how you would decide.

Covers the pull (Prometheus scrape) and push (OTLP, Azure Monitor exporter) models, self-hosted Prometheus and Grafana versus Azure Monitor managed Prometheus, Azure Managed Grafana and Application Insights metrics, PromQL versus KQL, cardinality limits and cost drivers, and a decision framework.

Mid-Level Theory Intermediate azure-monitor cardinality grafana metrics observability prometheus

🎯 Key points

  • Pull: Prometheus scrapes /metrics on an interval; the up metric shows target health
  • Push: OTLP or Azure Monitor exporter sends on an interval (60 s OTLP default); suits short-lived jobs
  • Prometheus TSDB: one series per metric + label set; memory and cost scale with active series
  • Self-hosted Prometheus needs HA pairs and long-term storage (Thanos/Mimir) for retention
  • Azure Monitor managed Prometheus: PromQL, Azure Monitor workspace, 18-month retention, billed per sample
  • Application Insights metrics: customMetrics pre-aggregated, histograms as count/sum/min/max, KQL
  • Cardinality is the cost driver in every option: labels multiply series
  • Decide on team skills, AKS vs App Service estate, retention needs and who runs the stack

⏱ 30-second answer

Prometheus pulls: it scrapes a /metrics endpoint on each target every 15 to 60 seconds and stores each metric-plus-label combination as a time series, queried with PromQL; Grafana draws the dashboards. Azure Monitor is push: the Azure Monitor OpenTelemetry exporter or an agent sends metrics to Application Insights (queried with KQL) or to Azure Monitor managed Prometheus, which keeps PromQL but removes the servers you would otherwise run, and pairs with Azure Managed Grafana.

In all of them cardinality is the cost driver: self-hosted Prometheus pays in memory and disk per active series, managed Prometheus bills per sample ingested, and Log Analytics bills per GB.

On AKS I'd usually pick managed Prometheus plus Grafana for metrics and Application Insights for traces and logs; the trade-off is that you then run two query languages.

🗣 Full answer (senior)

How I would answer this in an interview

"The first difference is who initiates. Prometheus is pull: each service exposes /metrics, and Prometheus scrapes it every 15 to 60 seconds. That gives you a free health signal, the up metric, and service discovery in Kubernetes finds pods automatically. Its weakness is short-lived things, a job that finishes between scrapes is never seen. Azure Monitor and OTLP are push: the OpenTelemetry SDK aggregates in process and sends every 60 seconds by default, which suits App Service, Functions and jobs, and goes through firewalls easily.

Storage and query differ too. Prometheus keeps every metric-plus-label combination as a separate series in its local time-series database, queried with PromQL, and it's brilliant at rates and histogram_quantile. But one Prometheus server doesn't do long retention or high availability on its own; you add Thanos or Mimir, or you use a managed service. Azure Monitor managed Prometheus is exactly that: an Azure Monitor workspace that accepts Prometheus metrics from the AKS add-on, keeps PromQL and recording rules, and you visualise it with Azure Managed Grafana. Application Insights metrics are different again: OpenTelemetry metrics land in customMetrics, pre-aggregated per minute, histograms arrive as count, sum, min and max, and you query them with KQL next to your requests and traces.

For example, at [company] we had [40] services on AKS. We kept Application Insights for traces and logs, moved metrics to managed Prometheus with Grafana dashboards, and [the metrics bill dropped by x% and dashboards loaded faster], because pre-aggregated series are much cheaper than metrics derived from logs.

The mistake I see is choosing by tool popularity. Cardinality costs the same in every option, just in a different currency: memory in self-hosted Prometheus, samples in managed Prometheus, gigabytes in Log Analytics."


Pull vs push

Pull (Prometheus scrape) Push (OTLP, Azure Monitor exporter)
Who starts Prometheus server The application
Target health Free (up == 0 when the scrape fails) Need a heartbeat or absence alert
Short-lived jobs Missed between scrapes (Pushgateway workaround) Fine, flush on shutdown
Network Server must reach every pod App needs outbound only
Discovery Kubernetes service discovery, ServiceMonitor/PodMonitor Resource attributes identify the source

The options compared

Self-hosted Prometheus + Grafana Azure Monitor managed Prometheus + Azure Managed Grafana Application Insights metrics
Query PromQL PromQL KQL
Who runs it You (HA, storage, upgrades) Microsoft Microsoft
Retention What your disk/Thanos/Mimir allows 18 months in the workspace Log Analytics retention settings
Cost driver Active series × memory and disk Samples ingested + samples queried GB ingested and retention
Percentiles histogram_quantile on buckets Same From requests raw data; metric histograms are count/sum/min/max
Best for Multi-cloud, on-prem, full control AKS on Azure App Service/Functions, correlation with traces

Production example

A team on AKS was charting request rates with KQL over requests, ingesting about [200] GB a month. Moving RED dashboards to managed Prometheus series from http.server.request.duration kept the same panels at a fraction of the ingestion, and freed them to sample traces at 20% without losing accurate rates.

🔍 What the interviewer is checking

Checks that the candidate understands how metrics systems actually collect, store and bill, and can make a reasoned platform choice.

Green flags

  • Explains pull vs push with concrete consequences (the up metric, short-lived jobs)
  • Knows Azure Monitor managed Prometheus exists and keeps PromQL
  • Names cardinality as the cost driver in every option
  • Mentions who runs and supports the stack

Red flags

  • Thinks Prometheus and Application Insights store data the same way
  • Ignores retention and high availability for self-hosted Prometheus
  • Picks a tool with no reference to team skills or the hosting estate

📚 Learn in depth

1. The Prometheus data model

A time series is identified by a metric name plus a set of label key/value pairs:

http_server_request_duration_seconds_bucket{service_name="orders-api", http_route="/orders/{id}", http_response_status_code="200", le="0.25"}  1843

Every distinct label combination is a separate series with its own chunk in memory. Prometheus keeps the last ~2 hours of samples in memory (the head block), then compacts to disk. A commonly quoted rule of thumb is a few kilobytes of memory per active series, so 5 million series need tens of gigabytes of RAM. That is why cardinality, not sample rate, decides cost.

2. Pull path on Kubernetes

 pod :8080/metrics ◄── scrape every 30 s ── Prometheus (or ama-metrics add-on on AKS)
        ▲                                         │ remote write
 ServiceMonitor / PodMonitor / annotations         ▼
                                       long-term store (Thanos, Mimir,
                                       Azure Monitor workspace) ──► Grafana

On AKS, enabling managed Prometheus deploys the ama-metrics agent, which scrapes cluster components and, with configuration, your pods, then sends samples to an Azure Monitor workspace.

3. Push path with OpenTelemetry

 .NET app (OpenTelemetry SDK) ── OTLP every 60 s ──► OpenTelemetry Collector ──┬► Prometheus remote write / OTLP receiver
                                                                                  ├► Azure Monitor exporter
                                                                                  └► other back ends

The Collector lets you drop labels, rename metrics and fan out to several back ends without redeploying services. Prometheus 3.x can also accept OTLP directly when started with its OTLP receiver enabled.

4. Application Insights metrics

The Azure Monitor OpenTelemetry exporter sends custom metrics as pre-aggregated values into customMetrics (value, valueCount, valueSum, valueMin, valueMax, customDimensions). Histograms lose their buckets, which is why percentiles in Application Insights come from the requests and dependencies tables. Standard metrics (request rate, failures, duration) are also pre-aggregated by the exporter, so they stay accurate even when traces are sampled.

5. PromQL vs KQL for the same question

# PromQL: 5xx ratio per service
sum by (service_name) (rate(http_server_request_duration_seconds_count{http_response_status_code=~"5.."}[5m]))
 / sum by (service_name) (rate(http_server_request_duration_seconds_count[5m]))
// KQL: 5xx ratio per role from requests
requests
| where timestamp > ago(1h)
| summarize ratio = 100.0 * countif(toint(resultCode) >= 500) / count() by cloud_RoleName, bin(timestamp, 5m)

PromQL works on pre-aggregated series (fast, cheap, fixed dimensions). KQL works on events (any field, slower and paid by volume).

6. Cost and cardinality in each option

Option What a new label with 1,000 values does
Self-hosted Prometheus 1,000× the series: memory, slower queries, possible OOM
Managed Prometheus 1,000× the samples ingested and queried each interval
Application Insights customMetrics More rows per minute, more GB; custom dimensions have documented limits

Try it yourself

  1. Run Prometheus and Grafana with Docker Compose, scrape a .NET app using the OpenTelemetry Prometheus exporter, and chart the RED queries.
  2. Run topk(10, count by (__name__) ({__name__=~".+"})) to see which metrics have the most series.
  3. Add a label with a GUID value, generate load, and watch prometheus_tsdb_head_series climb.
  4. Point the same app at an OpenTelemetry Collector with both a Prometheus and an Azure Monitor exporter and compare the data in Grafana and in customMetrics.
  5. On a test AKS cluster, enable managed Prometheus and find your pod metrics in Azure Managed Grafana.

💻 Code

The same service wired for pull (Prometheus scrape) or push (OTLP to a Collector, or Azure Monitor):

// Program.cs (.NET 10)
using Azure.Monitor.OpenTelemetry.AspNetCore;
using OpenTelemetry.Metrics;

var builder = WebApplication.CreateBuilder(args);
var backend = builder.Configuration["Telemetry:Backend"] ?? "otlp";

var otel = builder.Services.AddOpenTelemetry()
    .ConfigureResource(r => r.AddService("orders-api"))
    .WithMetrics(m =>
    {
        m.AddAspNetCoreInstrumentation().AddHttpClientInstrumentation().AddRuntimeInstrumentation();
        if (backend == "prometheus")
            m.AddPrometheusExporter();     // pull: exposes /metrics for scraping
        else if (backend == "otlp")
            m.AddOtlpExporter();           // push: to a Collector every 60 s by default
    });

if (backend == "azuremonitor")
    otel.UseAzureMonitor();                // push: to Application Insights (connection string from config)

var app = builder.Build();
if (backend == "prometheus")
    app.MapPrometheusScrapingEndpoint();   // GET /metrics
app.MapGet("/", () => "ok");
app.Run();
# ServiceMonitor (Prometheus Operator) so Prometheus discovers and scrapes the pods
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: orders-api
spec:
  selector:
    matchLabels: { app: orders-api }
  endpoints:
    - port: http
      path: /metrics
      interval: 30s
# Which metric names have the most series? (run in Grafana Explore against Prometheus)
topk(10, count by (__name__) ({__name__=~".+"}))

⚠ Common mistakes

  • Mistake: Choosing self-hosted Prometheus without planning HA and retention. Why it is wrong: a single server loses data on restart and keeps only local disk history. Instead: use Thanos or Mimir, or Azure Monitor managed Prometheus.
  • Mistake: Expecting a scrape-only setup to see short-lived jobs. Why it is wrong: jobs that finish between scrapes never appear. Instead: push with OTLP and flush on shutdown.
  • Mistake: Deriving all dashboard metrics from logs with KQL. Why it is wrong: you pay ingestion for every event and lose accuracy when sampling. Instead: use pre-aggregated metrics for RED and keep logs for drill-down.
  • Mistake: Expecting percentiles from OpenTelemetry histograms in customMetrics. Why it is wrong: the Azure Monitor exporter sends count, sum, min and max, not buckets. Instead: use requests/dependencies or managed Prometheus.
  • Mistake: Ignoring cardinality because the service is managed. Why it is wrong: managed Prometheus bills per sample, so label explosions turn straight into cost. Instead: set a series budget per service and review the top series monthly.
  • Mistake: Scrape intervals of 5 seconds everywhere. Why it is wrong: 6× the samples of a 30-second interval with little extra insight. Instead: 30 to 60 seconds by default; shorter only where you alert fast.
  • Mistake: Running two metric stacks with no agreed split. Why it is wrong: the same number disagrees between tools and on-call doesn't know which to trust. Instead: decide which system owns dashboards and alerts and document it in an ADR.

🏛 Senior insight: trade-offs

The choice is mostly about operations, not features. Self-hosted Prometheus is excellent but becomes a platform you run: two replicas for high availability (and deduplication in Thanos or Mimir), object storage for retention beyond a few weeks, Alertmanager clustering, upgrades, and someone on call when the monitoring itself breaks. Scaling it means sharding scrape targets once a server passes a few million active series. On Azure, managed Prometheus removes all of that while keeping PromQL, recording rules and the community dashboards, and it integrates with Azure RBAC, private links and Azure Monitor alerts. Application Insights stays the best place for correlated traces, logs and requests in .NET, with Application Map and end-to-end transaction views. Many teams end up with both, and that's fine if the split is deliberate: metrics for dashboards and alerts, Application Insights for drill-down.

Whatever you pick, set a cardinality budget per service and measure it. As a rough guide, a typical .NET service with built-in ASP.NET Core, HttpClient and runtime metrics produces a few thousand series; a 40-service estate sits in the low hundreds of thousands; anything heading to millions usually means an unbounded label.

Option When it fits Cost When not to
Self-hosted Prometheus + Grafana Multi-cloud or on-prem, strong platform team Servers, storage, people, on-call Small team without on-call for the monitoring stack
Managed Prometheus + Azure Managed Grafana AKS on Azure, PromQL skills Per sample ingested/queried + Grafana instance Mostly App Service/Functions with no Prometheus skills
Application Insights metrics App Service, Functions, KQL teams Per GB ingested and retained High-cardinality, high-frequency metrics at scale
Third-party SaaS (Datadog, Grafana Cloud, New Relic) One tool across clouds Per host / per series pricing Strict data residency without an Australian region option

🔗 Follow-ups the interviewer may ask

  1. When: Candidate says cardinality is the cost driver. Why: Checks they can find and fix a cardinality problem in practice.
    How to answer

    Cardinality is the number of unique label combinations; each is a separate time series. A user_id label multiplies a metric's series by the number of active users, and on a histogram that is again multiplied by every bucket, so 20 routes × 5 status codes × 17 buckets × 50,000 users is 85 million series.

    I confirm it with prometheus_tsdb_head_series (or the Azure Monitor workspace's active series and ingestion metrics), find the metric with topk(10, count by (__name__) ({__name__=~".+"})), and the label with count(count by (user_id) (...)). I stop the bleeding without a deploy by dropping the label in the OpenTelemetry Collector or with Prometheus labeldrop, then remove the tag in code and move per-user questions to traces and logs.

    The trade-off: per-user detail is real value, but metrics are the wrong place for unbounded data.

  2. When: Candidate mentions Log Analytics or Application Insights cost. Why: Checks they can reason about the log platform choice as well as metrics.
    How to answer

    All four store structured logs and let you search them, but they differ in how much they index, which drives cost.

    • Application Insights / Log Analytics: fully managed, indexes every field, queried with KQL, correlated with traces and metrics. You pay per GB ingested; Basic and Auxiliary table plans and archive cut the cost of noisy or long-retention data.
    • Seq: small, self-hosted, excellent developer experience for structured logs; free for one user.
    • Elasticsearch / OpenSearch: inverted index on fields, powerful full-text search, but you run (or pay for) a memory-hungry cluster.
    • Grafana Loki: indexes only labels, stores chunks in object storage: cheapest at high volume, slower for free-text searches.

    I choose by team size, volume, existing cloud and who runs it, and I ship logs with OpenTelemetry so the choice stays reversible. The trade-off is index everything and query fast versus index little and pay less.

  3. When: Candidate mentions Grafana dashboards. Why: Checks they can design dashboards people use, not just pick the tool.
    How to answer

    An incident dashboard must answer three questions in the first screen: are users hurting, since when, and where. So the top row is SLO status and error budget, then RED for the service (rate, 5xx ratio, p50/p95/p99) with the SLO threshold drawn on the panels. The next row is RED for each dependency (database, downstream APIs, queues) so you can see where the fault starts. Below that, USE panels for the runtime, pods and database, collapsed by default.

    Every time series carries deploy and feature-flag annotations, because most incidents follow a change, and panels link to traces and logs filtered to the same service and time window. One template as code with service and region variables serves every service.

    The trade-off: fewer panels make it faster to read, but you need drill-down paths for the detail you removed.

🛠 Real-world problems: how you handle them

Moving RED dashboards from log queries to managed Prometheus
Situation
[40] .NET services on AKS in Australia East at [company]; all dashboards were KQL over `requests`, and Log Analytics ingestion had grown to [200] GB a month.
Signals
Dashboards took 20+ seconds to load during incidents; Azure Cost Management showed Log Analytics as the top observability cost; the team wanted to sample traces but feared losing accurate rates.
Investigation
Used KQL `Usage | summarize sum(Quantity) by DataType` to confirm `AppRequests` was the biggest table. Checked that `http.server.request.duration` was already emitted by every service through OpenTelemetry. Trialled managed Prometheus on one cluster and compared rates and p95 between PromQL and KQL for a week.
Resolution
Enabled managed Prometheus and Azure Managed Grafana, rebuilt RED dashboards on PromQL, and only then turned on 20% trace sampling in Application Insights. Kept KQL for drill-down and incident queries.
Prevention
ADR recording the split (metrics in Prometheus, traces and logs in Application Insights); a monthly top-series review; alert on series count per service; dashboard template in Git.

How to tell it (STAR)

**S:** At [company] all our dashboards for [40] AKS services were KQL queries over request logs, ingesting about [200] GB a month and loading slowly during incidents. **T:** I was asked to cut cost without losing visibility. **A:** I confirmed requests were the largest table, checked every service already emitted the ASP.NET Core duration histogram, and trialled managed Prometheus with Grafana on one cluster, comparing numbers for a week. We moved RED dashboards to PromQL, then turned on trace sampling and wrote an ADR for the split. **R:** Ingestion fell by [x]%, dashboards loaded in under [3] seconds, and rates stayed exact despite sampling.

↩ Usually asked after

More in Metrics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me