Return two cursors per page: prevCursor from the first row's key and nextCursor from the last. For the previous page, flip the comparison to rows before the first key (CreatedAt > @c OR (CreatedAt = @c AND Id > @i) for a newest-first list), flip the ORDER BY to ascending, Take(limit + 1) to know whether an earlier page exists, then reverse the rows in memory so they display newest first. Duplicate sort values are handled by the unique tiebreaker (Id) in both the predicate and the ORDER BY; without it, rows sharing a timestamp at the page edge are skipped or repeated. The same (CreatedAt DESC, Id DESC) index serves both directions because SQL Server can scan a B-tree backwards, so each page is still one seek plus limit + 1 rows.
Checks they can reverse the predicate and order, then restore the display order
Last updated 23 Nov 2026.