Practice this topic in a realistic system design interview
Logs describe individual events, but no one can read a million log lines to answer a simple question: is the system healthy right now? For that, you need numbers that summarize what is happening across many requests at once.
Metrics are those numbers. They are measurements collected over time. They reveal trends in latency, error rate, traffic, and resource usage. They power dashboards, trigger alerts, and help teams add capacity before the system runs out of room.
This chapter covers the main metric types, the golden signals worth tracking, how to add metrics to code, how to name metrics, how to avoid runaway labels, and how Prometheus-style systems collect and store metrics.
To see why metrics matter, consider an e-commerce platform during a flash sale.
Logs show individual events: order 123 completed in 250ms, order 124 completed in 280ms, order 125 completed in 310ms, and so on across tens of thousands of orders.
Metrics summarize the workload: request rate at 2,500/sec, p99 latency at 450ms, error rate at 0.3%, and CPU at 78%.
Logs show individual events. To understand the flash sale's impact from logs alone, you would need to count and group thousands of entries. Metrics give you the shape immediately: request rate tripled, latency increased by 40%, error rate is still acceptable, and CPU is climbing.
Metrics and logs answer different questions. The table compares what each one does best.
| Aspect | Metrics | Logs |
|---|---|---|
| Data type | Numbers over time | Text events |
| Question answered | How much? How many? | What happened? |
| Storage efficiency | Very efficient (numbers) | Less efficient (text) |
| Query style | Group, graph | Search, filter |
| Retention | Months to years | Days to weeks |
| Alerting | Primary use case | Secondary use case |
| Debugging | Find the problem | Understand the problem |
Both are essential. Metrics tell you that something changed. Logs and traces help you understand why. Think of metrics like a hospital vital-signs monitor: it quickly shows that something needs attention, but doctors still need more information to diagnose the cause.