System Design · Middle · Question 2 of 75

Why is cursor pagination better than offset pagination for a feed?

Explanation

With offset, new posts shift the window and the user sees repeats; OFFSET 100000 is expensive for the DB. A cursor ("after the record with id X") is stable and efficient on an index. The downside is you can't jump to page 57, so for tables with page numbers offset is sometimes more appropriate.

Further reading

Problem with a question

System Design · Middle · question 2

Test yourself

Take the System Design · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz