<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw" -->

---
title: Node.js worker threads in production | daily.dev
description: A detailed engineering writeup describes how Inngest moved its Connect SDK's WebSocket connection logic into a Node.js worker thread to prevent heartbeat...
canonical: https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Node.js worker threads in production | daily.dev
og:description: A detailed engineering writeup describes how Inngest moved its Connect SDK's WebSocket connection logic into a Node.js worker thread to prevent heartbeat...
og:url: https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw
og:image: https://api.daily.dev/og/posts/qs0opBgkW.png
og:image:alt: Node.js worker threads in production
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js worker threads in production

**[Inngest Blog](https://daily.dev/sources/inngest)** · 14 min read · 0 upvotes · 0 comments

## Summary

A detailed engineering writeup describes how Inngest moved its Connect SDK's WebSocket connection logic into a Node.js worker thread to prevent heartbeat failures caused by user code blocking the main event loop. It covers designing a message protocol as an API boundary, converting callbacks into a request-response RPC system over postMessage, sending protobuf-encoded bytes instead of rich objects, proxying loggers and other stateful objects that can't cross thread boundaries, packaging the worker as a real build artifact across ESM/CJS/TypeScript, capping crash-loop respawns with backoff, mirroring worker health/debug state back to the main thread, and treating shutdown as a graceful drain protocol rather than a hard terminate. It closes with lifecycle testing strategies using a transparent WebSocket proxy.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.inngest.com/blog/node-worker-threads-production>

## Questions this post answers

### How do you handle data that can't be sent across a Node.js worker thread boundary, like a logger or database client?

Keep stateful, behavior-holding objects such as loggers, metrics clients, tracing APIs, and database clients on the main thread rather than trying to pass them into the worker. The worker instead creates a logger-shaped proxy object whose methods send a message (type LOG with level, message, and data) over postMessage to the main thread, which then calls the real logger.

_daily.dev surfaces engineering writeups like this for developers designing thread-safe message protocols._

### How should a worker thread handle shutdown so in-flight requests aren't dropped?

Shutdown should be a drain protocol, not a call to worker.terminate(). The main thread sends a CLOSE message, the worker enters a CLOSING state, tells the Gateway to stop routing new work, lets in-flight executions finish while heartbeats and lease extensions keep running, flushes buffered responses, sends a CLOSED message back, then calls process.exit(0) itself since the parentPort listener keeps its event loop alive.

_Developers building resilient worker-thread shutdown logic can find engineering deep dives like this on daily.dev._

### How do you prevent a crashing Node.js worker thread from causing an infinite respawn loop?

Watch the worker's exit event, track consecutive crashes, and apply exponential backoff (base backoff doubled per crash, capped at a max) before respawning. Reset the crash counter only once the worker reaches a healthy state like CONNECTION_READY, not merely on startup. If crashes exceed a threshold, stop respawning and emit an error log instead of retrying forever.

_daily.dev helps engineers researching crash-recovery and backoff strategies for long-lived worker processes._

## Similar posts on daily.dev

- [Hardening Real-Time Matching Systems with Node.js and WebSockets](https://daily.dev/posts/hardening-real-time-matching-systems-with-node-js-and-websockets-niwsqbayc) · SitePoint · 0 upvotes · 0 comments
- [How to Go from Toy API Calls to Production-Ready Networking in JavaScript](https://daily.dev/posts/how-to-go-from-toy-api-calls-to-production-ready-networking-in-javascript-urjuzdobr) · freeCodeCamp · 2 upvotes · 0 comments
- [How workerd, the Cloudflare Workers runtime, is built](https://daily.dev/posts/how-workerd-the-cloudflare-workers-runtime-is-built-jripr3oyh) · Flavio Copes · 0 upvotes · 0 comments
- [Cloudflare Workers Accept Inbound TCP, with gRPC the First Protocol on Top](https://daily.dev/posts/cloudflare-workers-accept-inbound-tcp-with-grpc-the-first-protocol-on-top-pplojcdxn) · InfoQ · 0 upvotes · 0 comments
- [A TypeScript Class-Based WebSocket Library for React](https://daily.dev/posts/a-typescript-class-based-websocket-library-for-react-yeehki5b1) · iO tech\_hub · 57 upvotes · 0 comments

---

Tags: [#inngest](https://daily.dev/tags/inngest), [#nodejs](https://daily.dev/tags/nodejs), [#websocket](https://daily.dev/tags/websocket)

[View this post on daily.dev](https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Node.js worker threads in production","url":"https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw"},"datePublished":"2026-09-13T19:57:33.018Z","dateModified":"2026-10-15T02:22:32.344Z","description":"A detailed engineering writeup describes how Inngest moved its Connect SDK's WebSocket connection logic into a Node.js worker thread to prevent heartbeat...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ff709f077d379909ac7ace65a630959c?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ff709f077d379909ac7ace65a630959c?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Inngest Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Inngest Blog","logo":"https://media.daily.dev/image/upload/s--ieZKUa5y--/c_limit,w_256/f_auto,q_auto/v1789329423/logos/inngest?_a=BAMAMicg0","url":"https://daily.dev/sources/inngest"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"inngest,nodejs,websocket","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Inngest Blog","item":"https://daily.dev/sources/inngest"},{"@type":"ListItem","position":3,"name":"Node.js worker threads in production"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/node-js-worker-threads-in-production-qs0opbgkw#faq","mainEntity":[{"@type":"Question","name":"How do you handle data that can't be sent across a Node.js worker thread boundary, like a logger or database client?","acceptedAnswer":{"@type":"Answer","text":"Keep stateful, behavior-holding objects such as loggers, metrics clients, tracing APIs, and database clients on the main thread rather than trying to pass them into the worker. The worker instead creates a logger-shaped proxy object whose methods send a message (type LOG with level, message, and data) over postMessage to the main thread, which then calls the real logger. daily.dev surfaces engineering writeups like this for developers designing thread-safe message protocols."}},{"@type":"Question","name":"How should a worker thread handle shutdown so in-flight requests aren't dropped?","acceptedAnswer":{"@type":"Answer","text":"Shutdown should be a drain protocol, not a call to worker.terminate(). The main thread sends a CLOSE message, the worker enters a CLOSING state, tells the Gateway to stop routing new work, lets in-flight executions finish while heartbeats and lease extensions keep running, flushes buffered responses, sends a CLOSED message back, then calls process.exit(0) itself since the parentPort listener keeps its event loop alive. Developers building resilient worker-thread shutdown logic can find engineering deep dives like this on daily.dev."}},{"@type":"Question","name":"How do you prevent a crashing Node.js worker thread from causing an infinite respawn loop?","acceptedAnswer":{"@type":"Answer","text":"Watch the worker's exit event, track consecutive crashes, and apply exponential backoff (base backoff doubled per crash, capped at a max) before respawning. Reset the crash counter only once the worker reaches a healthy state like CONNECTION_READY, not merely on startup. If crashes exceed a threshold, stop respawning and emit an error log instead of retrying forever. daily.dev helps engineers researching crash-recovery and backoff strategies for long-lived worker processes."}}]}
```

