How would you add pagination to an API whose records change frequently?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Use a stable sort with a unique tie-breaker, such as created_at followed by id. Offset pagination is simple but can skip or repeat records as earlier rows change and can become expensive at large offsets. Cursor pagination encodes the last sort position and queries after it. Bind cursors to relevant filters and validate them. If a fully consistent snapshot is required, define how that snapshot is maintained. Explain whether new records appear on refresh and retu only metadata the client actually needs.
Related Questions in Full Stack Web Development
What is Idempotency in REST APIs, and how should HTTP methods and status codes be structured?
Intermediate level • 9 views
Compare Microservices Architecture with Monolithic Architecture: Trade-offs, Scalability, and Distributed Challenges.
Advanced level • 8 views
How should client-side and server-side form validation work together?
Easy level • 6 views
What responsibilities belong to the browser, application server, and database?
Easy level • 5 views
What is the difference between synchronous and asynchronous code in Node.js, and how does the Event Loop manage them?
Intermediate level • 4 views