← All topics/Networking & data

Practical interview questions

Scenario-style prompts with sample answer outlines. Focus is on how you would design and reason in real codebases.

Question 4

Pagination and large feeds

You’re building a feed that loads large amounts of data. How do you handle pagination and ensure smooth performance?

Answer outline

Pagination should serve both efficient data loading and smooth UI performance. The approach is to load data in pages and request the next page before the user reaches the end.

The preferred pattern for feeds is cursor or token-based pagination. Instead of asking “give me items 21–40,” the client says “give me the next 20 items after this position.” The server returns a token, an opaque string the client doesn’t need to interpret and the client sends it back on the next request.

This is more robust than offset-based paging for feeds because feeds change constantly. A cursor or token says “continue from here” rather than “start at item 20,” so new insertions don’t shift what the client receives.

On the UI side, request the next page before the user reaches the end to avoid visible loading gaps. Keep cell configuration light, load and decode images off the main thread, and update only changed rows to maintain smooth scrolling.

Principles

  • Prefer cursor or token-based pagination for feeds. It stays stable when items are inserted or deleted, unlike offset.
  • Prefetch the next page before the user reaches the end to avoid loading gaps.
  • Prevent overlapping requests with explicit pagination state (idle, loading, exhausted).
  • Keep cell configuration light — decode and cache images asynchronously, update only changed rows.
  • Watch memory as the feed grows; consider releasing off-screen data or capping the in-memory page count.