#

# Choose Wisely

At the most basic level, pagination just means retrieving a (potentially big) collection of items in small sequential chunks (pages)... but there's more than one way to crack an egg.

Choose the right one to ensure the best performance and workflow.

# OFFSET Pagination

The most common pagination technique is counting the collection items (COUNT DB query), using the count to calculate where the specific pages start (i.e., OFFSET) and retrieving only the LIMIT items for that page (OFFSET+LIMIT DB query).

It is straightforward to understand and set up and very versatile for the UI, but you have to be aware of a few shortcomings.

# KEYSET Pagination

The KEYSET pagination technique allows the fastest and lighter DB performance. It does not count the (ordered) collection (which makes it faster), nor calculates any numeric page pointers in advance (which avoids the data-shift during browsing). It just uses the values in the last record of the page to retrieve the next one.

# TIME RANGE Pagination

This hybrid technique filters by a specific time period (Year, Month, Day, etc.) and applies the offset paginator within that period.

# Search platforms

Pagy supports Elasticsearch, Meilisearch, and Searchkick.

These paginators get the count, limit and results provided by the search platform. Pagy acts as an interface to these underlying gems, using the :offset paginator (whithout the shortcomings).