Design a Monitoring and Alert System
HardReal World SystemsObserver PatternThresholdsMetricsTime SeriesAlert Management
Problem Statement
Design a production monitoring and alerting system like PagerDuty or Datadog alerts — where services emit metrics, alert rules are defined on thresholds, and notifications are triggered when conditions are met.
Requirements
Functional Requirements
- Register metrics sources (services/hosts)
- Record metric data points: (sourceId, metricName, value, timestamp)
- Define alert rules: metric + condition (>, <, ==) + threshold + duration window + severity
- Alert evaluation: continuously evaluate rules against incoming metrics
- Trigger alert when condition holds for the entire duration window
- Alert lifecycle: PENDING → FIRING → RESOLVED
- Notification channels: EMAIL, SLACK, PAGERDUTY, SMS
- Alert suppression: silence an alert for a configurable duration
- Dashboard: current metric values, active alerts, alert history
- Escalation: if alert not acknowledged within N minutes, escalate to next on-call
Non-Functional Requirements
- Thread-safe metric ingestion
- Async alert evaluation
- Singleton MonitoringService
Key Entities
- MetricSource: id, name, type (SERVICE/HOST/DATABASE)
- MetricPoint: sourceId, metricName, value, timestamp
- AlertRule: id, sourceId, metricName, condition, threshold, windowSeconds, severity, notificationChannels
- Alert: id, rule, status, firedAt, resolvedAt, annotations
- MonitoringService: Singleton; ingests metrics, evaluates rules, manages alerts
Constraints
- Metric ingestion must be non-blocking
- Alert evaluation runs asynchronously every 30 seconds
- Duration window: alert fires only if condition holds for entire window (not just a single point)
- Duplicate alerts suppressed: same rule cannot fire twice within cooldown period
!Constraints
- Metric ingestion is non-blocking (async write to in-memory time series)
- Alert fires only if condition is true for all data points within the window
- Same alert rule cannot re-fire within cooldown period (default 5 minutes)
- Alert suppression overrides all rules during silence window
- Escalation triggers after acknowledgment timeout (configurable, default 30 minutes)
Output
Run or submit your code to see output here.