Skip to the page

Classic case studies · senior

Case study: news feed

A strong news feed design uses a normalised store with an ordered id list, cursor pagination loaded by an IntersectionObserver sentinel, virtualisation for long sessions, a 'new posts' pill instead of jumping content, optimistic likes with rollback, safe rich text, and the feed accessibility pattern.

The notes

What you must know

  • Requirements and rendering: confirm post types (text, image, video), infinite scroll, like/comment/share, create post, live updates, and NFRs (fast first load on low-end phones, smooth scrolling, a11y, i18n); server-render or stream the first page for LCP (CSR is fine behind login) and load the composer and video player code on demand.
  • Store: posts and users by id, feed = { ids, nextCursor }; merge pages with dedupe by id; share entities with the post detail page.
  • API: GET /feed?cursor=&limit=20 → { items, nextCursor }; cursor, not offset, because new posts at the top shift offsets; POST /posts with an idempotency key; POST /posts/:id/like.
  • Loading more: an IntersectionObserver sentinel with a rootMargin so the next page loads before the end; guard with isLoading and hasMore; an error row with Retry; an end message.
  • Long sessions: virtualise variable-height items (measure and cache heights) after a few hundred posts; restore scroll on Back by saving the first visible post id and its offset.
  • New posts: show an 'N new posts' pill and insert on tap; never push content down while the user reads. Get counts by SSE/WS or polling.
  • Media and text: width/height from the API to reserve space (no CLS), srcset, lazy images, muted video only while in view with one active player; render @mentions and #tags from structured tokens, never raw HTML.
  • Accessibility (APG feed) and measurement: role=feed, each post role=article with aria-labelledby, aria-busy while adding posts, aria-posinset/aria-setsize (-1 when unknown), Page Up/Down between posts; measure INP on like, scroll jank (long animation frames), image error rate and feed load time.

The red pen

Common traps: mistake → fix

  • Mistake: Offset pagination

    Fix: duplicates and skipped posts when new items arrive.

  • Mistake: Keep all 2,000 posts in the DOM

    Fix: memory and scroll jank on phones.

  • Mistake: Insert new posts at the top automatically

    Fix: the post being read jumps away.

  • Mistake: Render the post body with innerHTML

    Fix: stored XSS.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design the frontend of a news feed. Start with requirements.
  2. Offset or cursor pagination, and why?
  3. How do you keep scrolling smooth after 1,000 posts?
  4. The user likes a post, then the request fails. What happens?
  5. How do new posts appear while the user is reading?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview