{"success":true,"name":"move-slow-work-out-of-the-request-into-background-jobs","description":"A user action triggers heavy work (emails, reports, processing) inline.","category":"ai-brimind","path":"ai-brimind/move-slow-work-out-of-the-request-into-background-jobs/SKILL.md","file":"SKILL.md","content":"---\nname: move-slow-work-out-of-the-request-into-background-jobs\ndescription: \"A user action triggers heavy work (emails, reports, processing) inline.\"\n---\n\n# Move Slow Work Out of the Request Into Background Jobs\n\n## When to use\nAn HTTP request handler performs slow operations (sending mail, generating files, calling slow APIs, bulk processing) before responding, making users wait or requests time out.\n\n## Example request\nSignup sends the welcome email inline → the mail server is slow; signup takes 20 seconds and sometimes times out — user waiting on non-urgent work. Report generation runs in the request → big data makes it exceed the timeout; the user gets an error though the work half-happened — long task in a short window. Bulk import processed synchronously → the browser spins for 3 minutes; a refresh kills it — no job separation.\n\n## Instructions\nAct like a developer who sorts every piece of request work into two piles: must-happen-before-responding (validate, save the core record) and can-happen-after (emails, notifications, file generation, syncs, heavy computation). For the second pile: (1) respond to the user as soon as the essential part is durable — 'import started' beats a spinner of doom — and run the rest in the background; even without infrastructure, a minimal version (a jobs table with status + a worker/interval that processes pending rows) delivers the pattern; check whether the stack already offers a job/queue mechanism before building one; (2) background jobs need lifecycle: status the user can check (pending/running/done/failed with a message), retry policy for transient failures, and a way to see and rerun failed jobs — a job that fails invisibly is worse than inline failure, which at least the user saw; (3) jobs must be idempotent (safe to rerun) because retries and crashes guarantee reruns. Only proceed once no user-facing request waits on work the user didn't need to wait for, and every background task's failure is visible somewhere someone looks.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1172\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}