Aditya Dutt Pandey

Incident · 1 May 2026

Published · 3 min read

The most dangerous change I ever shipped was a cleanup

On 1 May 2026 a one-line tidy-up moved our queue sweepers into startWorker(). CI was green. Thirty seconds after the deploy, production was down. Why the change looked right, why CI couldn't see the problem, and the question I ask before every change like it now.

The most dangerous change I've shipped was a cleanup. One line that made the code tidier. On 1 May 2026 it took tunyt's production down thirty seconds after CI went green. I wrote that line.

One place for everything that starts

tunyt does a lot of work in the background: notifications, analytics, AI jobs. That work lives in queues, and each queue has sweepers. A sweeper is a small loop that keeps a queue healthy: it finds stuck jobs, cleans up old ones and nudges things along.

Our workers all started in one function, startWorker(). The sweepers started somewhere else, and that bugged me. Two places where background work starts means two places to forget something and two places to read when you're debugging at night.

So I moved the sweepers into startWorker(). Lint passed, tests passed, the build passed.

I still think one place for startup is good engineering. What I didn't do was count.

What that line did

startWorker() gives the work its own worker thread. In Node a worker thread is a separate JavaScript runtime with its own heap, its own event loop and, in our setup, its own connections.

Every sweeper I moved got the full package. On one node, at the same moment, that meant:

  • 21 V8 runtimes,
  • 21 thread pools,
  • 21 Redis connections,

all booting together and fighting for CPU and memory while the API tried to serve real users. The node went down.

Why CI couldn't catch it

CI checked that the code was correct, and it was. The sweepers still swept, the workers still worked, the types lined up.

CI never checks what happens when you start 21 of something on one box at once. That's a capacity question, and our pipeline had nothing to say about capacity. Green CI tells you the code does what you wrote. It can't tell you whether you should have written it.

Threads only for work that needs them

The fix came from looking at what sweepers do. They mostly wait: ask Redis something, wait, ask the database something, wait.

Node's event loop is built for that. Thousands of things can wait on one thread and cost almost nothing while they wait. A thread helps when CPU work would otherwise block everything else. For work that mostly waits, a thread costs a whole runtime and gives you nothing back.

So the sweepers went back onto the main event loop. The rule now: only CPU-heavy work gets its own thread.

// Mostly waiting on I/O: stays on the event loop, where waiting is cheap.
startSweepers(queues);

// CPU-heavy: worth a thread, because it would otherwise block everything else.
startWorker("some-cpu-heavy-job");

Count before you multiply

You pay for isolation per instance. A thread, a runtime, a connection pool, a container: each costs memory and start-up time, and that cost multiplies by however many you create. One extra worker is nothing. Twenty-one at once, on one node, during a deploy, is an outage.

Before I split anything into its own worker, process or service, I write down two numbers: what one instance costs, and how many there will be. If I can't answer both, I'm not ready to ship it.

What I do now

For anything that touches how processes, workers or connections start, I ask: does this multiply something? It's a version of the question I ask before shipping anything, which is what breaks first if 100K users hit this tonight. On 1 May the 100K was my own code.

By , CTO of tunyt

← All writing