โ Back to Observability: logs, metrics and traces
๐ฅ Observability: logs, metrics and traces: cheat sheet
๐จ The analogyA hospital ward: monitors show numbers, nurses write notes, and each patient's chart follows them between wards.
๐ The regular explanationUnderstanding a running system from the signals it emits. Metrics show trends and trigger alerts, structured logs record individual events, and distributed traces follow one request across services, all tied together by a shared trace id.
- A patient arrives on the ward. Case 42.
- While caring for them, the ward keeps three kinds of record. The monitor counts patients and how long they wait, the notes say what was done, and the chart notes how long each step took.
- The next patient, case 43, waits far too long. The monitor's waiting time jumps.
- The doctor sees the jump on the monitor and opens case 43's chart. Most of the wait was at the lab.
- Then she reads the nurses' notes for case 43. The lab machine got stuck and the test had to be run again. Now she knows why.
- Ana and Ben arrive together. The nurse writes plain notes, "gave a dose", "sent for an X-ray". Whose notes are whose? Nobody can tell.
- Now each patient gets a case number. While the nurse cares for Ana, her stamp says 42, and every note she writes gets stamped.
- When she moves on to Ben, she wipes the stamp and sets it to 43. Otherwise Ben's notes would end up on Ana's case.
- Later the doctor asks for every note about case 42, and gets exactly Ana's notes, in order, in seconds.
- A patient is admitted. The tally goes up by one. It only ever goes up.
- They take a bed, so beds in use goes up. When someone goes home, it goes down again.
- The patient waited 12 minutes, so the wait-time chart drops them in the "within 15 minutes" box.
- Every little while the nurses' station screen collects all the numbers and keeps the history. Nine in ten patients are seen within 15 minutes.
- Someone labels the tally by patient name. Now there's a separate line for every patient ever, and the screen slows to a crawl.
- A patient arrives at reception and gets case number 42. Reception opens a chart and writes the first entry.
- Reception sends the patient to the emergency room with the chart. The emergency room adds its entry, "sent by reception".
- The emergency room sends them to X-ray and to the lab, chart in hand. Each adds an entry, "sent by the emergency room".
- X-ray is quick. The lab takes ages. Then the patient heads back the way they came and goes home.
- Laid out together, the chart shows the whole two-hour visit at once, and ninety minutes of it was at the lab. That's where to look.
- Every ward fills in the same standard form and sends it to the records office.
- Reception decides when each patient arrives, keeping a full chart for one in ten, and every ward follows that choice. Cheap, but case 43, the one with a complication, may not be kept.
- The better way is for the office to keep every chart until the visit is over, so it can see how each one ended.
- It files every chart with a complication or a long wait, and only a few of the ordinary ones. The rest are thrown away.
- The monitors' numbers all go to the history, none thrown away, so the counts stay right.
- The ward's goal is 999 in every 1,000 patients seen within 15 minutes this month. The one in a thousand left over is its allowance for bad days.
- The X-ray machine gets very busy, but patients are still seen on time. Nobody wakes the doctor.
- Then patients really do start waiting too long, and the allowance drains fast.
- That's what patients feel, so the alarm goes off and the doctor is woken up.
- She finds the cause and fixes it. With little allowance left, the ward holds off on new changes for the rest of the month.
๐งฉ Key questions
- The monitor shows that patients are suddenly waiting far too long. What should the doctor look at next to find which ward they're stuck in?
- The chart of one slow patient, which shows how long each ward took. The monitor says something is wrong, the chart says where, and the notes for that case number say why.
- Someone wants the admissions tally split by patient name, so they can see each person. Why is that a bad idea?
- Every patient ever gets their own line, and the screen fills up and slows to a crawl. Label numbers by ward, a short fixed list. Details about one patient belong in the notes and the chart.
- The hospital decides at reception to keep a full chart for one patient in ten. What's the catch?
- The rare patient with a complication is usually one of the nine whose chart isn't kept. Deciding at the door is cheap but blind. Holding every chart until the visit ends lets the office keep all the troubled ones. The monitors count everyone either way.
- The X-ray machine is very busy, but every patient is still seen on time. Should the alarm wake the doctor?
- No, patients aren't feeling it, so it can wait on a screen for the day team. Alarms for things patients don't feel teach the doctor to ignore alarms. Wake her when patients really wait.