Pagination
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 9 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    How many rows does OFFSET read to serve page 5,000?

      Elasticsearch with 5 shards. How many hits merge to serve page 500?

        How much memory do frozen feed snapshots take?

          Build-up · 5 steps

          Watch offset drift and the cursor hold

          A newest-first list, 4 per page. Two items are posted between page 1 and page 2. Watch the offset slide and the cursor hold.

          Step 1 of 5

          Page 1, offset 0

          A newest-first list, 4 per page. Page 1 is “skip 0, take 4”, items 20 to 17. The client remembers only a count.

          4 interview moments

          You’re the candidate

          The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

          1. Deep dive 1 of 4

            Interviewer

            “Your cursor holds only created_at. A flash sale creates dozens of orders in one millisecond. How should page 2 seek?”

            Your move. Pick an approach:

          2. Deep dive 2 of 4

            Interviewer

            “Your orders list now supports several sort orders and filters. What do you put in next_cursor?”

            Your move. Pick an approach:

          3. Deep dive 3 of 4

            Interviewer

            “Your home feed is ranked per viewer, by time and fresh engagement. How do you serve page 2?”

            Your move. Pick an approach:

          4. Deep dive 4 of 4

            Interviewer

            “The PM wants page numbers and a total on an orders list with 40 million matching rows. What do you build?”

            Your move. Pick an approach:

          Build-up · 5 steps

          The life of an opaque cursor

          What a production cursor carries, how it is protected, and what the server checks before it touches the database.

          Step 1 of 5

          Pack the position

          The last row’s sort key and ID, plus the direction. A hash of the filters and sort binds it to this query; a version lets you change the format later, and an expiry ends its life.