Designing an infinite-scroll social feed

System design scenarios Senior Swift 5.9+ iOS 17+ Reviewed By Alok Singh

Pick the fix

New posts arrive at the top while the user scrolls, and offset pagination shows duplicates. Fix?

Options
Hint 1 of 1

What changes when items are added at the top?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Cursor-based pagination: request items after the last item's cursor

Correct. Insertions at the top don't shift the next page.

Why not the others?
  • B Use a larger page size. Duplicates still appear when items shift.
  • C Reload the whole feed on each page. It's expensive and loses scroll position.
  • D Remove duplicates by text. Two posts can have the same text; use ids, and fix the cause.

30-second answer

Use cursor-based pagination from the server, a local cache (database) that the UI observes so the feed opens instantly and works offline, and a repository that merges fresh pages into it. Prefetch the next page before the end, load media through an image pipeline, update likes optimistically with rollback on failure, and show new posts with a 'new posts' pill rather than shifting the list.

Practise saying it · 90 s. No recording, just a timer

Design a social feed.

Say your answer out loud, then check which of these points you covered:

  • Cursor pagination
  • Local cache as source
  • Prefetch and media
  • Optimistic updates

Deep dive

Cursors stay stable when items are inserted; offsets don't.

Diff by stable post ids for smooth updates.

Cap the cache size and evict old pages.

Track impressions and scroll performance as metrics.

Common mistakes

  • Offset pagination for a live feed.
  • Inserting new posts above the user's reading position.

Senior take & follow-ups

Seniors cover API shape, caching, UI updates and metrics, with trade-offs.

Follow-up questions

Think of your answer first, then open the hint.

  1. How do you handle a deleted post?

    Show hint

    Server tombstones or a sync that removes it by id.

  2. How do you keep scrolling smooth?

    Show hint

    Precomputed layouts, downsampled media, prefetching.

Suggest a fix if something here is wrong or out of date.