Sign up free

Blog · November 27, 2026 · 12happy team

What a /health endpoint should check, and what it shouldn't

Most /health endpoints look like this:

app.get('/health', (req, res) => res.send('OK'));

It returns 200 as long as the process is running. That’s something, but not much. The database can be unreachable, the queue full and every real request failing, and this endpoint still says “OK”. Your monitor stays green through the whole outage.

A useful health endpoint answers a better question: can this app do its job right now? Here’s what that takes.

Check what the app can’t work without

Go through what a real request needs, and check each one:

  • The database. Run a trivial query, such as SELECT 1, with a short timeout. Checking that a connection pool exists isn’t enough; the pool can exist while every connection in it is dead.
  • The cache or session store, if requests fail without it.
  • The queue, if the app needs it to accept work.
  • The disk, if the app writes files: is there free space?
  • The providers it can’t work without, such as payments or email, but read the next section before you add them.

Give each check its own short timeout, a second or two, and run them in parallel. A health check that hangs for 30 seconds because one dependency is slow is a problem of its own.

Required or optional

Not every dependency should fail the whole check. Ask: if this one is down, is the site down for users?

  • Required: the database, for most apps. If it fails, return 503, and the monitor alerts.
  • Optional: a recommendations service, analytics, a search index the site can live without. Report it in the body, but keep returning 200.

Be careful with third-party providers. If the payment provider has an outage and your health check fails because of it, you get paged for something you can’t fix, and if a load balancer uses the same check, it may take your servers out of rotation for it. Usually it’s better to report providers in the body and watch them with a separate check.

Return the details in the body

The status code tells a monitor “up” or “down”. The body can say why:

{"status":"fail","db":"ok","cache":"ok","queue":"fail"}

A monitor with a keyword check can read it, and you choose how strict to be:

  • Alert when the body contains fail anywhere, and you hear about any broken dependency, required or optional, even on a response that returned 200.
  • Alert when it contains "status":"fail", and you hear only when a required one breaks.

The body also tells you which dependency broke, so you don’t start from zero.

Keep it fast and cheap

A health endpoint is called often: by your monitor, maybe from several locations, by a load balancer, by Kubernetes. Keep it light:

  • No heavy queries and no writes. SELECT 1, not a count over a large table.
  • Cache the result for a few seconds if many things call it, so a burst of checks doesn’t become a burst of database queries.
  • Leave it out of rate limiting and bot protection, or the monitor gets blocked and reports an outage that isn’t there.

Keep it private, or keep it vague

A public health endpoint is a gift to anyone mapping your system if it lists versions, hostnames, internal addresses or stack traces. Two common ways to handle it:

  • Keep the public one vague: ok / fail per dependency, nothing more.
  • Put the detailed one behind a secret: a token in a request header, or an endpoint that only answers on the internal network.

Never put a secret in the URL itself. URLs end up in logs, browser history and screenshots.

A small example

In Node.js with Express, with a PostgreSQL pool and a Redis client:

const withTimeout = (promise, ms) =>
  Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), ms))]);

app.get('/health', async (req, res) => {
  const checks = {
    db: withTimeout(pool.query('SELECT 1'), 2000),
    cache: withTimeout(redis.ping(), 1000),
  };
  const required = ['db'];
  const result = {};
  await Promise.all(
    Object.entries(checks).map(async ([name, check]) => {
      try { await check; result[name] = 'ok'; } catch { result[name] = 'fail'; }
    }),
  );
  const down = required.some((name) => result[name] === 'fail');
  res.set('Cache-Control', 'no-store');
  res.status(down ? 503 : 200).json({ status: down ? 'fail' : 'ok', ...result });
});

The database is required, so it decides the status code. The cache is reported, but doesn’t take the site down. The overall status field is fail only when a required check fails, so a keyword check for "status":"fail" agrees with the status code, and one for fail also catches the cache.

Liveness and readiness are different questions

If you run on Kubernetes, you may need two endpoints, not one:

  • Liveness: is the process stuck? If this fails, Kubernetes restarts the container. Keep it minimal; it should not check the database, or a database outage restarts every container at once and makes things worse.
  • Readiness: can this instance serve traffic? If this fails, the instance is taken out of the load balancer until it recovers. This is where the dependency checks belong.

Your external uptime monitor wants the readiness question: can a user get served?

Monitor it from outside

A health endpoint only helps if something calls it and tells you when it fails. Checking it from outside your own network also catches what an internal check can’t: DNS, certificates, the load balancer, the network in between.

With 12happy:

  • Create an HTTP monitor for https://yoursite.com/health. A response outside the expected status codes, or no response within the timeout, counts as down.
  • Add a keyword check that alerts when the body contains fail, for problems behind a 200.
  • Keep one more monitor on a real page users load, such as the home page or the login page. A health endpoint can say “ok” while the page people actually use is broken.

A failure is confirmed from a second location before anyone is alerted, so one bad network path doesn’t page you. Why that matters.

The free plan includes 50 monitors checked every 5 minutes, with HTTP and keyword checks. Pro is $15 a month, or $12 billed yearly, for 100 monitors, with checks as often as every 30 seconds.

A short checklist

  1. Check the database with a real query and a short timeout.
  2. Decide which dependencies are required; only those return 503.
  3. Return a short JSON body with ok / fail for each check.
  4. Keep it fast: no writes, no heavy queries, cache for a few seconds, no rate limiting.
  5. Keep it vague in public, or behind a secret header.
  6. Monitor it from outside, with a keyword check for fail, and keep one check on a real page.

Comparing uptime monitors? See all comparisons →