Consider a sequence-ordered message collection. A page query requests one extra row in descending order, while the response reverses retained rows into chronological order. The key reasoning question is which side contains the extra older row, when trimming must occur, and which retained sequence forms the next exclusive cursor. A small worked trace should also show termination without duplicates.
Backward pagination with chronological page output
Here are three skills that might be helpful.
The sequence trace confirms that overflow is defined in fetch order. For a descending limit-plus-one buffer, remove the final and therefore oldest fetched row before presentation reversal. Reverse only the retained page. When more data exists, build the next cursor from the oldest retained row and use a strict earlier-than predicate. For sequences one through eight at size three, the descending buffers are eight seven six five, then five four three two, then two one; the chronological responses are six seven eight with cursor six, three four five with cursor three, and one two without a cursor. Choosing the discarded row as an exclusive cursor skips it. Reversing before trimming is equivalent only when trimming the chronological head.
Here are three skills that might be helpful.