SproutStackSproutStack home
BeginnerAPI gateway & load balancing

Report exports fail with 504 at the gateway

The gateway times out at 30 seconds; big exports take up to two minutes.

The setup today

A reporting endpoint builds a CSV export synchronously and returns it in the response. Requests go through an API gateway and a load balancer to the reporting service.

Current configuration

gateway: upstream timeout 30 s
load balancer: idle timeout 60 s
GET /reports/export?range=... -> builds the CSV, then responds

What you know

  • Small exports take 5 seconds; large ones take up to 2 minutes and keep growing.
  • Users with large exports get a 504 and often click again, starting a second export.

The new requirement

Large exports must work reliably, and repeated clicks must not start duplicate work.

Make the call

2 questions · first-try answers earn the most XP

1. What is the most robust change?
2. How do you stop repeated clicks from starting duplicate exports?
What a strong answer also covers
  • Store finished exports in object storage and hand out a short-lived signed URL, so downloads bypass the API.
  • Set the gateway timeout per route: short for normal APIs, and keep long work off the request path.
  • Show progress and estimated time; users click again when nothing seems to happen.
  • Run exports against a replica or warehouse so they do not slow the main database.
Variations to think through

Change one fact and decide again. There is no single right answer here.

  • Some exports take 30 minutes. What does the user experience look like now?
  • Exports contain personal data. How long should the files live, and who can download them?
  • A partner calls the API from a script. How does polling work for them?

The background

More drills