PM2 Cluster Mode and stateful session persistence
0 reputation · 09 Oct 2023, 11:22 UTC
PM2 Cluster Mode leverages the Node.js cluster module to distribute incoming network connections across multiple worker processes using a round-robin strategy. This architecture is designed to optimize CPU utilization by spawning instances across available logical cores.
When deploying stateful applications, there is a known constraint regarding local memory. Because each worker process operates in its own isolated memory space, session data stored in local variables or in-memory caches is not shared across the cluster instances.
For applications requiring consistent state across requests, it is necessary to determine the most efficient integration point for an external store.
- What is the recommended architectural pattern for implementing a shared session store like Redis within a PM2 cluster environment?
- How does the round-robin load balancer affect session affinity compared to sticky session implementations?