KAHIBARO
Discord Login Register

20.11. Alerting

Why Alerting Matters

Monitoring tells you what is happening. Alerting tells someone that action is needed.

Alerting connects your system metrics, logs, and checks to humans or automated responders. Without alerting, you only find incidents when a user complains or when you look at dashboards manually.

Good alerting helps you:

Important: A monitoring system without alerting is almost useless in production. A bad alerting system can be worse than none, because it causes alert fatigue and real incidents get ignored.

Types of Alerts

You can think of alerts in several categories. This helps you design them more clearly.

By Source

SourceExamplesTools (typical)
MetricsCPU, memory, request rate, error ratePrometheus + Alertmanager
LogsSpecific error patterns, spikes in exceptionsLoki, Elasticsearch, Datadog Logs
TracesSlow spans, failing servicesJaeger, Tempo, X-Ray, etc.
SyntheticHealth check endpoints from outsideUptimeRobot, Pingdom, custom

Metrics-based alerts are usually the core of backend alerting. Log- and trace-based alerts are often used for specific conditions or debugging recurring failures.

By Purpose

PurposeDescriptionExample
Availability alertsService is down or unusableHealth check failing for 5 minutes
Performance alertsService is slow, but still worksp95 latency exceeds 500 ms for 10 minutes
Error-rate alertsToo many errors compared to normal5xx rate > 2% of all responses for 10 minutes
Capacity / saturationRunning out of resourcesDB connections > 90% of pool size for 15 minutes
Business / product alertsBusiness KPI problems, fraud detectionCheckout success rate drops below 80%
Security alertsSuspicious or malicious behaviorMany failed logins from same IP

By Urgency

You cannot treat all alerts the same. If you do, your on-call engineers will burn out.

Typical severities:

LevelMeaningExample
CriticalImmediate user impact, wake someone upAPI completely down, payments failing globally
HighSerious, fix during working hoursError rate increased, but system still mostly usable
MediumNeeds investigation soonBackground worker queue growing unusually fast
LowObservation or suggestionDisk usage > 70%, plan to increase volume size

Rule: Only Critical alerts should wake people at night. Everything else should be routed as lower-priority notifications.

Basic Alerting Concepts

To work with alerting tools, you should understand some common concepts.

Alert Rules

An alert rule is a condition plus some metadata about what to do.

Example in human language:

Trigger "High error rate" alert when 5xx responses are more than 5% of total responses for 10 minutes.

Common fields in an alert rule:

FieldDescription
NameHuman-readable name of the alert
ExpressionThe condition, often based on metrics
ThresholdThe value that indicates a problem
DurationHow long the condition must be true
SeverityHow urgent it is
Labels/tagsInfo for routing (service, team, environment)
DescriptionWhat the alert means and how to handle it

In Prometheus, for example, the condition is a PromQL expression like:

text
rate(http_requests_total{status=~"5.."}[5m]) 
/
rate(http_requests_total[5m]) 
> 0.05

You usually also specify a for: 10m duration so it only fires if the condition is true for 10 minutes.

Thresholds and SLOs

A threshold is the value where you decide something is too bad to tolerate.

Instead of picking random thresholds, production teams often define SLOs (Service Level Objectives), for example:

Then they build alerts around violations of these SLOs, or around being close to violating them.

Example pattern:

Pattern: Alert on symptoms, not just causes.
Instead of "CPU > 90%", prefer "Error rate > 2%" or "Latency > SLO".

High CPU alone might not hurt users. High error rate definitely does.

Alert States: Firing, Pending, Resolved

Most alerting systems have states like:

You typically only notify humans when the alert is firing. Some systems also send a "resolved" notification when things recover.

What to Alert On

For backend systems, some alert types are especially common.

Uptime and Health Checks

Use health endpoints that your service exposes, for example /healthz or /live.

Typical alerts:

Example service-level alert:

Error Rates

Instead of only counting errors, compare them to all requests.

Let:

Then the error rate is:

$$
\text{error\_rate}(t) = \frac{E(t)}{R(t)}
$$

Rule: Alert on ratio, not just raw counts.
5 errors per second could be trivial if you handle 10,000 requests per second, but huge if you only handle 20.

Example alert:

Latency (Response Time)

Latency describes how long requests take. Instead of an average, you want percentiles like p95 or p99, because outliers hurt users even if the average looks okay.

Example:

Resource Saturation

Monitor when you are close to limits:

You usually want capacity alerts to be warning-level, giving you time to act before a hard failure.

Examples:

Business and Security Signals

Over time, you add alerts closer to business impact, for example:

These are just metrics like any other, but they require thinking about business behavior.

Alert Destinations and Routing

An alert that no one sees is useless. You must send alerts to places where someone will react.

Common Destinations

DestinationUse case
EmailNon-urgent notifications, summaries
Chat (Slack etc)Team visibility, most alerts
Pager appsCritical alerts, wake on-call engineer
Ticketing (Jira)Track follow-up work on recurring problems
WebhooksTrigger automation, runbooks, or other tools

For Critical alerts in production, teams usually integrate alerting with:

Routing by Labels or Tags

Alerts often carry labels such as:

Then your alert manager uses routing rules:

This way, the right team sees the right alerts.

Avoiding Alert Fatigue

Alert fatigue happens when engineers receive so many alerts that they stop paying attention. This is very common in badly configured systems.

Common Causes of Bad Alerts

Good Practices

Use these guidelines to keep alerts useful:

  1. Start with a small, critical set.
    Focus on availability, error rates, and very bad performance first.
  2. Use a "for" period.
    Require the condition to be true for several minutes before firing.
  3. Group related alerts.
    Many alerting systems can group alerts by service or cluster, sending a single message about multiple instances failing.
  4. Tune thresholds over time.
    Look at real metric histories before picking values. Adjust if you see frequent false positives.
  5. Silence during maintenance.
    When deploying or doing maintenance, silence relevant alerts, or mark deployments to avoid false alerts.
  6. Review incidents.
    After a real incident or a noisy alert, update the alert rules. Bad alerts should be fixed or removed.

Rule: Every firing alert should be:

  • Actionable: You can do something specific.
  • Owned: A team is clearly responsible.
  • Relevant: It indicates real or likely user impact.
    If an alert fails any of these, change or delete it.

Writing Useful Alert Messages

The content of an alert is as important as the condition. At 3 AM, someone half-asleep must understand it quickly.

A good alert should answer:

  1. What is broken?
    Which service, which environment, which region.
  2. How bad is it?
    Severity, error rate, affected users if known.
  3. What should I check first?
    Links to dashboards, logs, and maybe a runbook.
  4. What changed recently?
    Often the cause is a recent deployment or config change.

Example: Bad vs Good Alert

Bad message:

"Error alert: high error count"

Good message:

`[CRITICAL][payments-api][production] 5xx error rate > 10% for 15m
Affected: /api/payments/*
Check: https://grafana.example.com/d/abcd/payments-api
Runbook: https://wiki.example.com/payments-api-runbook#high-error-rate`

The good example includes context, severity, and pointers to next steps.

Basic Alerting with Prometheus and Alertmanager

In many modern backends with Prometheus and Grafana, alerting works like this:

  1. Prometheus collects metrics from your services.
  2. You define alert rules in Prometheus.
  3. When a rule fires, Prometheus sends alert data to Alertmanager.
  4. Alertmanager groups, deduplicates, and routes alerts to email, Slack, paging tools, etc.

An abbreviated example of an alert rule (in YAML) could look like:

yaml
groups:
  - name: backend.rules
    rules:
      - alert: HighErrorRate
        expr: rate(http_requests_total{status=~"5.."}[5m])
              /
              rate(http_requests_total[5m]) > 0.05
        for: 10m
        labels:
          severity: critical
          service: payments-api
          environment: production
        annotations:
          summary: "High 5xx error rate on payments-api"
          description: "Error rate > 5% for more than 10m in production."

Alertmanager configuration then decides:

You do not need to master these tools yet, but understanding this flow helps you design your backend metrics and health checks so they can feed into alerting later.

Alerting and On-Call

In many teams, real-time alerting is connected to an on-call rotation. That is a schedule where one engineer is responsible for handling Critical alerts.

Key ideas:

As a backend developer, you contribute by:

Summary

Alerting is the bridge between your backend systems and human or automated responses. It builds on monitoring and observability, uses thresholds on metrics and logs, and routes information to the right people and tools.

Keep in mind:

With well-designed alerting, your backend can fail gracefully, and your team can respond quickly without being overwhelmed.

Views: 7

Comments

Please login to add a comment.

Don't have an account? Register now!