Stateless Node.js services: workers, shared state, and graceful shutdown
A Node process runs your JavaScript on a single event-loop thread, so using more cores and more machines means changing how the service is built. Each Question covers one piece: why instances must be stateless, cluster vs. worker_threads, moving sessions into Redis, what goes wrong with sticky sessions, draining connections on SIGTERM, liveness vs. readiness probes, and keeping CPU work off the event loop. The code and the libuv thread-pool details match current Node.
Questions
- Not answered. Why do users get randomly logged out after scaling to three instances?
- Not answered. Which tool is the idiomatic way to move CPU-bound work off the event loop?
- Not answered. Which statements about
clustervs.worker_threadsare true? - Not answered. How does
clusterdistribute incoming TCP connections by default? - Not answered. Where should the shared session state live?
- Not answered. Which of these are real drawbacks of sticky sessions?
- Not answered. What should a Node process do on
SIGTERMto shut down gracefully? - Not answered. Why does
server.close()hang even with no requests in flight? - Not answered. How do failing liveness and readiness probes differ in Kubernetes?
- Not answered. What should a Pod do first when it receives
SIGTERM? - Not answered. While one
/reportrequest runs, what happens to other requests? - Not answered. How many threads does libuv's thread pool have by default?
- Not answered. Which signal asks a container to shut down gracefully?