elixir-omg icon indicating copy to clipboard operation
elixir-omg copied to clipboard

API pagination based on a static page identifier

Open unnawut opened this issue 4 years ago • 2 comments

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

  1. Start with 20 transactions in the system (txn_20 ... txn_1)
  2. User A makes a request to /transaction.all with page: 1
  3. User A observes txn_20 ... txn_11 returned
  4. User B - K create 10 new transactions (txn_30 ... txn_21) in a relatively short period.
  5. User A makes a request to /transaction.all with page: 2 expecting a continuous set of data
  6. 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.

unnawut avatar Dec 06 '19 03:12 unnawut

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.

jrhite avatar Feb 11 '20 12:02 jrhite

Updated the description as suggested 🎉

unnawut avatar Feb 11 '20 14:02 unnawut