Design a metrics monitoring system - 500,000 servers send numbers every 10 seconds, engineers draw charts over 30 days, and a rule pages the on-call engineer when checkout fails for five minutes. Ingest, query and alerting are three workloads that pull in different directions. The staff-level signal is a series budget that says no before a bad label hurts every team, rollup tiers with a planner, and alert state that survives a dead evaluator and never turns "no data" into "healthy".
Written by a Staff+ Engineer and an Engineering Manager
12+ years of experience in distributed systems and real-time messaging. Tech lead for large-scale chat applications serving billions of users. Over 12 years of industry experience with 6 years in engineering leadership, building and scaling tech infrastructure teams that deliver end-to-end large-scale distributed systems.
Finished this lesson?
Sign in to save your progress across devices.
Tip: use ← and → to move between lessons.
Was this lesson helpful?
Rehearse this exact question with the author
45-minute mock with a Staff+ engineer who interviews at your target company. Premium members save $20.
What to Design?
Could you answer these today? Tick what you already know.
The happy path is quick to draw: servers send numbers, a database stores them, a chart reads them, a job checks rules. The interview is decided by four questions about what happens when a label explodes, a chart covers a month, an evaluator dies, or the store falls behind. Each one is a deep dive later on this page, with three designs side by side: the one that sounds right, a better one, and the one that holds.
Swipe to see all columns
| The four questions, and the answer that sounds right | |||
|---|---|---|---|
| # | The interviewer asks | The answer that sounds right | What it misses |
| DD1 | A deploy adds a user_id label to one metric. What happens? | We store it, storage is cheap | Every user becomes a series: 2 million where there were 10,000. The index breaks, not the disk, and it breaks for every team. Refuse the series before it exists, and name the metric and the label |
| DD2 | Someone opens a chart over 30 days. How is it fast? | ||
The same three habits answer all four:
Do not spend your questions on chart colours. Spend them on what the platform promises.
Swipe to see all columns
| Scope Decisions | ||
|---|---|---|
| Question | Agreed answer | Why it matters |
| Which data? | Numbers only. Logs and traces are other products | The store can be built for small numeric points and nothing else |
| Push or pull? | Push: an agent on every server sends batches | The gateway sees every sample first and can check limits before anything is stored (Phase 1, DD1) |
| How fast must an alert react? | A rule is checked every 30 seconds. A new sample is part of a check within 1 minute | |
Out of scope (say this out loud): log search, distributed tracing, anomaly detection with machine learning, billing-grade usage metering, and building the pager itself.
FR1 — Ingest. Agents send batches of samples. A sample is one number at one time for one series. A series is one metric name plus one combination of label values, for example http_requests_total for service checkout, route /pay, status 500, pod-17.
FR2 — Query. Users ask for an expression over a time range with a step, the distance between two points on the chart.
FR3 — Alert rules. A rule has an expression, a condition, and a for duration: how long the condition must hold before anyone is paged.
FR4 — Notify. The platform tells the right person when an incident starts and when it ends, once each.
The key principle behind all four
Swipe to see all columns
| Five facts and the conclusions they do not supportRead each row as: the fact on the left does not, by itself, imply the claim in the middle. | ||
|---|---|---|
| Fact | Does not imply | Why the gap exists |
| The gateway answered 200 | The sample is in the store | 200 means it is in the queue. The writers may be minutes behind |
NFR1 — Ingest scale. 5 million samples a second at peak from 500,000 servers.
NFR2 — Bounded cardinality. Cardinality is the number of series. It is a resource with a limit per metric and per team, like disk or memory.
NFR3 — Query speed. A typical chart answers in a few seconds, whatever its time range.
NFR4 — Trustworthy alerts. A rule is checked every 30 seconds. An incident pages once. A dead machine of the platform neither loses nor doubles a page.
NFR5 — Honest degradation. Under overload, samples may be dropped, with a counter that says why. Rules, incidents and their history are never dropped. Late samples are accepted within a fixed window.
| Capacity Thought Experiment | |
|---|---|
| Parameter | Value |
| Servers | 500,000, each with about 100 series |
| Active series | 50 million |
| Samples | One per series every 10 seconds: 5 million a second |
| Batches | One per agent every 10 seconds, 100 samples, about 15 KB: 50,000 requests a second |
| Inbound bytes | About 150 bytes a sample: 750 MB a second |
The number that identifies the real system is not the write rate. It is what one chart costs:
one service, one metric 10,000 series
30 days of raw points 259,200 points per series = 2.6 billion points
a screen about 720 points per line
A queue and enough disks handle 5 million small writes a second. The hard part is that readers want months, alerts want the last minute, and both read the same store. Compression ratio, retention and machine speeds on this page are illustrative assumptions.
Interviewer signal: candidates who say "it is a write-heavy system, so I use a time-series database" have named a product. Candidates who say "ingest, query and alerting fail in different ways, so I size and protect them separately" have found the design.
Three ideas shape everything:
Ingest wants fast appends and may shed load. Query wants fast reads over long ranges. Alerting wants a small state that is always right. A design that serves all three from one database lets the loudest one hurt the other two. So there is a queue in front of the store, pre-computed tiles behind it, and a separate small database for rules and incidents.
A sample costs 2 bytes. A series costs an index entry, memory, and a little time in every query that touches its metric. Labels multiply: 200 pods times 10 routes times 5 statuses are 10,000 series. One more label with a million values is a disaster. The platform must count series before it creates them.
"Error ratio over 5% for 5 minutes" needs memory: since when has it been over 5%? That memory, and the fact that a page was sent, must survive any machine. And the machine that cannot evaluate must say so, instead of guessing.
The core recognition
This is an append-only pipeline for the numbers, and a small transactional core for the decisions. The pipeline is allowed to be late or lossy as long as it says so. The core is not.
| Design Decisions | |
|---|---|
| Design choice | Reason |
| A queue between gateway and store | The gateway answers in 5 ms whatever the store does, and a store outage loses nothing |
| Series budgets checked at the gateway | A bad label is refused before it becomes an index entry, and only its own metric is hit |
Two rows carry the decisions: the alert rule and the incident. Everything else is either the mass of samples or a setting.
What a team wants to be told about. Written by people, read by the evaluators.
Swipe to see all columns
| alert_rules | ||
|---|---|---|
| Field | Type | Comment |
rule_id | STRING | Key, for example rule_42 |
tenant | STRING | The team that owns it, for example shop |
expression | ||
One row per rule and group while the condition holds. This is the state machine.
Swipe to see all columns
| incidents | ||
|---|---|---|
| Field | Type | Comment |
incident_id | STRING | Key, for example inc_7 |
rule_id, group_key | STRING | rule_42 and service=checkout. One open incident per pair |
Swipe to see all columns
| Supporting records | ||
|---|---|---|
| Record | What it holds | Why it exists |
| Raw point | Series, timestamp, value. One every 10 seconds, kept 15 days | The full detail for recent time |
| Rollup tile | Series, resolution (1 minute or 1 hour), start of the bucket, count, sum, min, max | |
A tile keeps four numbers, not one average, for a reason: the average of an hour is sum divided by count, and that stays correct when tiles are combined. The average of sixty averages does not.
Swipe to see all columns
| Storage | ||
|---|---|---|
| Store | Data | Consistency |
| Time-series store | Raw points and rollup tiles, compressed, keyed by series and time | Append-only and very large. May lose samples under overload, with counters |
| Ingest queue (a log such as Kafka, 500 partitions) | Samples on their way to the store, one hour of them | At least once. A sample written twice replaces itself |
| Control store (PostgreSQL) | Rules, incidents, notifications, silences, routes, budgets, leases | Transactions. Small, replicated, never dropped |
Swipe to see all columns
| The calls | ||
|---|---|---|
| Call | Who calls it | What it does |
POST /v1/metrics:batch | Agent | A batch of samples: metric, labels, value, timestamp, type. Answers 200 with accepted and dropped counts, 429 with Retry-After when the platform sheds load |
GET /v1/query?query=&start=&end=&step= | Dashboard, evaluator | |
A batch may be sent twice, because an agent retries when it sees no answer. That is harmless: a point is identified by its series and its timestamp, so the second copy replaces the first.
An error on a rule is shown on the rule, through the fourth call. It never disappears into a log.
Present the design as four short stories, each in its own colour on one whiteboard: Phase 1 ingest (black), Phase 2 roll up and query (blue), Phase 3 evaluate a rule (green), Phase 4 notify (purple). The number on an arrow is the same number in the animation and in the step table.
Swipe to see all columns
| The four phases | |||
|---|---|---|---|
| Phase | Colour | Story | What it leaves behind |
| Phase 1: Ingest a batch (FR1) | Black | The agent on pod-17 sends 100 samples. They pass the series check, wait in the queue and are appended to the store | 100 raw points |
| Phase 2: Roll up and draw a chart (FR2) | Blue | Finished minutes become tiles. mei opens a 30-day chart and the query service reads 1-hour tiles | Tiles, and one cached answer |
How to read the picture
http_requests_total, with 10,000 series. At 12:00:00 checkout starts to fail. mei looks at charts. priya is on call.Each phase below is an interactive walkthrough of the same picture. It plays on its own. You can pause it, step with the arrow keys, and click any component to read its role.
Goal: take 50,000 batches a second, answer each in a few milliseconds, and let nothing into the store that should not be there.
/v1/metrics:batchAgents → Ingest gatewayNothing is written in this step.
Swipe to see all columns
| Phase 1 step by step (black arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The agent on pod-17 sends a batch to the Ingest gateway: 100 samples with the timestamp 12:00:00 and the token of team shop. | Nothing yet |
| 2 | The gateway asks the Series limiter whether these 100 series may exist. All 100 are known. A known series always passes. | Nothing |
| 3 | The gateway appends the 100 samples to the Ingest queue. Each goes to the partition of its series. | 100 samples in the queue |
Why it is built this way
Because a writer can die between the two. If it moved the position first, the samples it had taken would be gone: the queue thinks they are done, the store never got them. Writing first means that after a crash the next writer reads the same samples again and writes them again. That is harmless, because a point with the same series and timestamp replaces itself.
Goal: make a chart over 30 days as cheap as a chart over one hour.
raw points of 12:00:00 to 12:00:50Rollup job → Time-series storeNothing is written in this step.
Swipe to see all columns
| Phase 2 step by step (blue arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | At 12:06 the writers are five minutes past the minute 12:00. The Rollup job reads the raw points of that minute: 6 per series. | Nothing |
| 2 | The job writes one 1-minute tile per series: count 6, sum, min, max. When an hour is finished, its 60 minute tiles become one 1-hour tile. | The tile of 12:00, and later the tile of the hour |
| 3 | mei opens a chart: checkout requests per second, last 30 days, step 1 hour. The Query service looks in its cache: nothing. | |
Why it is built this way
Because the first person to ask is usually someone in the middle of an incident, and that query would take 52 seconds. Tiles are cheap to compute as the data arrives: six points become one, in the background, a few minutes late. Paying a small cost for every minute, whether or not anyone looks, is what makes the one urgent read fast.
Goal: check every rule every 30 seconds and remember, durably, how long its condition has been true.
renew the lease of shard 12, load its rulesAlert evaluators (E1) → Control storeshard 12updateSwipe to see all columns
| Phase 3 step by step (green arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | 12:00:30, a tick. Evaluator E1 holds the lease of rule shard 12 and loads rule_42: error ratio of checkout over 5% for 5 minutes. | The lease is renewed until 12:01:00 |
| 2 | E1 asks the Query service for the value now. The Query service reads raw points and answers: 8%. | Nothing |
| 3 | 8% is over 5%, and there is no open incident for rule_42 and service=checkout. E1 creates one. | |
Why it is built this way
PENDING is the filter against noise. A spike of twenty seconds opens an incident and closes it again without a page. Only a condition that holds for the whole for duration fires.for plus at most a minute. Errors started at 12:00:00, the first tick that saw them was 12:00:30, the incident fired at 12:05:30. A faster page means a shorter for, not a faster platform.Because the requirement is a verdict every 30 seconds, not every millisecond. A scheduled query reuses the whole read path: the same language, the same tiers, the same cache. A stream processor would be a second implementation of every function in the query language, and sooner or later the two would disagree. If a rule ever needs a reaction within a second, that single rule can get a streaming path. The other 99,999 do not need it.
Goal: turn a state change into exactly one message to the right person.
SELECT notifications WHERE status = QUEUEDNotifier → Control storentf_1Nothing is written in this step.
Swipe to see all columns
| Phase 4 step by step (purple arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The Notifier reads the queued notifications from the Control store and takes ntf_1. | Nothing |
| 2 | It checks silences and routes. No silence matches service=checkout. The route says: on-call engineer of team shop, by pager. All 200 pods are failing, but the group is the service: one page, not 200. | Nothing |
| 3 | The Notifier calls the pager: "checkout error ratio 9%, over 5% for 5 minutes", with the dedup key inc_7:FIRING. The pager calls priya. | |
Why it is built this way
FIRING and back. The notification is recorded as SUPPRESSED, so the history shows what happened and why nobody was called.It is what the rule asked for. Thirty seconds went to the first tick, five minutes to the for duration, two seconds to the Notifier. The platform's own share is at most a minute. If the team wants to know sooner, they shorten for and accept more pages for short spikes. Say this trade-off in the interview: the delay is a setting of the rule, and the platform's part of it is bounded.
The deep dives are the four questions from the top of the page. Each one compares three designs for the same scenario: a Bad one, which is usually the answer that sounds right; a Good one, which still leaves a gap; and a Great one, which holds. The answers start covered. Read the scenario, decide what you would build, then click each card.
Swipe to see all columns
| Deep Dive Map | |||
|---|---|---|---|
| Deep Dive | Topic | Scenario | NFR |
user_id#Scenario: at 12:00 dan deploys a new version of checkout. It adds one label to http_requests_total: user_id, to make debugging easier. Checkout has 2,000,000 users. The metric had 10,000 series. What does the platform do?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. A label is just more data. The gateway accepts whatever the agents send.
Where it breaks. Every user who makes a request becomes a new series: about 556 a second, 2,000,000 within the hour, 200 times what the metric had. A series is not 2 bytes. It is an entry in the index, about 4 KB of memory: 8 GB more, from one metric. Writes slow down and the queue grows. Every query on this metric now touches 2 million series, so the checkout charts time out. And the store is shared: the charts and alerts of every other team slow down with it. Nobody is told why.
The idea. Every team gets a limit, for example 1,000,000 series. The gateway counts new series per team and refuses them when the limit is reached.
What it fixes. The damage has a ceiling, and it stays inside one team. shop has 400,000 series, so 600,000 new ones fit. At 12:18 the cap is reached and the growth stops.
What it still misses. From 12:18 on, every new series of shop is refused. That includes the 20 new pods of the payments service, which did nothing wrong: their metrics are simply missing. The counter says "team limit" and names no metric, so the team has to search for the cause. And the 600,000 junk series are already in the index: 2.4 GB that stay until they age out.
The key idea. Limit the thing that explodes. A metric may have 50,000 series, and each of its labels may have 1,000 distinct values. The check happens at the gateway, before a new series is created.
How it works
user_id pass. That takes about two seconds.dropped_samples_total with the reason label_limit, the metric and the label.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure. A dashed box is not part of every design.
/v1/metrics:batchAgents (checkout) → Ingest gateway200: acceptedNothing is written in this step.
Swipe to see all columns
| DD1 side by side | |||
|---|---|---|---|
| Bad: accept every label | Good: a cap per team | Great: a budget per metric and label | |
| What is limited | Nothing | All series of a team | Series per metric, values per label |
| New series from the deploy | 2,000,000 | 600,000 | 1,000 |
Check it against the scenario
| The user_id label arrives | |
|---|---|
| Situation | Outcome with the Great option |
| Samples of the 10,000 old series, from pods that still run the old version | Known series. They pass without any count |
A sample with a new user_id, value 1,001 | Refused before a series exists. Dropped and counted with metric and label |
| payments rolls out 20 new pods in the same minute | New values of the pod label, far under 1,000. Accepted |
| The limiter restarts and loses its sets | It is rebuilt from the index of the time-series store. Until then the gateways accept known series and hold back new ones |
The trade-off to name. After the deploy the new pods send every sample with a user_id, so most of their samples are dropped: the checkout request chart is incomplete until dan rolls back. That is the right failure. One metric of one service is wrong and says so within a minute, instead of the whole platform being slow for a reason nobody can see. The budgets themselves are work too: someone has to choose them, and a team with a real need has to ask.
Because the samples would then collide. Two users on the same pod, route and status would send two different counter values for what is now the same series at the same time, and the store cannot tell which is right. Adding them up correctly means aggregating inside the gateway, which is a different and much larger feature. Refusing is simple and honest, and the counter tells the owner exactly what to fix.
"The scarce resource in a metrics system is the number of series, not bytes. Every new combination of label values is an index entry, and one label with a value per user turns ten thousand series into two million. So I treat cardinality like a quota. Each metric has a budget of series and each label a budget of distinct values, kept in a control store. The gateway checks a shared limiter before it lets a new series exist. Known series pass with a lookup. A series over budget is refused, its samples are dropped, and a counter records the reason, the metric and the label, so the owning team is told within a minute. A cap per team alone is too blunt: it punishes the team's healthy metrics and does not say who caused it."
Follow-up: "How do you count distinct values cheaply?" — Exact sets where a limit is enforced, because the decision must be right. For trend charts of cardinality an approximate counter such as HyperLogLog is enough.
Scenario: mei opens "checkout requests per second, last 30 days". The metric has 10,000 series. She sees a spike near the end and zooms into the last 15 minutes. Both views must answer in a few seconds.
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. Store every sample as it came. A query reads what it needs.
Where it breaks. Thirty days at one point every 10 seconds are 259,200 points per series. For 10,000 series that is 2.6 billion points. At 50 million points a second the scan takes 52 seconds, and the query is cut off at 30. Even if it finished, mei's screen can draw about 720 points per line: 99.7% of what was read is thrown away. And keeping every raw point for ever costs 864 GB a day, 315 TB a year.
The idea. A background job writes 1-minute and 1-hour tiles. Whoever builds a dashboard picks the tier for each panel. The 30-day panel reads 1-hour tiles.
What it fixes. The long chart: 720 tiles per series, 7.2 million points, 0.14 seconds.
What it still misses. mei zooms into the last 15 minutes, and the panel still reads 1-hour tiles: one point. The spike of two minutes has vanished into an hourly average. The tile of the current hour does not exist yet, so the chart ends up to an hour before now, at the very moment she is looking at "now". And the alert rule reads raw points while the panel reads whatever someone chose by hand, so during an incident the chart and the alert show different numbers.
The key idea. The person asks for a range and a step. The query service decides where to read: the coarsest tier that is still at least as fine as the step.
How it works
tier: 1h, and it is cached for 60 seconds under expression, range, step and team.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure. A dashed box is not part of every design.
/v1/queryDashboard → Query service → RawNothing is written in this step.
Swipe to see all columns
| DD2 side by side | |||
|---|---|---|---|
| Bad: raw points only | Good: a fixed tier per panel | Great: a planner picks the tier | |
| What the 30-day chart reads | 2.6 billion raw points | 7.2 million tiles | 7.2 million tiles |
| Time | 52 s, cut off at 30 s | 0.14 s | 0.14 s |
Check it against the scenario
| Four reads of the same metric | |
|---|---|
| Query | What the planner does |
| 30 days, step 1 hour | 1-hour tiles, plus the unfinished hour from 1-minute tiles and the last minutes from raw. 0.14 s |
| 6 hours, step 1 minute | 1-minute tiles: 360 per series, 3.6 million points. 0.07 s |
| 15 minutes, step 10 seconds | Raw points: 900,000. 0.02 s |
| 30 days, step 10 seconds, typed by hand | Raw is kept 15 days, and the scan would exceed the limit. The answer is an error that suggests a step of at least 1 minute |
| The maximum latency over a week | |
The trade-off to name. Tiles are written a few minutes late and cost extra storage, about a sixth of the raw points for the 1-minute tier. A tile also forgets detail: you can get the average and the extremes of an hour, not what happened inside it. That is why raw points are kept for 15 days, the time in which people still zoom into an incident. After that, the hour is all there is.
The second viewer does. The first one waits 52 seconds, and during an incident the first one is the person who needs it most. A cache also holds one exact question: move the range by a minute or change the step and it misses. Tiles make every first read cheap. The cache then removes the repeats on top of that.
"A long range cannot be served from raw points: thirty days of one service are billions of points, and the screen shows a few hundred per line. So a background job keeps rollup tiers, one-minute and one-hour tiles holding count, sum, min and max. The query service has a planner that takes the range and the step and reads the coarsest tier that is still fine enough, stitches the newest part from a finer tier, and reports which tier it used. Alert rules go through the same planner, so they read raw for their short windows and agree with the chart. Raw data is kept for about two weeks, tiles much longer."
Follow-up: "Why min, max, sum and count, not the average?" — Because the average of averages is wrong when buckets hold different numbers of points. Sum and count can be added up. Percentiles need histogram buckets, which roll up the same way.
Scenario: inc_7 has been PENDING since 12:00:30. At 12:02:45 evaluator E1 stops. Another evaluator, E2, takes over its rules. Is priya paged at 12:05:30, as the rule promises, and only once?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. Each evaluator keeps a small table in memory: this rule has been breached since then. When the time is up, it calls the pager.
Where it breaks. E1's memory dies with it. E2 takes the rule at 12:03:30 and sees the breach "for the first time", so the clock starts again and the page goes out at 12:08:30, three minutes late. Had E1 died just after paging, E2 would know nothing about that either and would page priya a second time. And when the query service times out at 12:06:00, E2 gets no value, treats that as "no breach" and resolves an alert while checkout is still failing.
The idea. The incident row is written to the control store at every tick. A new evaluator reads it and carries on. When the time is up, the evaluator writes FIRING and calls the pager.
What it fixes. The lost clock. E2 reads "pending since 12:00:30" and fires at 12:05:30.
What it still misses. Writing FIRING and calling the pager are two steps. If E2 dies between them, the row says FIRING and no page was ever sent. Nobody will send it, because the next evaluator sees a state that is already right. Turn the order around and a crash gives a double page instead. And E1 may not have been dead, only frozen for a minute. It wakes up, still believes the rule is its own, and pages too.
The key idea. The evaluator only decides. It writes the new state and "someone must be told" in one transaction. Who may write is settled by a lease with a number that only goes up.
How it works
PENDING since 12:00:30.FIRING, and the notification ntf_1 is inserted. Its unique key lets it exist once. The Notifier sends it.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure. A dashed box is not part of every design.
E1's memoryEvaluator E1Nothing is written in this step.
Swipe to see all columns
| DD3 side by side | |||
|---|---|---|---|
| Bad: state in memory | Good: state in the database | Great: one transaction, numbered lease | |
| Where the state lives | In the evaluator's memory | In the control store | In the control store |
| After the takeover the page goes out at | 12:08:30 | 12:05:30 | 12:05:30 |
Check it against the scenario
| What can go wrong around 12:05:30 | |
|---|---|
| Situation | Outcome with the Great option |
| E1 dies at 12:02:45 | E2 holds the shard from 12:03:00, reads PENDING since 12:00:30 and fires on time |
| E2 dies right after its transaction at 12:05:30 | FIRING and ntf_1 are both stored. The Notifier sends ntf_1 |
| E2 dies right before that transaction | Neither is stored. The next evaluator finds PENDING, sees five minutes are over, and fires. One tick late |
The trade-off to name. Every tick of every rule with an open incident is a small write to a relational database, and the evaluators stop when that database is down. That is acceptable because the data is tiny: 100,000 rules and a few thousand open incidents. The database is replicated like any system of record. A lease also means a gap: after a crash the rules of that shard wait up to 30 seconds for a new owner.
A missed tick changes nothing: the state stays as it was, and the next tick decides with fresh data. The worst case is a page that is 30 seconds late. A tick on missing data makes a decision: "no breach" closes a real incident, and "breach" opens a false one. So the rule is that an evaluator may skip, and must say that it skipped, but it may not decide on what it could not see.
"An alert with a for-duration is a state machine: pending, firing, resolved. I keep that state per rule and group in a relational control store, not in the evaluator, so a replacement evaluator continues the same clock. Rules are split into shards, and an evaluator owns a shard through a lease with an epoch. Every write carries the epoch, so a paused evaluator that comes back cannot write. When an incident changes state, the evaluator writes the new state and a notification row in one transaction, with a unique key per incident and transition. A separate notifier delivers it at least once with a dedup key. And when the query fails, the evaluator records the error on the rule and leaves the state alone."
Follow-up: "What about silences?" — A silence is checked by the notifier, not by the evaluator. The incident still moves through its states, and the notification is recorded as suppressed, so the history stays complete.
Scenario: from 12:00 to 12:10 the store writers are down after a bad deploy of the platform itself. The agents keep sending 5 million samples a second: 3 billion samples. On top of that, pod-17 has a network problem, and its samples of 12:01 arrive at 12:04. What do the charts and the alerts show afterwards?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. No queue. The gateway writes each batch into the time-series store and then answers.
Where it breaks. At 12:00 every batch gets a 503. Agents keep a small buffer, about one minute of samples, and retry. After that minute the buffers are full and the agents throw samples away: nine minutes are missing from every chart, for ever. At 12:10 the store is back and 500,000 agents retry in the same second, which is a good way to take it down again.
The idea. The gateway appends to a queue and answers 200. The writers read the queue when they can.
What it fixes. The loss. The 3 billion samples wait. At 12:10 the writers return and read at twice the normal speed, and by 12:20 every sample is in the store.
What it still misses. Everything that goes by the wall clock is now wrong. At 12:06 the Rollup job writes the tile of 12:00, as it always does. The store has no points for that minute yet, so the tile is empty, and it is never corrected: the 30-day chart keeps a hole. From 12:00:30 the evaluators query the newest minute and find nothing. "No errors" resolves inc_7 while checkout is failing. And had the outage lasted more than an hour, the queue would have thrown away its oldest data without telling anyone.
The key idea. The writers publish how far they are: "everything up to this time is written". That time is the watermark. The Rollup job and the evaluators follow it, not the clock.
How it works
too_late.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure. A dashed box is not part of every design, and the arrow over the top is the Bad design's direct write.
/v1/metrics:batchAgents → Ingest gateway → Time-series storeNothing is written in this step.
Swipe to see all columns
| DD4 side by side | |||
|---|---|---|---|
| Bad: no queue | Good: a queue, by the clock | Great: a queue and a watermark | |
| Samples of the ten minutes | Nine minutes lost | Kept, written by 12:20 | Kept, written by 12:20 |
| The tiles of 12:00 to 12:10 | Do not exist | Empty for ever | Complete |
Check it against the scenario
| 12:00 to 12:20 | |
|---|---|
| Situation | Outcome with the Great option |
| 12:00 to 12:10: the agents send as always | 200 from the gateway. 3 billion samples, about 450 GB, wait in the queue |
| 12:05:30: inc_7 would fire | The watermark is at 12:00:00. No verdict. inc_7 stays PENDING, the rule shows that data is behind, the platform team is paged about the lag |
| 12:10 to 12:20: catch-up | The backlog shrinks by 5 million samples a second. Charts fill in from left to right |
| 12:20: the watermark is fresh again | The next tick sees the real values. The breach has held since 12:00:30, so inc_7 fires now |
The trade-off to name. During the lag the product alerts are blind, and the design says so instead of guessing. That only helps if someone is told: the platform needs its own small set of rules on queue lag, drop counters and evaluator errors, and those must not depend on the path that is broken. The late window is a choice too. Five minutes of waiting make every tile five minutes late, for ever, to catch the few samples that arrive late.
Firing on no data sounds safe and is not. A ten-minute outage of the platform would then page every on-call engineer of every team, for 100,000 rules, about a problem none of them has. After two such nights people stop trusting pages. The right page goes to the one team that can fix it, the platform team, and it says "ingest is behind". Rules that truly need an alarm when a service goes silent can ask for it with an explicit "no data" condition.
"I put a log-style queue between the gateway and the store, so an outage of the writers costs delay, not data. The part people forget is everything downstream that assumes the store is current. My writers publish a watermark, the time up to which all partitions are written. The rollup job cuts the tile for a minute only when the watermark has passed it by the late window, so a backlog never produces an empty tile. Evaluators compare the watermark with the clock, and if the data is more than a minute behind they record that, keep the incident state, and do not decide. Late samples are accepted within five minutes and dropped with a counter beyond that. If the backlog grows towards the queue's retention, the gateway sheds the lowest priority class first and counts it."
Follow-up: "What is your first metric for the health of ingest?" — The lag between the clock and the watermark. It is one number that covers a slow store, a slow writer and a full queue.
| If the interviewer keeps going | |
|---|---|
| Question | Short answer |
| Push or pull? | Push here: agents work behind firewalls, batch on their own, and every sample passes the gateway before a series exists. Pull fits when the platform already knows every target, for example inside one cluster manager, and it shows at once when a target is gone |
| Why not one relational database for everything? | 5 million inserts a second with an index entry per row, and reads that scan billions of rows. A time-series store keeps one index entry per series and compresses the points of a series together |
| An agent sends the same batch twice | A point is identified by series and timestamp. The second copy replaces the first, so nothing is counted twice |
| Who monitors the monitoring? | A small second path with its own rules: the lag behind the watermark, drop counters by reason, evaluator errors, notifier failures. Its pages go to the platform team, by a route that does not use the broken path |
For the patterns behind this page, see Time-Series Metrics Ingestion and Stream Processing and Real-Time Aggregation, and the Message Queues building block. The Notification System question uses the same "record first, send second" idea for its pushes.
The flood of samples then decides how safe your alert state is. Keep the mass of numbers in a store that may shed load, and the decisions in a small transactional one.
The cost of a metric is its number of series, and one label with a value per user multiplies it by millions. Give every metric and label a budget and check it before the series exists.
A limit that drops silently looks like a bug in the user's service. Count every drop with its reason, the metric and the label.
Thirty days of one service are billions of points for a chart that shows a few hundred. Keep rollup tiles and let a planner choose the tier.
The average of averages is wrong, and the maximum is gone. Keep count, sum, min and max.
A restart resets every pending clock and forgets every page already sent. Keep the state per rule and group in a database and guard it with a numbered lease.
Writing the state and calling the pager are two steps, and a crash between them loses or doubles the page. Write state and notification in one transaction and let a notifier send.
A failed query or a late store would then close real incidents. Keep the state, show the error, and page the platform team about the lag.
The shape of a strong answer: agents push batches to a gateway that checks a series budget, appends to a queue and answers. Writers move samples into a time-series store, and a background job keeps 1-minute and 1-hour tiles. One query service with a planner serves dashboards and evaluators alike. Evaluators run rules on a schedule, keep the incident state in a relational store, and write state changes together with their notifications. Everything that depends on fresh data follows the writers' watermark.
Three workloads, three stores
A queue and a time-series store for the numbers, which may be late or shed with a counter. A relational store for rules, incidents and notifications, which may not.
Say no early, and loudly
A series over budget is refused at the gateway, before it costs an index entry. A sample that is too late or shed under overload is counted with its reason.
"I could not look" is never "it is fine"
A failed query, a stale store or a lost lease keep the incident as it is and put an error on the rule. Only fresh data may open or close an incident.
| What the interviewer expects at each level | |
|---|---|
| Level | A strong answer shows |
| Junior | A correct flow from agent to chart: a gateway, a store, a query, a job that checks rules. Explains why one relational database is not enough and names one reason cardinality matters |
| Mid-level | Explains rollup tiers and why the step decides the tier. Describes pending and firing with a for duration. Puts a queue in front of the store and can say what the gateway's 200 means |
| Senior | Owns the tension between ingest, query and alerting. Enforces series budgets before a series exists. Keeps alert state durable, with one transaction for state and notification. Says what charts and alerts do while the store is behind, and how anyone can tell |
These aren't toy problems — they reflect real infrastructure challenges at companies that watch hundreds of thousands of servers. If you want to walk through this design in a mock interview or get feedback on your own approach, book a session with us. We're here to help you sharpen your thinking, build your confidence, and land your next offer.
Pick an answer for each question, and you see at once whether it is right. Show explanation opens the answer, why it is right, and why each of the other options fails.
Question 1 of 10
A metric has the labels service, route, status and pod: 10,000 series for checkout. A deploy adds the label user_id, and checkout has 2 million users. What is the real cost?
Question 2 of 10
Where does the platform enforce the series budget of a metric?
Question 3 of 10
An agent sends a batch and gets 200 with accepted 100. What does that promise?
Question 4 of 10
A chart shows 30 days of a metric with 10,000 series, with a step of one hour. What does the query service read?
Question 5 of 10
Why does a rollup tile store count, sum, min and max instead of the average?
Question 6 of 10
rule_42 says: error ratio over 5% for 5 minutes, checked every 30 seconds. The errors start at 12:00:00, and the first check that sees them is at 12:00:30. When is the incident FIRING?
Question 7 of 10
Why does the evaluator write the new incident state and the notification row in one transaction, instead of writing the state and then calling the pager?
Question 8 of 10
At a tick, the query for a rule times out. The incident of that rule is FIRING. What does the evaluator do?
Question 9 of 10
The store writers were down from 12:00 to 12:10 and are now catching up. When does the Rollup job write the 1-minute tile of 12:00?
Question 10 of 10
The ingest queue is 30 minutes behind and still growing. What does the platform drop first, and how can a team tell?
| We add a cache |
| The first read still scans 2.6 billion points: 52 seconds. Pre-computed tiles make it 7 million points, and a planner picks the tier per query so a zoom still sees raw data |
| DD3 | The alert evaluator dies while a rule is pending. Is the page late, lost or doubled? | Another evaluator takes over | Takes over with what? If the state was in memory, the clock restarts. If state and page are two steps, a crash between them loses the page. One transaction, and a numbered lease |
| DD4 | The store is down for ten minutes. What do charts and alerts show afterwards? | A queue buffers the samples | The samples survive. But a rollup that goes by the clock writes empty tiles, and an evaluator that sees no data says "all fine". Follow the writers, not the clock, and never turn "no data" into "healthy" |
| A schedule is enough. No separate streaming engine is needed (Phase 3) |
| Are labels limited? | Yes. The platform enforces limits and shows what it dropped | Without limits one team can slow down everybody (DD1) |
| How fast is a chart? | A few seconds, for the last hour and for the last year | A long range cannot be answered from raw points (DD2) |
| A missed check or a false alert? | A missed check is better than a verdict on stale data, and both must be visible | Decides what the evaluator does when it cannot see fresh data (DD3, DD4) |
| A label is useful | It is affordable | The cost is the number of distinct values. A user_id label has millions |
| The data exists | A chart can read it in time | 30 days of raw points for one service are 2.6 billion points |
| The condition is true | Someone is paged | It must stay true for the for duration first, and the page may be silenced |
| The query returned nothing | The service is healthy | The data may be late, or the query may have failed. Empty is not zero |
| 432 billion |
| Stored size | About 2 bytes a sample after compression: 864 GB a day |
| Raw points kept | 15 days: 13 TB |
| 1-minute tiles | 72 billion a day, 6 times fewer points than raw |
| 1-hour tiles | 1.2 billion a day, 360 times fewer |
| Alert rules | 100,000, each checked every 30 seconds: about 3,300 queries a second |
| Raw points, 1-minute tiles, 1-hour tiles |
| A 30-day chart reads 7 million points, not 2.6 billion |
| A planner that picks the tier per query | A long range is fast, a zoom still sees raw data, and the answer says which tier it used |
| Evaluators call the same query service as dashboards | The chart and the alert can never disagree about the same minute |
| Incident state in a relational control store | A new evaluator carries on where the dead one stopped |
| State change and notification in one transaction | A page is neither lost nor doubled by a crash |
| The rollup and the evaluators follow the writers' watermark | A backlog produces a delay, never an empty tile or a false "all fine" |
STRING |
| What to compute, in the query language. Here: the share of status 500 among checkout requests over the last minute |
condition | STRING | Over 5% |
for_duration | DURATION | 5 minutes. How long the condition must hold |
group_by | STRING[] | service. One incident per value, however many pods fail |
route | STRING | Who is told: the on-call engineer of team shop |
last_eval_at, last_error | TIMESTAMP, STRING | When it was last checked, and why the last check failed, if it did |
state | ENUM | PENDING: the condition holds, the for duration is not over. FIRING: it is over, someone is paged. RESOLVED: the condition no longer holds |
pending_since | TIMESTAMP | The first check that found the condition true |
last_value, last_eval_at | FLOAT, TIMESTAMP | What the last check saw, and when |
epoch | INT | The lease number of the evaluator that wrote last (DD3) |
| A summary of many raw points, so long ranges are cheap |
| Series budget | Per team and metric: most series, most values per label, an allowlist | What may become a series. Operator intent, so it lives in the control store |
| Notification | incident_id, transition (FIRING or RESOLVED), status QUEUED, SENT or SUPPRESSED. Unique per incident and transition | The promise to tell someone, written together with the state change |
| Silence | Label matchers, start, end, who created it | Suppresses notifications without deleting history |
| Shard lease | Rule shard, owner, epoch, expires_at | Says which evaluator may run which rules right now |
| Series limiter (in memory, shared by the gateways) | The known series, and counts per metric and per label | Fast and rebuildable from the time-series store |
Runs an expression over a range. Returns one line of points per series, the tier that was used, and warnings. Cut off after 30 seconds |
POST /v1/alerts/rules | User | Creates or changes a rule: expression, condition, for, group keys, route |
GET /v1/alerts/rules/{id} | User | The rule with its last check, its last error and its open incidents |
POST /v1/alerts/silences | User | Silences everything that matches some labels for a time |
PUT /v1/admin/policies/cardinality | Platform team | Sets series budgets and allowlists |
GET /v1/health | Anyone | Separate answers for ingest, query and evaluation |
| Phase 3: Evaluate a rule (FR3) | Green | Every 30 seconds an evaluator checks rule_42. The error ratio is over 5%: pending, and five minutes later firing | An incident that is FIRING, one queued notification |
| Phase 4: Notify (FR4) | Purple | The Notifier checks silences and routes and pages priya. Later the incident resolves and she is told that too | Two notifications, sent once each |
| 4 | The gateway answers 200: accepted 100, dropped 0. About 5 ms have passed. | Nothing |
| 5 | A store writer reads the next samples of its partitions. | Nothing yet |
| 6 | The writer appends each sample to its series in the Time-series store, then moves its position in the queue. | One raw point per series. A query sees it about 2 seconds after the agent sent it |
| Nothing |
| 4 | The Query service picks the 1-hour tier, because the step is one hour, and reads 720 tiles for each of the 10,000 series: 7.2 million points in 0.14 seconds. | Nothing |
| 5 | The Query service returns 720 points per line and says which tier it used. | The answer is cached for 60 seconds |
| 6 | Twenty seconds later a second engineer opens the same panel. The answer comes from the cache in 5 ms. The store is not touched. | Nothing |
incidentsPENDING| 4 | Every 30 seconds E1 asks again. At 12:05:30 the value is 9%. | Only last_eval_at and last_value move |
| 5 | The condition has held at every tick for five minutes. In one transaction E1 sets the incident to FIRING and inserts a notification. | inc_7: PENDING to FIRING. notifications row ntf_1: QUEUED |
| Nothing in our store yet |
| 4 | The Notifier records the result. | ntf_1: QUEUED to SENT, sent at 12:05:32 |
| 5 | 12:20:30: the fix is out and the value is 1%. In one transaction the evaluator sets the incident to RESOLVED and inserts a second notification. | inc_7: FIRING to RESOLVED. ntf_2: QUEUED |
| 6 | The Notifier sends "Resolved: checkout error ratio" and records it. | ntf_2: SENT, sent at 12:20:32 |
| DD1 |
A deploy adds the label user_id |
| One metric grows from 10,000 series to 2 million |
| NFR2 — Bounded cardinality |
| DD2 | A chart over 30 days | 2.6 billion raw points, then a zoom to 15 minutes | NFR3 — Query speed |
| DD3 | The evaluator dies between two ticks | A pending incident and a new evaluator | NFR4 — Trustworthy alerts |
| DD4 | The store writers are down for ten minutes | 3 billion samples wait, and one pod reports late | NFR1, NFR5 — Ingest scale, honest degradation |
| Index memory wasted |
| 8 GB |
| 2.4 GB |
| 4 MB |
| Who else is hurt | Every team | Every other metric of shop | Nobody |
| Who learns the cause | Nobody, until the store is slow | "Team limit", no metric named | The metric and the label, within a minute |
A team needs a region label with 30 values on a metric that is near its series budget | The platform team raises that metric's budget through the policy call. The change is recorded with who made it |
| Zoom to 15 minutes |
| Works, from raw |
| One point. The spike is lost |
| Raw, 0.02 s |
| The newest hour | There | Missing | Filled from the finer tier |
| Chart and alert agree | Yes | Not always | Yes |
| Raw points kept | For ever: 315 TB a year | 15 days | 15 days |
maxminmaxsumcount| State change and page |
| One step in memory |
| Two steps. A crash between them loses or doubles the page |
| One transaction, then the Notifier |
| A frozen evaluator wakes up | Pages again | Pages again | Its write is refused |
| The query fails | The alert is resolved by mistake | Depends on the code | State kept, error shown |
SENT| It sends ntf_1 again with the dedup key inc_7:FIRING. The pager shows one page |
| E1 was frozen and wakes up at 12:05:40 | Its writes carry epoch 3 and are refused. It drops the shard |
| The control store is down | No evaluator can read rules or write state. Evaluation stops and the health call says so. No state is guessed |
Retry-After, counted with the reason overload. Metrics that alerts depend on go last.| Alerts during the lag |
| No data |
| Resolved by mistake |
| State kept, "data is behind" shown |
| A sample 3 minutes late | Lost with the rest | Written | Written |
| An outage longer than the queue | The same loss | The oldest data is lost silently | Lowest class shed first, counted |
| A writer dies during catch-up |
| Another writer takes its partitions from the last stored position. A few samples are written twice and replace themselves |
| The checkout team asks why they were paged at 12:20 and not at 12:05 | The rule history shows fifteen minutes of "data is behind", and the platform incident explains it |
| Fifty people open dashboards during an incident | The cache answers the repeats. Each team has a limit on query cost, heavy exports wait, and the evaluators have capacity that dashboards cannot take |
| A team wants no pages during a planned maintenance | A silence with label matchers and an end time. Incidents still change state and notifications are recorded as SUPPRESSED, so the history stays complete |
| 200 pods fail at once | The rule groups by service: one incident, one page. The page says how many series are affected |
| Data older than 90 days | Only 1-hour tiles, kept two years. Old tiles can move to object storage. Queries there are slower and need a step of at least an hour |
| Percentiles, for example p99 latency | Not from averages. Services report histogram buckets, which are counters and roll up like any other series. The percentile is computed from the buckets at query time |
| How are series counted for the limit? | Exactly, with a set per metric and label, because the decision must be right. For charts of how cardinality grows, an approximate counter such as HyperLogLog is enough |
| Where do user IDs and request IDs go? | Into logs and traces. Metrics answer "how many and how fast", with labels that have few values |