Data & Integrity

Reporting & Data Exports

Intermediate

Reports and exports are how data leaves the safety of the app, into spreadsheets, downloads, dashboards, and other systems. That makes them a quiet source of two problems: leaking more personal data than intended, and hurting performance by pulling huge datasets. Export with care: the right data, to the right person, sized to handle real volumes.

An export is a deliberate copy of data into a less-controlled place, so it needs the same care as any data handling: who is allowed it, what is included, and where it ends up. Reports also tend to aggregate across many rows, which is exactly where unbounded queries and N+1 patterns cause outages. And in a multi-tenant business, a report that forgets its tenant filter is a cross-tenant breach in a downloadable file.

This connects Data Modelling and Persistence (efficient queries), Multi-Tenancy (scoping), Data Classification and Masking (what is safe to include), and Privacy (lawful basis, minimisation).

Export the right data, safely

Make reports scale

Unbounded, unscoped export var all = db.Query("SELECT * FROM Customers"); // no tenant, no paging
return Csv(all); // full PII, every tenant, in one download

A cross-tenant breach and a memory or timeout failure in one: every customer of every tenant, all columns including PII, loaded at once into a file anyone with the endpoint can pull.

Scoped, minimal, streamed // background job, streamed, tenant-scoped, columns limited, access-checked
await foreach (var row in db.StreamReport(tenantId, fields, paged))
writer.Write(Mask(row));
// delivered as a signed-URL file; the download is audited

Only the requester's tenant and the needed (masked) fields are included. It streams, so volume is safe, and the download is access-controlled and audited.

Self-review checklist

Why it matters: Exports are where data escapes our controls into spreadsheets and downloads, which makes them a prime route for breaches. A forgotten tenant filter or an over-broad field list becomes a sensitive file in the wild. And the large queries behind reports are a classic cause of outages. Scoped, minimal, efficient, audited reporting protects both the data and the system.