Medium java spring

API loads one hundred thousand rows and returns them in one response?

The 30 second answer

You burn a lot of heap on entities, the persistence context, and the JSON buffer, which leads to GC pressure or out-of-memory, a slow query and transfer, timeouts, and a client that cannot render the payload. Paginate with Pageable, prefer keyset pagination for deep pages, project only the columns you need, cap the max page size, and for exports stream in a read-only transaction or write asynchronously to a file.

Large heap usage (entities + persistence context + JSON buffer) → GC pressure/OOM, slow DB query and transfer, timeouts, client can't render it. Fix: pagination (Pageable; prefer keyset/seek pagination for deep pages since OFFSET scans skipped rows), project only needed columns (DTO projections), limit max page size; for exports, stream (Stream<T> with fetch size in a read-only transaction, or async export to file).

Sources:

Sources (0)
See inline citations in the answer above.