title: Implementation of lazy loading for lists with DB, client and backend
body: <p>I have a more general question about how to implement lazy loading in my projects for lists, grids, etc.. My question is not about an specific framework or language, because I develop different project types with C#, java, android, winforms, etc. </p>
  
  <p>My question is, how to implement this lazy loading pattern in a RESTful envirorment?</p>
  
  <p><strong>For example</strong>, I have a database with about 2 mio datasets. The user select some filters on client side and the server response about 100.000 records. Thats to much to show them all, all over that the time to "load and render" the items in the list control takes several minutes (on bad days). The better way is to show the user the first 200 items, and load the next blocks as needed.</p>
  
  <p><strong>Another example</strong> is search for images on a mobile device. If the search result are about 10.000, the mobile traffic for image loading will be exploding. So it's better to show up to 20 entries and if the user scrolls to bottom for example, the next 20 are loaded.</p>
  
  <p>So, how can I archive that on backend / db / client side? Unfortunatly I can't query "select 200 to 400 from table where ...". </p>
  
  <p>On some extern API's I could send a "page token" to get the next block of items. But how do I know which "page" the user ask for? </p>
  
  <p>A bad way I've tried is to load with every request the whole collection (the 100.000 records in first example), and serve only the part which is needed. But this is very ressource wasty when the quantity of clients expands and 10.000 clients do this every minute serveral times. </p>