The short version

“Add an export button” is four lines of code and the smallest item on the board. Then the data grows and the feature passes through four distinct stages — synchronous, streamed, queued, pre-aggregated — each one forced by a different ceiling, and the third changes the interface rather than the backend. Two problems arrive with it that are not about size at all: the export can leak rows the screen hides, and nobody can reconcile a file that is not stamped with the moment its data was read.

Reporting is the part of a business application that is always nearly finished. The first version is a button that returns a CSV, it takes an afternoon, and it works for a year.

It works because every customer is small at first. Export cost scales with the individual account, not with your average, so the feature does not degrade gradually. It fails for one named company on one Monday morning, and the ticket says the button is broken.

Four stages, four ceilings

Every reporting feature that survives follows the same progression, and each transition is forced by a different limit rather than by a decision anyone made.

HOW AN EXPORT GROWS, AND WHAT ENDS EACH STAGE 1 · Built in the request whole file assembled, then sent ENDS AT the request timeout — met first by your largest customer 2 · Streamed, row by row nothing held in memory ENDS AT the proxy idle timeout — and a truncated file looks complete 3 · Queued job, then a link written to storage, not to you CHANGES the interface — a status, a retention rule, its own access check 4 · Pre-aggregated read from a reporting store CHANGES the question — which set of numbers is now authoritative
Only the first two transitions are engineering problems. The third is a product change, because a queued export is a thing the user has to be shown; the fourth is a data-ownership question.

Stage one builds the file inside the request. Query, format, send. It is correct and it is cheap, and it lasts exactly as long as the biggest account stays small, because the request has to stay open for the query, the formatting and the transfer combined.

Stage two writes rows to the response as they are read instead of assembling the file first. This is a real improvement and it is routinely mistaken for the fix. It removes memory as the constraint and leaves everything else: the connection is still open for the full duration, the idle timeouts in front of the application still apply in this direction too, the user still cannot navigate away, and a failure at eighty per cent produces a file that opens cleanly and is wrong.

Stage three is the one that costs more than people budget, because it is not a backend change. The request now creates a job; the job writes a file to storage; the user is told when it is ready. That means an export is suddenly an object in the product with a status, a history, a notification, a retention period and a download that has to be authorised. Half a dozen interface decisions arrive with it, which is why doing it first is cheaper than doing it second.

Stage four arrives when the query itself is the problem — when the numbers are aggregates over data too large to scan on demand, and the answer is a separate reporting store refreshed on a schedule. The engineering here is well understood. What is not is the consequence: there are now two places that can answer the same question, they disagree by one refresh interval, and somebody has to say which one is official.

The two problems that are not about size

These bite at every stage, and they are worse than slowness because they are silent.

The export sees more than the screen. The on-screen list is filtered by the viewer's scope, usually through the ordinary application path. The export is frequently a second query, written later, perhaps by someone else, reading the underlying table with a date range and little else. The outcome is a file containing rows the user cannot see in the interface, and nobody notices because nobody looks at the bottom of a forty-thousand-row spreadsheet. Once generation moves to a background job the risk increases, because the job runs with its own identity and the requester's scope has to be carried to it deliberately.

Nothing can be reconciled. The screen shows one total, the file shows another, and both are right — they were read at different instants from a table still being written to. Every export should carry, inside the file, the exact instant its data was read and the precise boundaries of the period it covers. It is one extra row of output and it ends an entire class of argument, the same way recording the moment a payment was committed ends arguments about whether it happened.

A sensible default

  1. Queue anything that could grow. If the dataset is per-customer and customers get larger, go straight to a job, a status and a link.
  2. Reuse the list query. The export should run the same filtered, scoped query as the screen it exports, with paging removed — not a new query against the table.
  3. Carry the requester's identity into the job and evaluate permissions at generation time, never the runner's.
  4. Stamp every file with the generation instant, the period boundaries and who asked for it.
  5. Set a retention period and expiring links on the day you build it. These files are production data in storage.
  6. Test with the largest tenant's volume, not a seed database. That single test tells you which stage you are actually at.

Reporting has a reputation for being the unglamorous half of a product that consumes a surprising share of the schedule. It earns that reputation honestly, mostly because the first version is so easy that nobody treats the feature as a subsystem until it already is one.

Questions we get asked

Why does an export that works for most customers fail for one?

Because export cost scales with that customer's data, not with your average. A synchronous export holds a request open for the whole of the query, the formatting and the transfer, so the largest account is the one that meets the request timeout first. Nothing is wrong with the code. The feature was sized against the median tenant and the distribution has a long tail, which is why the bug report always names one company.

Should an export be a background job from the start?

If you can see the data growing, yes, because the move is cheap to make early and disruptive later. A queued export changes the interface, not just the backend: the user gets a record with a status rather than a file, which means a list of past exports, a notification when one is ready and somewhere to put the result. Building that once is less work than building the synchronous version and then replacing it under pressure.

Is streaming the response enough?

It solves memory and nothing else. Writing rows to the response as they are read stops the server assembling the whole file first, so the process stops falling over. The request is still open for the full duration, so proxy and load-balancer idle timeouts still apply, the user still cannot navigate away, and a failure halfway through leaves a truncated file that looks complete. Streaming buys headroom; it does not change the shape of the feature.

Why do exported numbers not match the screen?

Usually because the two were produced at different moments, against a table that is still being written to. The screen was rendered at one time and the export ran seconds or minutes later, so a few rows moved. The fix is to make the reporting period explicit and closed, and to stamp every export with the exact instant the data was read, printed in the file itself. A report nobody can date is a report nobody can reconcile.

Does an export need its own permission check?

Yes, and this is the most common serious bug in reporting features. The on-screen list is usually filtered by the viewer's scope, while the export path is often a separate query written later that reads the underlying table directly. The result is a file containing rows the user cannot see in the interface. Any export that runs as a background job must also record who requested it and evaluate their scope at generation time, not the job runner's.

What should be kept and for how long?

Generated files are a copy of production data sitting in storage with a shareable link, so they need a retention period, an expiring link and an access check on download rather than a long unguessable URL. Decide the retention when you build the feature. Otherwise you accumulate years of files containing customer records that no policy covers and no one remembers, which is exactly the finding an audit is looking for.

Related service Web development Web applications that hold up under load

If your reporting is at stage one and your largest customer is growing, that is a known piece of work rather than a surprise. It is a normal part of how we build web applications, because the retrofit always lands in the worst week.