{"success":true,"name":"design-node-js-servers-as-stateless-so-they-can-scale-and-re","description":"Storing sessions, caches, or uploads inside a Node.js server process.","category":"ai-brimind","path":"ai-brimind/design-node-js-servers-as-stateless-so-they-can-scale-and-re/SKILL.md","file":"SKILL.md","content":"---\nname: design-node-js-servers-as-stateless-so-they-can-scale-and-re\ndescription: \"Storing sessions, caches, or uploads inside a Node.js server process.\"\n---\n\n# Design Node.js Servers as Stateless So They Can Scale and Restart\n\n## When to use\nProject is a Node.js server, and you are about to keep user data in a variable, in-memory session, or local disk file between requests.\n\n## Example request\nSessions in an in-memory object → every restart logs everyone out, and a second instance can't see them — session stores (Redis) own this. Uploads saved to local disk → gone on redeploy, invisible to other instances — object storage (S3-style) is the owner. A global cache Map growing forever → that's a slow memory leak and it's per-instance — external cache or bounded LRU. Counting things in a module variable → two instances give two different counts — shared state belongs in the database.\n\n## Instructions\nAct as a Node.js architect who assumes the process can die or be duplicated at any second. Before storing anything in process memory or on local disk between requests, classify it: is it truly disposable (per-request temp), or would losing it or splitting it across two instances cause a bug? For anything that must survive or be shared, name the correct external owner: database for records, Redis or a session store for sessions, object storage for files, an external or bounded cache for hot data. In-process state is acceptable only when it is a pure performance cache with a size bound and a correct miss path. Test the design mentally against two questions: 'what breaks on restart?' and 'what breaks with two instances behind a load balancer?' If either answer is 'user-visible data is wrong or lost', the state is in the wrong place. Only approve the design once every piece of state has a confirmed owner that survives restarts and scaling, and explain why.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #986\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}