DEV Community

tanmay kuamr chaurasia
tanmay kuamr chaurasia

Posted on

Proactive Backend Alerting: Catch Outages Before Your Users Do

There is a specific kind of dread every backend engineer knows: opening Twitter or your support inbox and seeing a customer ask, "Is the site down?"

By the time a user reports an outage, your service has likely been broken for minutes—or even hours. The failure wasn't silent; your monitoring system was simply blind to it.

Most basic setups only check if the root URL (/) returns an HTTP 200 status code. But a healthy landing page does not mean your database connection pool hasn't exhausted or your payment processing queue hasn't stalled.

To build systems that report failures before customers do, you need to move beyond simple ping checks. Here is how to structure proactive alerting on your backend step by step.

Step 1: Implement Deep Health Checks

A shallow health check only verifies that your web server process is alive. A deep health check actively verifies that your application can reach its critical dependencies, such as databases, caches, and third-party APIs.

Instead of pointing your uptime monitors at /, expose a dedicated /healthz/deep endpoint.

Here is an example pattern using Python and FastAPI that checks database connectivity and records connection latency:

from fastapi import FastAPI, Response, status
import time
import asyncpg

app = FastAPI()

@app.get("/healthz/deep")
async def deep_health_check(response: Response):
    checks = {"status": "healthy", "components": {}}

    # Check Database Connection & Latency
    start = time.perf_counter()
    try:
        conn = await asyncpg.connect("postgresql://user:pass@localhost:5432/db")
        await conn.execute("SELECT 1;")
        await conn.close()

        latency_ms = (time.perf_counter() - start) * 1000
        checks["components"]["database"] = {
            "status": "up", 
            "latency_ms": round(latency_ms, 2)
        }
    except Exception as e:
        checks["status"] = "unhealthy"
        checks["components"]["database"] = {
            "status": "down", 
            "error": str(e)
        }

    # Signal failure to external uptime monitors
    if checks["status"] == "unhealthy":
        response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE

    return checks
Enter fullscreen mode Exit fullscreen mode

Point your external monitoring tools (such as Better Stack, Datadog, or UptimeRobot) at this endpoint so you are immediately notified if a core dependency drops.

Step 2: Alert on Degradation, Not Just Outages

A service that takes 10 seconds to respond is broken for your users, even if it eventually returns an HTTP 200. Waiting for hard 5xx errors to trigger an alert means you miss major performance degradations.

Collect request metrics and set up alerts for high-percentile latency (such as p95 or p99) over a sustained time window.

Here is a sample Prometheus rule that fires an alert if 95% of your API requests take longer than 1.5 seconds over a 3-minute period:

groups:
  - name: backend_latency_alerts
    rules:
      - alert: HighLatencyP95
        expr: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le)) > 1.5
        for: 3m
        labels:
          severity: critical
        annotations:
          summary: "API P95 Latency High"
          description: "95% of requests are taking longer than 1.5s over the last 3 minutes."
Enter fullscreen mode Exit fullscreen mode

Step 3: Track Silent Failures (Crons and SSL)

Two of the most common silent failure modes in backend engineering are expired SSL certificates and failed background cron jobs.

  • Background Jobs: Use a "dead man's snitch" pattern. Instead of relying on a cron job to send an alert when it fails, have the script ping an external monitoring URL upon successful execution. If the monitor does not receive a ping within the expected interval, it alerts your team.
  • SSL Certificates: Configure automated checks to alert you 30 days before certificate expiration. Auto-renewal scripts fail regularly due to rate limits or DNS verification changes.

Step 4: Route Alerts to Actionable Channels

An alert that lands in an unread email folder does not exist.

Divide your alerting channels based on urgency:

  1. Warnings (Slack/Discord/Teams): Non-urgent issues like high disk usage (70%) or SSL certificates expiring in 30 days.
  2. Critical Alerts (PagerDuty/Opsgenie/Phone Calls): Failures that directly impact user experience, like database disconnects or p95 latency spikes.

Building systems that tell you about problems first gives you time to fix them quietly, preserving user trust without public apologies.


Tanmay builds AI agents and automation for businesses and is open to freelance projects. If you want to strengthen your backend infrastructure or automate your DevOps workflows, connect with Tanmay on LinkedIn.

Top comments (0)