Stage 1: Problem
Problem
You are building an analytics dashboard backend. Your data lives in a third-party API that returns results page by page ā 100 records per request, with a cursor token for the next page. Some reports need all records; others need only the first few hundred.
Your current code fetches all pages upfront into a giant array, then processes. For a customer with 50,000 events, that means 500 API calls before any processing starts, and the entire dataset sits in memory.
Your challenge: How would you let calling code loop through records one at a time (or in chunks) without loading everything upfront, and without exposing pagination details to every consumer?
Write your approach before continuing.