From the AWS Well-Architected Framework, the Security Pillar, is the AWS Shared Responsibility Model
Rudger Gravestein
Types of API pagination:
The cursor pagination utilizes a pointer that refers to a specific database record.
API: GET /api/user/list
request: {
cursor: 12345,
page_size: 10
}
In each request, clients pass a cursor
and a page_size
SELECT * FROM users
WHERE id <= %cursor
ORDER BY id DESC
LIMIT %<limit + 1>
The server fetches (limit + 1
) records whose ID is smaller than the cursor value.
Note that the limit is equal to the given page size plus one.
LIMIT
, it implies that we are on the last page.ID
of the extra record is passed back to the client as the next_cursor
.response: {
"users": [...],
"next_cursor": "12335", # the user id of the extra result
}
Stable pagination window
Scale well with large datasets
Keyset pagination
Offset and Limit Pagination
The offset pagination leverages the OFFSET
and LIMIT
commands in SQL to paginate data.
Said we are implementing an API to get a list of user information.
API: GET /api/user/list
request: {
page_size: 10,
page_number: 3
}
In each request, clients pass a page_size
(offset) and a page_number
(limit).
SELECT COUNT(*) AS total FROM user_tab;
The server first queries the total number of records from the user table.
SELECT * FROM user_tab
ORDER BY id DESC
LIMIT 10 OFFSET 20;
The server utilises the offset and limit commands to retrieve ten records from the table.
page_number
is 3, the offset = 10 * 2 = 20.response: {
"users": [...],
"paging": {
"total_record": 295,
"page": 3,
"total_pages": 30
}
}
The server returns the paging information to the clients allowing them to keep track of the current and available pages.
Result inconsistency
Offset inefficiency — Doesn’t scale well with large dataset
Page-Based Pagination
Time-Based Pagination