Observability — metrics, logs and traces
Overview
A design isn’t finished when it works on a whiteboard; it has to be operated. Observability is how you know what a running system is doing and why. When something goes wrong at 3 a.m., good observability is the difference between a five-minute fix and a five-hour guessing game. Interviewers increasingly expect a sentence or two about it.
The three pillars
Metrics
Numbers aggregated over time: request rate, error rate, latency percentiles, CPU, queue depth. They’re cheap to store and fast to query, perfect for dashboards and alerts. Tools: Prometheus, Grafana, Datadog, CloudWatch.
For every service, track the four golden signals:
- Latency: as percentiles, separately for successful and failed requests,
- Traffic: requests per second,
- Errors: rate of failed requests,
- Saturation: how full the service is (CPU, memory, connection pools, queues).
Add business metrics: orders per minute, sign-ups, payment success rate. They often reveal problems that technical metrics miss.
Beware high cardinality: a label with millions of values (user ID) explodes storage. Put those in logs and traces instead.
Logs
Detailed records of individual events. Make them structured (JSON with consistent fields) so they can be searched and aggregated, and always include a request or trace ID so you can follow one request across services. Use levels sensibly, avoid logging secrets or personal data, and sample very high-volume debug logs. Tools: the ELK/OpenSearch stack, Loki, Splunk, cloud logging services.
Traces
A distributed trace follows one request through every service it touches. Each unit of work is a span with a start time, duration and parent, so a trace shows exactly where time went. Traces answer questions like “why is checkout slow for some users?” in minutes. The trace context is passed between services in headers (W3C traceparent). Because tracing every request is expensive, systems sample, keeping a fraction of normal traces and all slow or failed ones. Tools: OpenTelemetry for instrumentation; Jaeger, Tempo, Zipkin or vendor tools for storage.
Alerting
Good alerting is about symptoms users feel, measured against SLOs (week 1):
- page a human when the checkout error rate or latency is burning through the error budget fast,
- send lower-urgency tickets for causes and early warnings (disk filling up, one instance unhealthy),
- every page should be actionable and link to a runbook and dashboard.
Too many noisy alerts lead to alert fatigue, and real problems get ignored.
Dashboards and debugging
Useful dashboards start at the top (is the user experience OK?) and drill down (which service, which endpoint, which dependency, which instance). During an incident the flow is typically: alert on a symptom → dashboard to locate the service → traces to find the slow or failing span → logs for the specific error.
Built in, not bolted on
- Use OpenTelemetry to instrument metrics, logs and traces with one vendor-neutral standard.
- Propagate request IDs from the edge through queues and async jobs.
- Record deploys and feature-flag changes as events on dashboards; many incidents start with a change.
- Include health checks and readiness endpoints (week 2).
In an interview
In the wrap-up: “Each service exports golden-signal metrics and structured logs with trace IDs via OpenTelemetry; we trace requests end to end; alerts fire on SLO burn rate for the main user flows, such as feed load latency and post success rate.” One or two sentences are usually enough unless the interviewer wants more.
Recap
Metrics show that something is wrong, logs explain individual events, and traces show where time goes across services. Track latency, traffic, errors and saturation plus business metrics, use structured logs with trace IDs, sample traces sensibly, and alert on user-facing symptoms against SLOs so pages are rare and meaningful.
Instrument the checkout
You own a checkout service that calls Cart, Pricing and Payment services. Users report that checkout is 'sometimes very slow'. (a) Which metrics would you collect for the checkout service and its dependencies? (b) What would you put in each log line? (c) How would tracing help find the cause? (d) Write one alert rule that wakes someone up and one that doesn't.
(a) Metrics:
(b) Logs:
(c) Tracing:
(d) Alerts:(a) Metrics: request rate, error rate (by status/type) and latency percentiles
(p50/p95/p99) for the checkout endpoint; the same per dependency call (Cart,
Pricing, Payment); saturation: CPU, memory, connection-pool usage, queue depth;
business metrics: checkouts started/completed, payment failures.
(b) Logs: structured JSON with timestamp, level, service, version, request ID /
trace ID, user or account ID (not personal data like card numbers), route,
status, duration, and error details - so all logs for one slow request can be found.
(c) Tracing: each checkout produces a trace with spans for each downstream call and
database query. Looking at slow traces shows which span grows (e.g. Payment taking
2 s only for one card network, or a slow SQL query), instead of guessing.
(d) Page: "checkout success rate below 99% or p99 latency above 2 s for 10 minutes
(burning the monthly error budget fast)". Don't page: "CPU above 70% on one
instance" - create a ticket or dashboard warning instead.Summary
- Metrics are cheap numeric time series for dashboards and alerts; logs record detailed events; traces follow one request across services.
- Watch the golden signals for every service: latency, traffic, errors and saturation.
- Use structured logs with a request or trace ID so one request's story can be reassembled across services.
- Alert on user-facing symptoms against SLOs, not on every cause; keep pages rare and actionable.
- Instrument with open standards (OpenTelemetry) and include business metrics, not just technical ones.