Express Production Health Check Endpoints in Node.js Docker — Readiness, Liveness, 5xx Logs
TL;DR: Give the marketplace pipeline two small Express endpoints: liveness says the Node.js process can answer, while readiness says this instance can accept a run. Poll through the external route, retain every sanitized 5xx, and keep compact run summaries longer than verbose success events. The bill is ingestion, indexed fields, retained bytes, query work, and alert evaluation. Start with events…
Two small Express endpoints are essential for health checks in Node.js Docker pipelines: liveness and readiness. The /health/live endpoint should be lightweight, confirming the Node.js process can respond. If the event loop is functional, it should return success; any dependency outage should not cause healthy processes to be restarted. The /health/ready endpoint controls work admission, requiring completed startup and loaded configuration. It should fail before a worker drains to prevent new batches from arriving.
To calculate storage costs, use the formula: events per run × encoded bytes × retained runs × storage overhead. For example, 8 million offers emitting four 700-byte events result in 22.4 GB per run and 672 GB across 30 runs before indexing or replication. One terminal event per offer is 5.6 GB, while 10,000 sampled successes at four events add 28 MB. Eliminating unnecessary events helps manage storage costs.
The primary purpose of an Express health check endpoint is to prove readiness. The /health/live endpoint should be shallow, confirming the event loop can function. The /health/ready endpoint ensures the system is ready to accept work. Both endpoints should return concise responses without credentials, dependency URLs, stack traces, or queue contents.
When logging, include a timestamp, severity, service, environment, pipeline_run_id, stage, HTTP status, error class, duration, and trace identifier. Avoid logging tokens, payment data, or raw bodies. The cardinality budget should be considered when narrowing search results. Use W3C Trace Context for interoperable propagation fields.
Attribute costs to each run and attach a stable run ID to logs and traces. Use low-cardinality ownership fields like service and environment. Avoid putting run or listing IDs into metric labels. Retain every sanitized 5xx failure, rejected batches, and one run summary. Sample repetitive successes to maintain diagnostic value.
External monitoring should be separate from the container. Self-checks cannot cover DNS, certificates, gateways, or routing. Local liveness checks are for supervision, while readiness should be polled through the path operators depend on. Alerts should be triggered by a sequence or window of failures, not a single miss. Distinguish between ready worker alerts and unready worker alerts.
Tests should cover startup, draining, sanitized 5xx, timeout, DNS failure, certificate failure, and alert recovery. Retain only compact records, successful work, and stable samples. Discard verbose events for successful transformations and indexed raw URLs, listing IDs, and exception text. Focus on bounded counters, summaries, stable samples, and complete sanitized failures. Measure encoded sizes and counts after launch and adjust retention policies accordingly.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.