{"success":true,"name":"keep-the-backend-stateless-server-memory-is-not-a-storage-pl","description":"Backend code is about to keep user data or sessions in server memory","category":"ai-brimind","path":"ai-brimind/keep-the-backend-stateless-server-memory-is-not-a-storage-pl/SKILL.md","file":"SKILL.md","content":"---\nname: keep-the-backend-stateless-server-memory-is-not-a-storage-pl\ndescription: \"Backend code is about to keep user data or sessions in server memory\"\n---\n\n# Keep the Backend Stateless: Server Memory Is Not a Storage Place\n\n## When to use\nProject has a backend, and you are about to store sessions, counters, uploaded files, queues, or any user data in a variable or the server's local disk as its only home.\n\n## Example request\nkeeping logged-in sessions in a JS object → the process restarts (deploy, crash, PM2 reload) and every user is logged out; sessions belong in the database or a store like Redis. saving uploads to the server's local folder only → the disk fills or the server is replaced and files vanish; files belong in dedicated storage the app points to. counting rate-limits in a memory map → run two instances and each has its own count, the limit stops working; shared state needs a shared store. building an in-memory job queue → a restart silently drops pending jobs; a persisted queue survives restarts, memory does not.\n\n## Instructions\nAct like an engineer who assumes the backend process can die at any second — because with deploys, crashes, and restarts, it does. Before storing anything in a variable, in-memory map, or the server's local disk, ask: if the process restarts right now, is losing this acceptable? A pure cache you can rebuild — fine. Sessions, user files, counters, queues, anything a user would miss — not fine: it must live in durable shared storage (the database, a store like Redis, file/object storage) and memory may only hold a copy. Check what durable stores the project already has and reuse them before adding a new one. Also ask: if a second instance of this backend runs tomorrow, does this logic still work, or does each instance have its own private truth? If you are unsure whether some state must survive restarts, ask instead of assuming. Only proceed once every piece of state has a home that outlives the process, and explain why a restart or a second instance now costs the users nothing.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #522\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}