Spring Boot: Handling a REST Endpoint That Queries More Data Than Memory Available

If you are a developer and have not faced this issue yet, it is still worth reading, as at some point in your career, you will likely need to create a Spring Boot REST endpoint that performs a database query with results that do not fit into memory.

Generated by bing.com/images/create.

In this article, let’s delve into an example of a REST endpoint that cannot be implemented in the traditional way due to memory consumption.

Scenario

In this exercise, let’s use a simple scenario involving Customer, Order, OrderItem, and Product:

Our goal is to create an endpoint that will generate a report. This endpoint will query and return:

  • One million Orders.
  • More than 5 million OrderItems.

Traditional Implementation

Let’s define a DTO with some fields:

@Data
public class ReportDto {
private final Long orderId;
private final LocalDate date;
private final String customerName;
. . .
private final List<Item> items;

@Data
public static class Item {…

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Rolar para cima