What this prompt does
This prompt implements a Node.js worker system for a [app_type] that must handle [cpu_task]. It generates a worker-thread pool with [pool_size] workers and task queuing, typed message passing using [serialization], cluster mode with [cluster_count] processes and sticky sessions, graceful shutdown on SIGTERM/SIGINT that finishes in-flight requests, worker health monitoring with auto-restart on crash, optional SharedArrayBuffer usage for [shared_data], benchmarks comparing single-thread versus worker threads versus cluster, and integration with [web_framework] without blocking the event loop. All message contracts get TypeScript types.
The structure works because it targets the real problem: CPU work blocking Node's event loop. Throwing more instances at a blocked loop rarely helps. Moving [cpu_task] into a worker pool plus clustering with graceful shutdown means heavy work runs off the main thread and in-flight requests survive a deploy. The benchmark step keeps the architecture decision evidence-based rather than guesswork.
When to use it
- A Node service is blocking the event loop on CPU-heavy
[cpu_task]. - You want to offload heavy work to a worker thread pool.
- You need clustering across
[cluster_count]processes with sticky sessions. - You want graceful shutdown so deploys do not drop in-flight requests.
- You need worker health monitoring with automatic restart on crash.
- You want benchmarks to justify the architecture rather than guessing.
Example output
You get a Node worker system: a [pool_size] worker-thread pool with a task queue, typed message contracts using [serialization], a cluster setup of [cluster_count] processes with sticky sessions, graceful shutdown handlers, health monitoring with auto-restart, optional SharedArrayBuffer for [shared_data], benchmark scripts comparing approaches, and [web_framework] integration — with TypeScript types for every message.
Pro tips
- Match
[pool_size]to available cores (often CPU count minus one) so workers do not starve the main thread. - Only reach for SharedArrayBuffer when
[shared_data]genuinely needs shared memory; it adds complexity and synchronisation concerns. - Test graceful shutdown under real load so in-flight
[cpu_task]requests actually complete before exit. - Run the benchmarks before committing to clustering — sometimes a worker pool alone is enough.
- Keep message contracts typed via
[serialization]so main/worker communication stays type-safe. - Verify sticky sessions work with your load balancer, or cluster routing will break stateful flows.