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
Compare Microservices Architecture with Monolithic Architecture: Trade-offs, Scalability, and Distributed Challenges.
Advanced level • 5 views
What is Idempotency in REST APIs, and how should HTTP methods and status codes be structured?
Intermediate 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 • 1 views
How does React's Virtual DOM work and what is the Reconciliation process in React 18 Fiber?
Intermediate level • 1 views
What is Cross-Origin Resource Sharing (CORS), and when does the browser trigger a Preflight OPTIONS request?
Intermediate level • 1 views