Design Infinite Scrolling
viaLeetCode
Requirements: Design an infinite scrolling feed (e.g. a restaurant/feed list) that loads more content as the user scrolls, covering the edge cases encountered while building it.
Design points:
- Use an IntersectionObserver (or scroll-position threshold) to detect when the user nears the bottom and trigger the next page fetch.
- Paginate via cursor-based pagination (not offset) to avoid skipped/duplicated items when underlying data changes.
- Edge cases: duplicate requests from rapid scrolling (debounce/in-flight guard), handling the end of the list (no more data), maintaining scroll position on back-navigation, memory growth from unbounded DOM nodes (virtualization/windowing), race conditions between concurrent page fetches, and loading/error states per page.
asked …