How do you implement efficient pagination on both the frontend and backend for a dataset containing millions of records?