elixir-omg
elixir-omg copied to clipboard
API pagination based on a static page identifier
Summary
Pagination with page:
could cause the returned records to appear to be jumping around.
We need to base the pagination on a static identifier that can return consistent results.
Current behaviour
- Start with 20 transactions in the system (
txn_20 ... txn_1
) -
User A makes a request to
/transaction.all
withpage: 1
-
User A observes
txn_20 ... txn_11
returned -
User B - K create 10 new transactions (
txn_30 ... txn_21
) in a relatively short period. -
User A makes a request to
/transaction.all
withpage: 2
expecting a continuous set of data -
User A observes the same list of
txn_20 ... txn_11
on page 2
Expected behaviour
User A should be able to use pagination to accurately retrieve a continuous list of records, i.e. in this case txn_10 ... txn_1
.
The requester should be able to provide a starting_after
value to scope the results to only records after the specified value.
On the opposite end, the requester should be able to provide an ending_before
value to scope the results to only records before the specified value.
The starting_after
and ending_before
values should be a unique identifier of each record.
For example, a possible field for starting_after
and ending_before
in /transaction.all
is txhash
.
Nice catch 👍
You might want to consider a backwards paging fix as well and add ending_before
too (move from page 2 to page 1) for the same reasons you mention in the issue.
Lots of good examples of this in the wild. Might want to check this one out: https://developers.coinbase.com/api/v2#introduction and search for the Pagination section, basically they're using the same idea.
Updated the description as suggested 🎉