---
title: "Node.js and the tale of worker threads"
description: "A Node.js service using cluster mode called os.cpus().length inside a Kubernetes container, which returns the host's core count, not the pod's CPU allocation."
url: "https://swe.quest/articles/node-js-and-the-tale-of-worker-threads-2f7f52d719f58af7"
canonical: "https://engineering.zalando.com/posts/2024/07/nodejs-tale-worker-threads.html"
source: "Zalando Engineering"
published: "2024-07-24"
difficulty: "medium"
kind: "Incident"
reading_minutes: 10
tags: ["javascript","kubernetes","incident-response","debugging","observability"]
---

# Node.js and the tale of worker threads

A post on [Zalando Engineering](https://swe.quest/sources/zalando.md), published 2024-07-24, 10 min read, Incident. Original: [https://engineering.zalando.com/posts/2024/07/nodejs-tale-worker-threads.html](https://engineering.zalando.com/posts/2024/07/nodejs-tale-worker-threads.html)

## Summary

A Node.js service using cluster mode called os.cpus().length inside a Kubernetes container, which returns the host's core count, not the pod's CPU allocation. On a 48-core node it forked 48 processes inside a 2GB pod. Each needed about 120MB, so the processes were killed under memory pressure and immediately re-forked by the exit handler, flooding a translation service with startup requests (1,000 to 20,000 rpm) and causing cancelled connections and read timeouts. The initial diagnosis of a retry feedback loop caused by process.exit() on fetch failure turned out to be wrong. The fix was to drop cluster mode and let Kubernetes handle scaling, and the incident motivated adding event-loop lag and other signals through an internal Node.js observability SDK.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Kubernetes](https://swe.quest/tags/kubernetes.md) (Infrastructure)
- [Incidents & postmortems](https://swe.quest/tags/incident-response.md) (Reliability & operations)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)

## Prerequisites

- Node.js cluster module ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- Kubernetes resource requests and limits ([easy posts on Kubernetes](https://swe.quest/tags/kubernetes.md?difficulty=easy))

## Keywords

Node.js, cluster module, os.cpus(), Kubernetes, AWS

## Related posts

- [Fully Loaded Node – A Node.JS Holiday Season, part 2](https://swe.quest/articles/fully-loaded-node-a-node-js-holiday-season-part-2-16ddab92917d79be.md): Mozilla Hacks · 2012-11-20 · Medium · 7 min read · JavaScript, Concurrency, Resilience, Scaling, Performance engineering
  Node.js runs JavaScript on a single core, so CPU-heavy work needs special handling to keep a server responsive.
- [Node.js at scale, rebalanced: how we cut cost by 38%](https://swe.quest/articles/node-js-at-scale-rebalanced-how-we-cut-cost-by-38-1008b397ea498cc9.md): Booking.com Engineering · 2026-09-29 · Medium · 17 min read · JavaScript, Performance engineering, Cost optimization, Load balancing, Runtimes & VMs
  Booking.com cut compute costs for its largest Node.js React SSR service by 38% (30% fewer pods, 20% less memory per pod, up to 10% lower tail latency) without touching service code, by moving from pm2's cluster-based processes to wattpm worker threads and revisiting long-untouched configuration.
- [2023-03-08 incident: A deep dive into our incident response](https://swe.quest/articles/2023-03-08-incident-a-deep-dive-into-our-incident-response-1c1581eb2c8b4a27.md): Datadog Engineering · 2023-06-01 · Medium · 17 min read · Incidents & postmortems, SRE, Kubernetes, Observability
  Datadog's March 8, 2023 global outage, triggered by an automatic systemd upgrade that broke Kubernetes nodes across isolated regions on multiple clouds, tested an incident process built on out-of-band monitoring, senior incident-commander rotations, blameless culture and a 30-minute customer update cadence.
- [How We Found 7 TiB of Memory Just Sitting Around](https://swe.quest/articles/how-we-found-7-tib-of-memory-just-sitting-around-a00b8a17b734c234.md): Render · 2025-10-30 · Medium · 7 min read · Kubernetes, Observability, Performance engineering, Cost optimization, Open source
  Render's Kubernetes clusters have an unusually large number of namespaces, and daemonsets that listwatch them, such as Vector's kubernetes\_logs source, used gigabytes of memory per node and put load on the apiserver during rollouts.
- [Debugging Systems in the Cloud: MySQL, Kubernetes, and Cgroups](https://swe.quest/articles/debugging-systems-in-the-cloud-mysql-kubernetes-and-cgroups-a5ded3f862ca5b21.md): Shopify Engineering · 2021-10-21 · Hard · 8 min read · Debugging, Linux, MySQL, Kubernetes, Performance engineering
  Slow MySQL Pod startup and degraded query performance on long-running GKE nodes in Shopify's KateSQL platform traced back to a Linux kernel memory cgroup leak: roughly 50K zombie memory cgroups made mem\_cgroup\_commit\_charge slow, so each 128MB mmap during InnoDB buffer pool initialization took about 100 ms. The investigation used strace, perf flamegraphs, slabtop and /proc/cgroups, and Google kernel engineers confirmed it as a side effect of slab reparenting on cgroup removal.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
