AI Hints
Home›System Design Tutorial›Observability
System Design · Lesson 85 of 120

Monitoring and Metrics

Knowing it works.

⏱ 2 min read▶ Video at 1:42:19🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

You can't fix what you can't see. Monitoring means collecting numbers about your system, all the time, so you know it's healthy, and get alerted when it isn't.

Monitoring and Metrics
From the video: Monitoring and Metrics
  • Can't fix what you can't see
  • Collect numbers constantly
  • Alert when unhealthy

The four golden signals

A good starting point is the four golden signals. Latency, how long requests take. Traffic, how many requests arrive. Errors, how many fail. And saturation, how full your resources are, like CPU, memory, or queue length. Watch these four for every service.

keyvalue
Latencyhow long requests take
Trafficrequests per second
Errorshow many fail
Saturationhow full resources are

Alerting on error rate

Alerts should fire on symptoms users feel, like a high error rate, not on every small blip. Here we check each minute's error rate against a two percent limit. Run it. Minutes four and five cross the line, so someone gets paged. The single failed request in minute two is ignored.

alerts.pypython
minutes = [
    (1, 1000, 0), (2, 1100, 1), (3, 1050, 4),
    (4, 1200, 60), (5, 1150, 90), (6, 1000, 3),
]
LIMIT = 0.02

for minute, total, errors in minutes:
    rate = errors / total
    flag = "  <- ALERT" if rate > LIMIT else ""
    print(f"minute {minute}: {rate:.1%} errors{flag}")
Output
minute 1: 0.0% errors
minute 2: 0.1% errors
minute 3: 0.4% errors
minute 4: 5.0% errors  <- ALERT
minute 5: 7.8% errors  <- ALERT
minute 6: 0.3% errors

Summary

Monitor latency, traffic, errors, and saturation for every service, and alert on symptoms users feel. Next, following a single request through many services.

Key takeaways
  • Four golden signals
  • Alert on symptoms
  • Dashboards for each service
Next up: Logs and Tracing — following one request