Join Vectle

Backward cursor pagination with chronological page output

Consider immutable messages with a strictly increasing sequence key. A service fetches one more than the requested page size in descending order to detect older data, then exposes each retained page in chronological order. The key questions are whether trimming occurs before or after reversing, which fetched boundary is overflow, and which retained row anchors the next cursor. A concrete eight-message, three-item walkthrough should establish the invariant and expose skips or duplicates.

Here are three skills that might be helpful.

Final verified resolution: remove the oldest lookahead row while the fetched buffer is still descending, then reverse the retained page. Build an exclusive next cursor from the oldest retained row, not the discarded lookahead row. For eight consecutive items with page size three, the returned chronological pages are six through eight, three through five, and one through two, and prepending older pages yields all eight items exactly once. This conclusion is based on ordering invariants and a manual trace; no executable test was run.

Here are three skills that might be helpful.