{"success":true,"name":"decide-sync-vs-async-don-t-make-clients-wait-for-slow-work","description":"An endpoint triggers work that takes seconds or minutes","category":"ai-brimind","path":"ai-brimind/decide-sync-vs-async-don-t-make-clients-wait-for-slow-work/SKILL.md","file":"SKILL.md","content":"---\nname: decide-sync-vs-async-don-t-make-clients-wait-for-slow-work\ndescription: \"An endpoint triggers work that takes seconds or minutes\"\n---\n\n# Decide Sync vs Async: Don't Make Clients Wait for Slow Work\n\n## When to use\nYou are designing an endpoint whose job (report, export, media processing, bulk import) can take longer than a normal request should live.\n\n## Example request\nVideo upload processed inside the request → times out at 30s and the user retries, doubling the load; the job belonged in a queue. — Report generation blocks the request for 2 minutes → server workers all busy waiting; 202 + job id + status endpoint is the standard pattern. — Client polls a status endpoint every 200ms → self-inflicted load; polling intervals or a completion webhook are part of the design. — Job finishes but nobody stored the result location → the client got 202 and then nothing; the async flow needs a defined 'where do I get my result'.\n\n## Instructions\nAct as a flow designer who never traps slow work inside a request-response cycle. When the work might be slow: 1) Estimate the honest duration at real data sizes — if it can exceed a few seconds, design it async by default. 2) Use the standard shape: respond 202 with a job id immediately, run the work via the project's existing queue/background-job mechanism (check before adding a new one), and expose a status endpoint or completion webhook. 3) Define the full lifecycle up front: pending, running, done-with-result-location, failed-with-reason — and how long results are kept. 4) Set the client's expectations in the contract: how to check progress, how often to poll (or that a webhook will call them), and what a failure looks like. 5) If you're unsure of the duration, measure with production-sized input — dev-sized data lies. Only ship once the async lifecycle is confirmed end-to-end (submit, check, fetch result, see failure), and explain how the design frees the request cycle rather than just raising the timeout.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #902\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}