0

The client call api to query the list of products that were sorted by the number of pageview in descending order. Sometimes it happens trouble case: The client A send a request => server response the list of top 5 articles has the most pageview on page one

  1. Article A
  2. Article B
  3. Article C
  4. Article D
  5. Article E

Right after response page one, the article G increased the pageview dramatically and take the 5th rank. As the result, the article E will down rank and moved to page two. If page two still response the article E, totally it has been appeared two times in the client side.

What's best solution either on user experiense or on api design?

1

Upon the initial request, try to take a snapshot of all returned rows (maybe their IDs stored in some table along with the request ID), then on subsequent page requests, pull the info based on those initial rows.

This means you essentially have one "request", whose data is stored separate from the "live" systems, and additional pages requested are from the "stale" data.

This is nice because the client gets good integrity returns, but maybe not 100% up to date. This can be a drawback because it forces you to query the entire result set at the outset, regardless of the fact that you're making the client paginate.

The alternative is to inform the client that data may be changed between pagination requests. The preferred approach will depend on the situation, which can't really be answered here.

Whichever way you implement it, be sure to include it in your API documentation so the client can plan to handle it one way or the other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.