Back to Blog
Technical 9 min read

How to Monitor Your API for Downtime (Step-by-Step Guide for 2026)

AlertSleep Team
AlertSleep Team
Monitoring & DevOps
Updated

TL;DR:

  • Uptime monitoring = automated external checks that detect failures from where your users sit β€” not from inside your infrastructure
  • A good monitor checks 4 things: availability (HTTP status), response time, response correctness (body validation), and certificate/infrastructure health
  • Build a /health endpoint that returns 503 when unhealthy and checks real dependencies (DB, cache) β€” not just a hardcoded {"status":"ok"}
  • Configure 2-3 consecutive failures before alerting + multi-region checks to eliminate false positives
  • Monitor authenticated endpoints with a dedicated service token or by embedding auth checks into your /health route
  • Key metrics to track: MTTD (time to detect), MTTR (time to resolve), uptime %, P95 response time

Most developers think about monitoring the wrong way.

They think about it as something you add after your app breaks. A reactive measure. A "we should probably set that up" item that lives at the bottom of the backlog until an incident forces it to the top.

Here's a better mental model: uptime monitoring is a sensor. It doesn't prevent failures β€” nothing does β€” but it determines how long failures go undetected. And in production systems, the cost of downtime scales almost linearly with detection time.

This article covers what uptime monitoring actually is, how it works under the hood, and specifically how to monitor an API properly β€” not just "is port 443 open," but "is my API actually doing what it's supposed to do."

The Four Things an Uptime Check Actually Measures

1. Availability (Is It Up?)

The most basic check: does the endpoint return a 2xx status code within a timeout period? A 200 OK means available. A connection timeout, a 502, a 503 means not available.

This is the "heartbeat" check β€” useful, necessary, but not sufficient on its own.

2. Response Time (Is It Fast Enough?)

An endpoint that responds in 45 seconds is technically "up" but practically down from a user experience perspective. Uptime monitoring should track latency alongside availability.

Useful thresholds:

  • Warning: 2-3x the baseline response time
  • Critical: User-perceptible slowness (typically >3-5 seconds for APIs)
  • Emergency: Approaching your client-side timeout

3. Response Correctness (Is It Returning the Right Thing?)

This is where most simple monitors fall short. A server can return a 200 OK with a completely broken response body. A misconfigured cache returns a 200 with yesterday's data. A half-deployed feature returns a 200 from an old code path that shouldn't be serving requests anymore.

Correctness checking means validating the actual response content β€” checking for specific fields, values, or structure β€” not just the status code.

4. Certificate and Infrastructure Health (Will It Keep Working?)

SSL certificate expiry, domain expiry, DNS resolution β€” these don't affect today's uptime, but they're time bombs. A monitor that tracks your cert expiry and alerts at 30 days gives you a month to act. One that doesn't leaves you explaining to users why there's a scary warning on your login page.

How to Monitor an API Properly

Monitoring an API is different from monitoring a website. Your homepage might return a 200 OK even when your API is completely broken. These are separate things, and they need separate checks.

Step 1: Identify What to Monitor

Don't just monitor your base URL. Map out the endpoints that matter:

Priority 1 β€” Core functionality:
  POST /api/auth/login
  GET  /api/users/me
  GET  /api/dashboard

Priority 2 β€” Revenue-critical:
  POST /api/subscriptions
  POST /api/payments/checkout

Priority 3 β€” Supporting services:
  GET  /api/health
  GET  /api/status

For most APIs, monitoring the health check endpoint plus 2-3 core business-critical endpoints gives you 90% of the signal you need.

Step 2: Build a Proper /health Endpoint

If your API doesn't have a /health endpoint, build one before you do anything else. It should:

  • Return 200 OK when everything is working
  • Return 503 Service Unavailable when something is degraded
  • Check actual dependencies (database connection, cache, external services)
  • Respond quickly (under 500ms)

Here's a production-ready implementation in Node.js:

// routes/health.js
const db = require('../db');
const redis = require('../cache');

app.get('/health', async (req, res) => {
  const startTime = Date.now();
  const checks = {};
  let overallStatus = 'ok';

  // Database check
  try {
    await db.raw('SELECT 1');
    checks.database = { status: 'ok' };
  } catch (err) {
    checks.database = { status: 'error', message: err.message };
    overallStatus = 'degraded';
  }

  // Cache check
  try {
    await redis.ping();
    checks.cache = { status: 'ok' };
  } catch (err) {
    checks.cache = { status: 'error', message: err.message };
    // Cache failure = degraded, not down (depending on your setup)
    if (overallStatus === 'ok') overallStatus = 'degraded';
  }

  const response = {
    status: overallStatus,
    timestamp: new Date().toISOString(),
    responseTime: Date.now() - startTime,
    checks,
  };

  const httpStatus = overallStatus === 'ok' ? 200 : 503;
  res.status(httpStatus).json(response);
});

And in Python (FastAPI):

from fastapi import FastAPI, Response
from datetime import datetime
import time

app = FastAPI()

@app.get("/health")
async def health_check(response: Response):
    start = time.time()
    checks = {}
    overall_status = "ok"

    # Database check
    try:
        await db.execute("SELECT 1")
        checks["database"] = {"status": "ok"}
    except Exception as e:
        checks["database"] = {"status": "error", "message": str(e)}
        overall_status = "degraded"

    result = {
        "status": overall_status,
        "timestamp": datetime.utcnow().isoformat(),
        "response_time_ms": round((time.time() - start) * 1000),
        "checks": checks,
    }

    response.status_code = 200 if overall_status == "ok" else 503
    return result

The key design decisions here:

  • 503 on degraded β€” Your monitor needs a machine-readable signal. Don't return 200 with a "status: error" body; that requires body parsing to detect. HTTP status codes are unambiguous.
  • Check real dependencies β€” A health endpoint that just returns {"status": "ok"} unconditionally is useless. Check the database. Check Redis. Check whatever your service actually needs.
  • Keep it fast β€” Set a short timeout on your dependency checks. If the DB doesn't respond in 300ms, that's the failure signal you need.

Step 3: Configure Your Monitor Correctly

Once your endpoint exists, configure your uptime monitor with these settings:

Check interval: 1 minute for production APIs, 5 minutes if your tool limits you to that. Every minute is the sweet spot β€” fast enough to catch failures before users flood your support inbox, slow enough to avoid rate limiting your own endpoints.

Alert threshold: Do not alert on the first failure. Network blips happen. Configure your monitor to alert after 2-3 consecutive failures. Tools like AlertSleep let you set this threshold directly β€” it's one of the most important settings you'll configure.

Multi-region checks: A single-location monitor is a single point of failure in your monitoring infrastructure. If your monitoring provider's Frankfurt node has a bad day, you get paged for a problem that doesn't exist. Use a tool that checks from multiple geographic locations and requires consensus before firing an alert.

Response validation: Configure your monitor to check the response body, not just the status code. For a JSON API, you want to verify that the response contains the fields you expect:

// Expected response from GET /api/health
{
  "status": "ok",
  "checks": { ... }
}

Your monitor should verify response.status === "ok", not just HTTP 200.

Timeout: Set a request timeout that matches your users' patience β€” typically 10-15 seconds. An API that takes 20 seconds to respond is broken from a user perspective, even if it eventually returns 200.

Step 4: Monitor Authenticated Endpoints

Most important API endpoints require authentication. Your monitor needs to handle this.

Options:

Option A β€” Dedicated monitoring token: Create a service account or API token specifically for monitoring. This gives you a separate audit trail and lets you revoke monitoring access independently of real users.

# AlertSleep or similar: add Authorization header to your monitor
Authorization: Bearer your-monitoring-service-token

Option B β€” Public health endpoint with internal checks: Expose a /health endpoint that doesn't require authentication but internally verifies that your auth system is working:

app.get('/health', async (req, res) => {
  // Check that the JWT signing key is accessible
  try {
    const testToken = jwt.sign({ test: true }, process.env.JWT_SECRET, { expiresIn: '1s' });
    jwt.verify(testToken, process.env.JWT_SECRET);
    checks.auth = { status: 'ok' };
  } catch (err) {
    checks.auth = { status: 'error' };
    overallStatus = 'degraded';
  }
  // ... rest of health check
});

Option C β€” Synthetic transaction monitoring: For critical flows (login β†’ create resource β†’ delete resource), some monitoring tools can simulate a full user flow. This is more complex to set up but catches failures that a simple endpoint check misses β€” like "the endpoint returns 200 but the data isn't actually being saved."

Step 5: Set Up Alerting That Reaches You

The best monitoring setup in the world is useless if the alerts don't reach you. Layer your alert channels:

Tier 1 β€” Always on:
  Email (low urgency, good for review)

Tier 2 β€” During business hours:
  Slack / Teams (team-visible, threaded discussion)

Tier 3 β€” On-call hours:
  SMS (cuts through silent mode)
  Phone call (for P0 incidents β€” wakes you up)

The key is matching alert channel to urgency. Not every failed check warrants a 3am phone call. But a sustained outage on your payment API absolutely does.

What Good API Monitoring Looks Like in Practice

After setting this up, here's what your monitoring dashboard should tell you at a glance:

  • Current status of each monitored endpoint (up / degraded / down)
  • Response time trend over the last 24 hours
  • Incident history β€” when did each endpoint last fail, how long was it down
  • Uptime percentage β€” rolling 30-day and 90-day figures
  • Alert log β€” who was notified and when

And when something goes wrong, your incident flow should look like this:

t+0:00  Monitor detects first failure
t+1:00  Second consecutive failure confirmed
t+1:00  Alert fires: Slack message + SMS to on-call
t+1:00  Status page auto-updates to "Incident detected"
t+X:XX  Engineer acknowledges, starts investigation
t+X:XX  Incident resolved, status page updates, users notified

The entire detection-to-notification chain should take under 2 minutes. Anything longer is signal you're missing.

The Metrics That Actually Matter

After you've been running uptime monitoring for a few weeks, you'll have data to answer the questions that matter:

MTTD (Mean Time to Detect): How long between a failure starting and your monitor catching it. Your check interval is the ceiling on this number.

MTTR (Mean Time to Resolve): How long between detection and resolution. Monitoring doesn't improve this directly, but faster detection gives your engineers more time to fix before users notice.

Uptime percentage: Rolling 30-day uptime for each endpoint. What's your actual SLA vs your advertised SLA?

P95 response time: The 95th percentile of your API response times. Averages lie β€” P95 tells you what your slower requests look like.

Getting Started

The setup isn't complicated. In order:

  1. Add a /health endpoint to your API that returns 503 when unhealthy
  2. Sign up for an uptime monitoring service β€” AlertSleep covers the basics from $59 a year, with a 14-day trial
  3. Add monitors for your health endpoint and your 2-3 most critical API routes
  4. Configure multi-region checks and a 2-failure confirmation threshold
  5. Set up alert channels that will actually reach you when something breaks
  6. Connect your monitors to a public status page

The entire process takes under an hour. The alternative is finding out your API has been down for three hours because a user posted about it on Twitter.

How are you currently monitoring your API? Single health check, synthetic transactions, something custom? Drop your setup in the comments β€” always interested in how teams solve this differently.

#api monitoring #api uptime monitoring #how to monitor api #api downtime #monitor api endpoints

Share this article

About the Author

AlertSleep Team

AlertSleep Team

Monitoring & DevOps

The AlertSleep team helps developers and ops teams keep their services online and communicate outages professionally.

Related Articles

Stay Updated

Get the latest articles and monitoring tips delivered to your inbox.