StackDevLife
🐛Bug of the DayIntermediateBackend / Database / APIs

Pagination Worked… Until Data Changed

~1 min read
🐛TL;DR

Pagination broke in production because page numbers were used instead of stable identifiers.

The Bug

Users reported: Missing records Duplicate items across pages Random jumps in pagination Everything worked fine in testing.

Root Cause

Pagination was implemented using: page + limit But data was changing: new records inserted old records deleted So page 2 today ≠ page 2 after data update.

The Fix

Fix:
Use cursor-based pagination instead of page numbers.

Example:

  • lastId
  • createdAt timestamp

Query:
“Give me next 10 records after this ID”

This keeps pagination stable even when data changes.

Lesson:
Offset pagination works only for static data.
For real systems → always prefer cursor-based pagination.
PaginationBackendDatabaseProduction-bugPerformance
🐛

Get a new Bug of the Day in your inbox

Subscribe to Stack Dev Life — free, no spam, unsubscribe anytime.

Subscribe free →