title: How to achieve Server side pagination with unpredictable results
body: <p>I have bunch of tools stored in one table and each tools associated transactions stored in its child table. I have an algorithm that determines what tool to buy based on its performance in the transaction table entries.  My output of the algorithm may recommend to buy a tool and may not based on its performance.  </p>
  
  <p>My end goal is only to show the list of tools page by page ( with server side pagination ) which are recommended to buy by the algorithm. My question here is,  if I fetch first 10 tools and its transactions and give as input to the algorithm, my algorithm may or may not recommend  all the tools to buy, in such a case,  the tools which are eligible to display are not enough for the current page.  I have to again go back to the data base and fetch few more until my results are enough to display the current page ( which includes too many db iterations ).   </p>
  
  <p>I am currently fetching everything and caching the results collection at the serverside ( with Ehcache) and applying the server side pagination over my collection.   But this is pushing the server to go out of memory if too many concurrent users hit this page.</p>
  
  <p>What is the best solution for this kind of issue..!!?</p>