System design · Metrics, logs, traces and alerting
Observability explained
Observability is the ability to investigate a system's behaviour from the evidence it emits. Metrics show trends and scope, logs describe events, and traces connect work across boundaries. In an interview, start with a user journey and show how these signals help detect a problem, narrow its cause and verify recovery, rather than listing monitoring products.
Updated · 4 min read
The short version
- Start from one user journey and define success at a named boundary. A fast error is not good latency.
- Metrics show scope and trends, logs say what the code decided, traces show where the time went.
- Keep metric labels bounded. Order IDs belong in logs and traces, never in a label.
- Page on SLO burn with an owner and an action, not on every resource threshold.
- Telemetry must never block the customer's request. Bound its buffers and make dropped data visible.
Clarifying questions to ask first
- Which journey matters? (Assume checkout: a gateway calls the order API, which writes to a database and queues fulfilment.)
- Where is success measured? (Assume at the gateway, with fulfilment finishing later and tracked by work age.)
- Do fast rejections count as good latency? (Assume no: latency covers successful requests only.)
- What's the objective? (Assume a teaching 99.9% success SLO.)
- May telemetry slow the request? (Assume never: exporters are bounded and dropped data is visible.)
Golden signals at a chosen boundary
Monitoring answers questions you knew to ask; investigation needs evidence for the ones you didn't. Google's SRE book names four golden signals: latency, traffic, errors and saturation. Keep fast rejections out of latency, or a broken release makes checkout look quicker. A quiet server isn't healthy if a broken gateway stops requests reaching it.
The gateway knows what it returned and the client knows whether it got a confirmation. If the fulfilment queue grows, checkout stays fast while orders wait, so measure work age too. Building the metrics platform is its own design.
Metrics: distributions and cardinality
Counters for completed requests, gauges for queue depth, histograms for latency (OpenTelemetry's metrics concepts). Never average instance p99s and call it the service p99; Prometheus's histogram docs explain why precomputed quantiles don't aggregate.
Cardinality is distinct label combinations, and Prometheus warns every label set has a cost. 4 regions × 5 route templates × 3 outcomes is 60 combinations. Add 10,000 order IDs and it's 600,000. Label by /orders/{id}, never the raw ID.
Logs and traces
Log stable event names with typed fields: order accepted, reservation rejected, retry scheduled, plus service, version, outcome and a correlation ID. OpenTelemetry's logs guide notes valid JSON isn't a schema; an amount that is sometimes a string breaks queries. Separate validation rejections from internal errors. Diagnostic logs are lossy by design, so an audit trail is a separate durable record.
A trace links spans at each boundary between your work and a dependency wait. Carry context through HTTP headers and message metadata so the async worker joins the trace. A trace ID is not an idempotency key. Sampling decides what you can investigate later (OpenTelemetry's sampling docs), so say whether slow and failed traces are kept and keep request counts unsampled.
SLOs and alerts someone can act on
An SLI measures an outcome; an SLO is its target over a window. Fix the denominator first: timeouts, retries, invalid input. A 99.9% objective allows 0.1% bad requests, so 1% failing burns budget 10 times too fast. SLAs, SLOs and error budgets covers budget policy.
Google's SRE Workbook suggests alerting on burn over a short and a long window together, so a sustained problem pages and a blip doesn't. Low traffic needs care. Every page needs an owner, an impact statement and an action.
Working an incident
Failures rise after a deploy. Check gateway outcomes, API outcomes and volume agree, then narrow to the route or region that moved. The deploy is a suspect, not proof. A trace shows waits on database connections and logs show acquisition timeouts; low database CPU doesn't clear the pool. Pick the next observation that separates the explanations. Verify recovery on the same indicator, and check the queue, since old orders stay late after latency recovers. The simulator's live metrics illustrate bottlenecks but collect no production logs or traces.
The pipeline fails too. OpenTelemetry's Collector resiliency guide covers queues, retries, persistence and where data is still lost. Watch dropped records and freshness; a flat dashboard may be a broken exporter. Redact secrets and keep bodies and credentials out of logs, spans and baggage.
Where it's used
- Notification system: a fast acknowledgement can hide late delivery, so measure completion delay too.
- Fault tolerance: correlated outcomes separate a failing dependency from your own retry amplification.
- UPI payments: the user-visible outcome, the provider's response and the reconciliation record stay separate.
Common traps
- Order IDs as metric labels. Put per-operation detail in logs or traces.
- Averaging instance p99s and calling it the service p99.
- Counting fast errors as healthy latency.
- Paging on high CPU. It's a diagnostic clue, not a reason to wake someone.
- Blocking checkout on a diagnostic exporter, or letting an unbounded telemetry queue eat checkout's memory.
Follow-up questions interviewers ask
- "Which signal do you open first?" The user-facing indicator and volume, for impact and scope.
- "Why not keep every trace?" Cost. Choose a sampling policy and name its blind spots.
- "What if the monitoring backend fails?" Bounded exporters, visible loss and an independent probe for user impact.
Frequently asked questions
What is observability in system design?
+
It's the ability to investigate a system's behaviour from the evidence it emits. A pile of dashboards doesn't prove you can do that.
What is the difference between metrics, logs and traces?
+
Metrics summarise measurements over time, logs record events with context, and traces connect the work behind one operation. Shared identifiers make them useful together.
Does OpenTelemetry store and analyse all telemetry?
+
No. It provides instrumentation, collection and export. The destination you choose does storage and analysis.