{"success":true,"name":"design-around-node-s-single-threaded-event-loop","description":"Building a Node.js backend and planning how it handles heavy work.","category":"ai-brimind","path":"ai-brimind/design-around-node-s-single-threaded-event-loop/SKILL.md","file":"SKILL.md","content":"---\nname: design-around-node-s-single-threaded-event-loop\ndescription: \"Building a Node.js backend and planning how it handles heavy work.\"\n---\n\n# Design Around Node's Single-Threaded Event Loop\n\n## When to use\nProject runs on Node.js, and you are designing features that involve CPU-heavy tasks (parsing, image work, crypto, big loops) or planning server architecture.\n\n## Example request\nOne big JSON parse of a 50MB file freezes every request → the event loop is single-threaded; heavy sync work blocks everyone — offload it (worker_threads, queue). A password hashing loop makes the API feel random-slow → sync CPU work starves the loop — use the async version (bcrypt async) or a worker. A report generator runs inside the request handler → long jobs don't belong in the request cycle — this is the job-queue pattern (Bull/BullMQ). An endpoint does fs.readFileSync on every call → sync I/O blocks all users, not just this one — use the async fs API.\n\n## Instructions\nAct as a Node.js architect who never forgets there is ONE event loop serving every user at once. Before designing or approving any feature, classify each piece of work: is it I/O (safe when async) or CPU-heavy (dangerous, it blocks the loop)? Trace what happens to OTHER requests while this code runs — if a single sync or CPU-heavy step can freeze them, the design is wrong. For CPU-heavy work, check the built-in mechanisms first: async library variants, worker_threads, child_process, or an existing job-queue package (BullMQ) — do not invent a custom threading scheme. For long tasks, separate 'accept the request' from 'do the work' (queue + status endpoint). If you cannot tell whether a step blocks, measure or read its docs instead of guessing. Only finalize the design once you have confirmed no request path contains blocking work, and explain how each heavy task is kept off the event loop — not just that the code 'works' on one request.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #956\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}