0
0
HLDsystem_design~3 mins

Why Pagination patterns (cursor, offset) in HLD? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how smart pagination saves your app from slow loading and confused users!

The Scenario

Imagine you have a huge list of items, like thousands of photos or messages, and you want to show them page by page on a website.

Without a smart way to split this list, you try to load all items at once or manually pick which ones to show on each page.

The Problem

Loading everything at once is slow and crashes the app.

Manually tracking which items belong to which page is confusing and causes mistakes, like showing duplicates or missing items.

Users get frustrated waiting or seeing wrong data.

The Solution

Pagination patterns like cursor and offset help by breaking the list into small, manageable pages.

Offset uses page numbers and counts to jump to a spot, while cursor remembers a position marker to fetch the next set smoothly.

This makes loading fast, accurate, and easy to handle.

Before vs After
Before
SELECT * FROM items LIMIT 1000; -- load all items at once
After
SELECT * FROM items WHERE id > last_seen_id ORDER BY id ASC LIMIT 20; -- cursor pagination
What It Enables

It enables fast, smooth browsing through large data without overwhelming servers or users.

Real Life Example

Social media apps use cursor pagination to load new posts as you scroll, so you never wait long or see repeated content.

Key Takeaways

Manual loading of large lists is slow and error-prone.

Pagination patterns split data into easy pages.

Cursor and offset each have strengths for different needs.