Design a Pull-Based Server Metrics Monitor
Design scheduled server-metric collection with bounded workers, truthful failure states, dashboards and alerts.
Problem statement
For this exercise, assume one operations team owns an authenticated host inventory in one region. Each host exposes a read-only endpoint returning a bounded batch of CPU, memory, disk and application-health observations with timestamps.
Build a pull-based monitoring system that polls 1,000 servers every 10 minutes and can grow to 100,000 or more. Store observations, support dashboards and evaluate alert rules. Multiple scheduler replicas must not create duplicate logical collection Runs for the same interval.
Decide what happens when a previous Run is still unfinished: skip the next collection, cancel and replace the previous Run, or allow explicitly isolated concurrent Runs. Track the chosen disposition and Run state.
Write the core collection-worker code as part of the design. Bound concurrency, give each server an independent request timeout and isolate failures. A pool of 50 workers and a 200 ms timeout are examples to reason about, not mandatory constants.
A slow or unreachable host must not prevent other hosts from being observed. Failed collection is Unknown, never a successful metric value of zero. Dashboards and alerts must preserve the difference between a real observation, a last-known value and missing coverage.
Explain what happens during a network outage and how an operator can investigate a Run at 2 AM using logs, metrics and its traceable identity.
For this exercise, assume each admitted Run uses a fixed inventory snapshot and each target has one authoritative terminal outcome within that Run. Replayed or stale completions must not overwrite a newer outcome or current host view.
Bound queued as well as active work; use a deadline-aware read client, stop admitting work when Run authority is lost, and keep any retries within an explicit Run budget. Physical read-only requests may repeat during recovery; do not claim exactly-once network execution.
For this exercise, assume operators query current fleet status and the latest 24 hours, common dashboard reads should finish within 2 seconds at p95, and observations plus Run diagnostics are retained for 30 days. Acknowledged state must survive a process restart.
Alert predicates are supplied threshold rules over valid recent observations; missing coverage remains a distinct state. Automatic remediation, anomaly-model training, agent-push collection and active-active multi-region operation are outside scope.
What to build
- Create at most one admitted collection Run per interval, apply an explicit overlap policy and expose every interval disposition and Run state.
- Collect the snapshot of hosts with bounded workers, independent request deadlines and isolated, attributable success or failure outcomes.
- Let operators inspect current fleet status and recent history with observation time, freshness, coverage and Unknown outcomes.
- Evaluate supplied alert rules using valid observations and make collection failures, overdue work and recovery traceable by Run and host.
At scale
- The source workload grows from 1,000 to 100,000 or more hosts, with one collection interval every 10 minutes; avoid one unbounded task or connection per host.
- For this exercise, normally complete a healthy 100,000-host snapshot before the next interval. Use the illustrative 50-worker and 200 ms request budget to estimate capacity, then account for actual tails, retries and persistence overhead.
- For this exercise, common current-state and latest-24-hour dashboard reads should finish within 2 seconds at p95; show overdue, partial or stale coverage when collection cannot keep up.
- For this exercise, retain observations and Run diagnostics for 30 days, and recover acknowledged state after a process restart without fabricating successful observations.