SoloMedium5m

The Offset Pagination Trap

Datadog — slow query on /api/feed

SRE Team: OFFSET 100000 query takes 4.2s. DB CPU at 90%. One user scrolling to page 5000 is timing out the cluster.

The trap: OFFSET is O(N) — Postgres reads and discards every skipped row. Fine on page 1 in dev; catastrophic at depth.

Your task

Refactor `get_feed_page()` in `feed_api.py`: replace page_number + OFFSET with cursor-based pagination — WHERE id < cursor for index seeks.

Book: LIMIT + OFFSET pagination · Prod: keyset/cursor pagination for infinite scroll.

Skills you'll prove

pythonsqlpaginationperformancedatabasebook-vs-prod

Browse freely — sign in when you're ready to open a ticket and prove your skills.