Menu

How I built a fault-tolerant Node.js backend — Docker, HashiCorp Consul, and GitHub Actions
📰

How I built a fault-tolerant Node.js backend — Docker, HashiCorp Consul, and GitHub Actions

DEV Community·Shahin Quliyev·6 months ago
#mWlw2NAf
#problem#node#backend#docker#health
Reading 0:00
15s threshold

I was working on iTicket.AZ — a backend service for real-time event ticketing, built with Node.js and TypeScript — when I came across a job posting at a major bank. Their requirement: "build scalable, resilient, and fault-tolerant applications."

I looked at my own backend and asked honestly: is this fault-tolerant? The answer was no. The server had no health awareness, no service discovery, no restart policy, and no automated build verification. This post is about exactly what I fixed — with real code from the project.

Problem 1 — The backend had no health awareness

When the database went down, the backend kept accepting HTTP requests and silently failing all of them. No signal to any external system.

app . get ( " /api/v1/health " , async ( _req , res ) => { const dbOk = await AppDataSource . query ( " SELECT 1 " ) . then (() => true ) . catch (() => false );

res . status ( dbOk ? 200 : 503 ). json ({ status : dbOk ? " healthy " : " degraded " , checks : { database : dbOk ?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.