Skip to content
GitShowcase Forum

Vercel function times out on a long report export, should I move it to a queue or a different host?

Asked by Ilse K. · Hosting, Edge and Deploys2 repliesupdated

Short answer

One of my small SaaS apps lets customers export a full year of activity as a CSV. The export endpoint is a Next.js route handler on Vercel that queries Postgres, builds the file in memory and returns it. For small accounts it is instant. For a couple of bigger customers it gets cut off and they see a 504 in the browser. Runtime logs show:

Written by Ilse K. ·
CiteGitShowcase Forum, "Vercel function times out on a long report export, should I move it to a queue or a different host?", https://gitshowcase.com/forum/discuss/vercel-function-times-out-on-a-long-report-export-should-i-move/, accessed 2026-11-30.
  1. Member ·
    Task timed out after 300.00 seconds
    

    I looked at raising maxDuration but I do not love the idea of a request that sits open for many minutes, and a user closing the tab would waste the work anyway.

    Options I am weighing:

    1. Raise the duration limit and keep the code as is.
    2. Return immediately, do the work in the background, and email a download link.
    3. Move this one endpoint to a long running server somewhere else (a small VM or container).

    I am cost conscious and the exports are rare, so I do not want to run a server all month for them. What would you do, and what is the simplest queue setup if that is the answer?

    0
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. Anand R.Member ·

    Option 2. A request that holds a connection for minutes will fail for reasons that have nothing to do with your platform: mobile networks, proxies, browser tabs. Return a job id right away, do the work separately, let the client poll or send an email.

  2. Teodor M.Member ·

    You do not need a queue product to start. A jobs table in the Postgres you already have, plus a worker that does SELECT ... FOR UPDATE SKIP LOCKED LIMIT 1, covers a handful of exports a day. Add a real queue when you outgrow that.

GitShowcase Forum. Questions and answers on shipping developer projects: dev tools, APIs, infrastructure and portfolios.