Pagination: Visualisation of how it works - devrath/ComposeAlchemy GitHub Wiki
Paging with API
- If we have just
client
and API
interaction, Then we usually request page-1
from the server and the page-1
is displayed in the client.
- Next the
page-2
is requested and the page-2
is appended to the existing data.
- Basically when I keep scrolling, I keep getting new data and I keep appending the data.
- Condition here is that our device needs to be online to show the data.
Paging with DB and API
- Here it is much different, Here the database becomes the
Single-Source-Of-Truth
.
Scenario-1
:-> Database is empty
- Now we need to request new data(page-1) from the server and populate the database
- Then the data from the database is then sent back to the client*
Scenario-2
:-> Database is not empty and same data(page-1) is needed
- We just return data from the database.
Scenario-3
:-> Database is not empty, It contains only page-1 and new data(page-2) is needed
- We make a new API request, and add it to the database.
- Return the data(page-2) from the DB and populate the UI.