patternModeratepending
Serverless function exceeds timeout — async processing patterns
Viewed 0 times
function timeoutasync processingStep FunctionsSQSfan-outpollingjob queue
ci-cdterminal
Problem
Serverless function times out processing a request. The operation takes longer than the maximum timeout (AWS Lambda: 15 min, Vercel: 10-300s, CloudFlare Workers: 30s). Users see timeout errors.
Solution
(1) Offload to async: accept the request, queue the work, return immediately with a job ID. (2) Use a message queue (SQS, EventBridge) to trigger a separate long-running function. (3) Step Functions / Durable Functions: orchestrate multi-step workflows that survive beyond single function limits. (4) For file processing: use streaming — process chunks instead of loading everything into memory. (5) Fan-out: split work across multiple concurrent function invocations. (6) Move long-running tasks to containers (ECS, Cloud Run) with longer timeouts. (7) For API responses: implement polling endpoint (GET /jobs/{id}) or WebSocket notification.
Why
Serverless functions are designed for short-lived, stateless operations. They have hard timeout limits because the platform needs to reclaim resources. Long operations must be decomposed into shorter steps.
Revisions (0)
No revisions yet.