Metrics Monitoring: First Design
Nobody is going to run a hundred thousand servers on one SQL table, and from minute ten to minute twenty you draw one anyway. A reading becomes a row, a chart becomes a query, and an alert becomes a query on a timer. All three jobs in the question are on the board with nothing invented, and every box you add later replaces something you can point at.
Hold the time-series store back for ten minutes, because drawing it now would hide what the table gets right. The interviewer leans on this design in four places. They are the quiz at the end of this lesson, and Scaling It takes them in that order.
Agents, a Collector and One Table
An agent on each server takes its readings every 10 seconds and posts them as a batch to one collector, a small service that accepts batches. The collector writes one row per reading to one relational table: metric, labels, time, value. Labels go in as free text, in the row. A dashboard panel is a SQL query over a range. And a scheduled job, the alert job, runs each rule as a query once a minute and calls the pager on a crossed threshold.
One Reading, One Panel, One Page
Follow one reading: CPU on host 42 at ten o'clock, value 91 percent. The agent puts it in a batch with that host's other 199 readings and posts it. The collector unpacks the batch and inserts 200 rows, this one among them.
Now one panel: CPU on host 42 for the last hour. The dashboard sends a query naming that metric, that label and that hour. It matches 360 rows, one for every 10 seconds, and the panel draws them. Every viewer who opens the panel runs the query again.
Now one rule: CPU on host 42 above 90 percent. At the top of the minute, the alert job runs the rule's query for the newest reading and sees 91. It records the alert's state as firing and calls the pager. The next run finds the state already firing and stays silent, so one condition sends one page. A value that crosses just after a run waits for the next one, on top of up to 10 seconds for the agent's own tick, so a page can run past the agreed minute, and you say so.
A Hundred Servers on One Table
This is a real answer at a stated size. Readings go in, charts come out, and a rule can page someone. Any SQL query works on day one, and an alert is just another query, so there is no second system to learn. Say what you get free before anyone takes it away.
Assume a hundred servers. That is 2,000 rows a second. At 100 bytes a row, that is 200 KB a second. Over a day it comes to about 17 GB, and over a month about 500 GB. So the 2 TB node assumed in Scope holds four months of every reading, with nothing else needed. Four months is short of the two years agreed, and you name that: even here, old rows have to be summarised or dropped.
Notice what you have not claimed: how many inserts one database can take. You have no figure you could defend, and you do not need one. Bytes and hours make the whole case.
Four Limits, Named and Left Alone
The table grows by a row per reading. A long chart scans everything it draws. Labels are free text in every row. And collector, table and alert job are one failure: lose any of them and the alerts go too. You fix none of these yet.
The first limit is the one to offer before you are asked, in bytes and hours: "A hundred servers is comfortable here. At a hundred thousand it's two million rows a second, and a two-terabyte disk fills in under three hours, so I'd start with the write path."
The fourth you mark separately, since it decides who gets woken and who does not: "The alert job is just another reader on this board. It shouldn't be, and I'm marking that to come back to."
- Opening with a time-series store and no first design. The interviewer never hears what the table got right, and has no reason to believe the store was forced.
- Claiming a relational database cannot take the load, with a made-up number. One question about where the number came from ends that argument, so argue in bytes.
- Treating the alert job as a detail below the dashboards. It is the part that wakes someone, and the interviewer will start there.
- Stating no limit: two million rows, three hours to a full disk. If the interviewer does that sum first, the limit is no longer yours to offer.
- A reading traced from the agent to the pager, with nothing between them skipped.
- The first limit given in bytes and hours, not as "it won't scale".
- What the design gets for free, any query in SQL, said before it is given up.
Knowledge Check
"A hundred thousand hosts, a couple of hundred metrics each, a reading every ten seconds. What does your table see?"
- "Two million rows a second, so move to an append-only store split by series and by time."
- "Two million rows a second, so add read replicas and take that load off the primary."
- "Twenty million rows a second, so sample the hosts and keep only one reading in ten."
- "Two million rows a second, so shard the table by timestamp to spread the inserts out."
"Someone opens a thirty-day dashboard across the whole fleet, and it scans billions of rows. How do you serve that?"
- "Cache each dashboard's result for an hour, so that the scan runs only when that expires."
- "Add an index on the time column, so that the query reads only the rows it is asking for."
- "Keep coarser rollups as the data ages, and answer the long ranges from those instead."
- "Give dashboards replicas of their own, so that their scans leave the writes in peace."
"A team adds a user ID label to its request counter. What just happened to your system?"
- "Very little: a label is a few more bytes per point, and storage is the cheap part here."
- "It mints a series per user, so hold each metric to a budget and refuse what is over it."
- "The series count rises, so let the store add nodes whenever its memory starts to run out."
- "Queries on the label slow down, so add a secondary index that keeps those lookups fast."
"The collector has fallen over, and every alert reads through it. Who tells you?"
- "Run three collectors behind a load balancer, so that this one failure cannot happen."
- "Add an alert on the collector's health, evaluated by the same job as all the others."
- "Have every host's agent email the on-call engineer when it fails to deliver its points."
- "Give critical alerts a small path of their own, and a heartbeat watched from outside."
You got correct