Metrics, Logs & Traces: The Three Pillars
You'll learn to
- -Distinguish monitoring (when something is wrong) from observability (why)
- -Say what each pillar is best for: metrics to notice, traces to locate, logs to explain
- -Follow one incident through all three pillars
- -Explain why percentiles beat averages, and name the four golden signals
Monitoring tells you when something is broken. Observability tells you why. With services split apart and traffic flowing through caches, queues and several regions, why stops being obvious from a single log file. A request may touch ten machines, and the problem may be on any of them. You need three complementary tools, usually called the three pillars: metrics, logs and traces.
An Analogy: A Patient in Hospital
A patient in hospital is connected to a monitor showing heart rate, temperature and oxygen level. These are cheap, continuous numbers, and an alarm sounds when one leaves its safe range. The monitor tells nurses something is wrong, but not what. The patient's chart holds detailed notes on every event: medication given at 2:10, a fever at 3:05. And a record of the patient's journey, from emergency room to X-ray to surgery, with times at each stop, shows where the waiting happened.
- -The vital-signs monitor is metrics: numbers over time, good for noticing.
- -The chart notes are logs: detailed events, good for explaining.
- -The journey record is a trace: one request followed through every service, good for locating.
Metrics
Metrics are numeric time series: counters and gauges such as requests per second, or error rate 2%. They are cheap to store and fast to query, which makes them ideal for dashboards and for alerting the moment a number crosses a threshold. The card below describes the monitoring component as it appears in the lab:
Monitoring is your system's vital signs monitor. The same way a hospital attaches a heart monitor, blood pressure cuff, and oxygen sensor to a patient, you attach monitoring to your servers and services. There are three pillars: - METRICS: Numbers over time (CPU at 73%, 500 requests/second, 12ms average latency, 0.1% error rate) - LOGS: Detailed text records of what happened ('User #42 tried to login, password incorrect, IP: 203.0.113.5') - TRACES: Following a single request across your system ('Request hit API Gateway -> Auth Service -> User Service -> Database -> back, total 240ms') Together, these three pillars answer every question: 'Is the system healthy right now?' (metrics), 'Why did this user get an error?' (logs), 'Why is this endpoint slow?' (traces). Alerting sits on top: 'If error rate > 5% for 3 minutes, page the on-call engineer.' Without monitoring, you're flying blind. You only find out about problems when users complain, by which time thousands have already been impacted.
Examples: Prometheus + Grafana (open-source metrics standard), Datadog (all-in-one SaaS), AWS CloudWatch, ELK Stack (Elasticsearch + Logstash + Kibana for logs), Jaeger/Zipkin (distributed tracing), PagerDuty (alerting/on-call)
Logs
Logs are discrete, timestamped events with full detail: user 4821 got a 500 error at 3:14:02 pm, with a stack trace attached. They answer what exactly happened, at the price of being expensive to store and search at scale without a dedicated aggregation system. Write logs as structured data (JSON, with fields) rather than free text, and put a request id in every line so one request can be followed across services. The card below describes the log aggregator:
Imagine you have 200 servers, each writing its own log file. When a user reports a bug, you need to figure out what happened. Do you SSH into all 200 servers and grep through their logs one by one? That would take hours. A log aggregator collects ALL logs from ALL servers and services, ships them to a central searchable store, and lets you query across everything in seconds: 'Show me every log line containing user_id=42 from the last hour, across all services, sorted by time.' Now you can see the full picture: the request hit the API gateway at 14:23:01, reached the Order Service at 14:23:02, called the Payment Service at 14:23:03, and THAT'S where the error happened. Timeout after 30 seconds connecting to the bank's API. Without centralized logging, you'd never piece this story together. A good log aggregator also supports alerts ('notify me when ERROR log count exceeds 100/minute'), dashboards (error trends over time), and retention policies (keep logs for 30 days, then archive or delete).
Examples: ELK Stack (Elasticsearch + Logstash + Kibana, the classic), Grafana Loki (lightweight, pairs with Prometheus), Splunk (enterprise-grade, expensive), Datadog Logs (SaaS), AWS CloudWatch Logs, Fluentd/Fluent Bit (log shippers)
Traces
A trace follows one specific request across every service it touches, as a set of spans, each recording one step and its duration. It shows exactly where the time went: this request took 800 ms in total, and 600 ms of that was one slow database query in the Orders service. Traces are what make a microservices system debuggable at all.
A single request traced across three services: the trace pinpoints which service ate the time, before you ever open a log.
One Incident, Three Pillars
- -3:14 am: an alert fires because the error rate passed 2%. This is a metric telling you something is wrong.
- -The dashboard shows the latency of checkout, measured at the 99th percentile, jumped from 300 ms to 4 seconds. Another metric, narrowing down what.
- -You open a trace of one slow checkout. It took 4.1 seconds: 50 ms in the gateway, 100 ms in Orders, and 3.9 seconds in a Payments database query. The trace says where.
- -You search the Payments service's logs for that trace id and find lock wait timeout exceeded on table payments. The log says why.
Why Percentiles Beat Averages
Averages hide pain. Say 980 of 1,000 requests take 100 ms and 20 take 10 seconds. The average is (980 x 100 + 20 x 10,000) / 1,000 = 298 ms, which looks acceptable. But one user in fifty waited ten seconds. A percentile shows it: the 99th percentile (p99) is the time that 99% of requests beat, and here it is 10 seconds. Track p50 for the typical experience, and p95 or p99 for the worst you are willing to allow.
What to Watch First
A widely used starting point is the four golden signals: latency (how long requests take, including failed ones), traffic (how much demand), errors (the share of requests that fail), and saturation (how full the system is, such as CPU, memory or queue depth). If you only had four dashboards, these would be them.
Costs to Keep in Mind
- -Logs are bulky: a service writing 1 KB per request at 5,000 requests a second produces 5 MB a second, about 432 GB a day. Keep them for days, not years, and sample the noisy ones.
- -Traces are sampled: keep, say, 1% of requests plus every error, rather than all of them.
- -Metrics must not carry unbounded labels: a label with the user id creates a separate time series for every user and overwhelms the metrics store.
The three pillars work as a team: a metric alerts you that latency spiked, a trace shows you which specific service in the chain is slow, and a log reveals the exact error inside that service.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!