I am making an API over HTTP that fetches many rows from PostgreSQL with pagination. In ordinary cases, I usually implement such pagination through naive OFFET
/LIMIT
clause. However, there are some special requirements in this case:
- A lot of rows there are so that I believe users cannot reach the end (imagine Twitter timeline).
- Pages does not have to be randomly accessible but only sequentially.
- API would return a URL which contains a cursor token that directs to the page of continuous chunks.
- Cursor tokens have not to exist permanently but for some time.
- Its ordering has frequent fluctuating (like Reddit rankings), however continuous cursors should keep their consistent ordering.
How can I achieve the mission? I am ready to change my whole database schema for it!