{"success":true,"name":"move-slow-work-out-of-the-request-answer-fast-process-in-the","description":"An API endpoint needs to do something slow like emails, files, or bulk work","category":"ai-brimind","path":"ai-brimind/move-slow-work-out-of-the-request-answer-fast-process-in-the/SKILL.md","file":"SKILL.md","content":"---\nname: move-slow-work-out-of-the-request-answer-fast-process-in-the\ndescription: \"An API endpoint needs to do something slow like emails, files, or bulk work\"\n---\n\n# Move Slow Work Out of the Request: Answer Fast, Process in the Background\n\n## When to use\nAn API endpoint needs to do something slow like emails, files, or bulk work\n\n## Example request\nSignup sends a welcome email before responding → the email provider is slow one day, and suddenly signup 'is broken'; the user only needed the account created, the email could follow. 'Generate report' builds a huge PDF inside the request → the request times out at real data sizes; the pattern is 'accept the job, return quickly, deliver the result when ready'. Import endpoint processes 10,000 rows in the request → one request holds the server for minutes; background processing with a status the user can check is the standard shape. The slow step is genuinely needed for the response itself (e.g. the login must verify the password) → then it stays in the request; only OPTIONAL-for-the-response work moves out.\n\n## Instructions\nAct as a backend engineer who treats the request-response cycle as a short, precious window — the user is literally staring at a spinner for every millisecond of it. For any endpoint you build, do this: (1) List every step the endpoint performs and mark each one: NEEDED for the response (validate input, write the core record, return the result) or NOT needed for the response (send email, notify, generate file, sync to another system). Be honest — 'the user must see it worked' usually means the core write, not the email. (2) For steps marked not-needed, decide how they run after the response: the simplest honest option for a small app is triggering the work without awaiting it WITH its own error logging, and the robust option is a real background job (a queue or scheduled worker your stack offers). Say which one you chose and why it fits the project's size — do not hand-build a half-queue when the need has a name and existing solutions. (3) A background step that fails must not fail silently: log it clearly with what failed and for whom, so a lost email is a readable line in the logs, not a mystery. (4) If the user needs the slow result itself (a report, an export), return quickly with a job status ('processing') and give them a way to get the result — a status endpoint, a notification, or a downloads page. (5) If a step is genuinely required before you can respond, leave it in — this skill is about optional work, not about making everything async for fashion. Only finish once the endpoint's response time no longer depends on the slowest optional step, and you can explain what the user experiences when that background step succeeds AND when it fails.\n\n## Metadata\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #193\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}