Deterministic Pagination in SpringBoot with Pageable and Custom PK Sorting

Rigas PapazisisSpringBoot

In Spring Boot applications using Spring Data JPA, pagination via Pageable is a standard way to retrieve large datasets efficiently. However, when sorting by non-unique fields (e.g., type, status, or creationDate), it can lead to inconsistent or duplicated results across pages. This post outlines the root cause, why deterministic sorting is critical for stable paging, and our chosen approach to enforce it dynamically and flexibly.