Why should Node.js services be stateless?

Stateless services do not rely on local process memory for information that must survive across requests or instances. This allows requests to be routed to any healthy instance and makes scaling, failover, rolling deployments, and replacement of instances easier. Persistent state should generally be stored in shared systems such as databases, caches, or object storage.

Key Takeaways
  • Avoid relying on instance-local persistent state.
  • Externalize shared state.
  • Statelessness improves scaling and failover.
Knowledge Check

Why is statelessness useful for horizontally scaled services?