Skip to content

How to design a news feed (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page

The problem

A feed client: someone on a phone scrolls posts from the accounts they follow, likes and comments on them, and writes posts of their own. The answer turns on keeping three things apart. A store keyed by post id holds a single copy of each post. A list draws just the posts around the visible area and reserves room for the rest. A data layer asks for pages by cursor, checks for new posts, and shows a like before the server has answered. With those apart, the hard moments (a session past 100 posts, new posts arriving mid-read, a refused like, the first screen on a slow phone) each have a place to go.

Clarifying questions

AskWhy it mattersA typical answer

Who reads this feed, and on what?

A phone on a slow connection sets the budget for the first screen and for each tap, and it decides how much of the page you can afford to keep alive.

Phones first, often on slow connections. The first posts should show within 2.5 seconds and a tap should answer within 200 milliseconds. Sessions run long: people scroll past 100 posts.

How does the server page the feed: by a cursor or by page number?

New posts land at the top while someone reads. With page numbers, each new post shifts what page two means; with a cursor, the next page starts after a post you already have.

By cursor. GET /feed?cursor&limit=10 returns ten posts, the next cursor and whether more exist. Ranking is the server's job.

How does the client find out about new posts?

It decides between asking the server on a timer and holding a connection open, which differ a lot in what you have to run and debug.

There is GET /feed/new-count?since={cursor}, which returns a count. Asking on a timer, 30 to 60 seconds apart, is the baseline; a pushed connection is a choice you can argue for.

What is in a post, and does any of it change size after it loads?

Posts of different heights decide how the list is drawn and how the reading place is kept. Images that arrive late move everything below them.

Text, one or more photos, an author, like and comment counts, and whether I liked it. Video and link previews are not asked for today.

Do likes and comments need to show before the server confirms them?

It sets which actions the client shows at once and takes back on refusal, and which wait for the server.

A tap must answer within 200 milliseconds, so the like shows at once. Whether a new post shows before the server confirms is your call to defend.

Does it have to work with no connection?

Offline reading and a queue of pending actions change the storage layer and the way you treat each action.

Not in the core. Have a sentence ready in case it comes up as a twist late in the round.

What is the accessibility bar?

A feed that loads as you scroll is hard for screen reader and keyboard users unless the markup and the loading are designed for them from the start.

Usable with a keyboard and a screen reader. That rules in labeled buttons, a way to move between posts by key, and an announcement when new posts arrive.

The requirements menu

RequirementScopeWhy

Scroll a feed of posts from followed accounts, more loading as the reader goes

Core

The product itself. The list and the paging are where this guide spends most of its attention.

Like a post and comment on it

Core

The actions that make the tap budget matter: each one changes a count the reader is looking at.

Write a post with text and photos

Core

The one write that is hard to take back, which makes it the counterexample to showing actions at once.

Learn that new posts have arrived without a manual refresh

Core

It forces the polling-or-push choice and the question of where new posts go while someone is reading.

Bring the reader back to the same place when they return to the feed

Optional

Take it if the round reaches the windowed list: it is the natural follow-up, since a pixel offset breaks once posts have different heights. Leave it until then.

Keep reading and reacting with no connection

Optional

Take it if asked. It adds storage on the device and a queue of pending actions with a way to tell a retry from a repeat. Too much to volunteer early.

Share or repost a post

Optional

Take it if there is time: it is another action to show at once, and a reposted post shows the same post in two places, which the store by id handles. Leave it if likes are not done.

Threaded replies under a comment

Optional

Leave it unless asked. It deepens the data model without changing the list, the paging or the tap budget.

Edit or delete a post

Optional

Take it if asked how a deleted post leaves the list: keeping its height with a placeholder holds the reading place. Otherwise leave it.

Video that plays as it scrolls into view

Out of scope

Autoplay, pausing off screen and bandwidth are a round of their own. Name it and set it aside.

How the server ranks posts

Out of scope

A backend question. The client gets an ordered page and a cursor.

Ads

Out of scope

Ad slots and their tracking are a separate concern; name them and move on.

Direct messages

Out of scope

Another product with its own real-time needs.

Moderation tools

Out of scope

Reporting and review queues are separate surfaces.

Non-functional requirements

RequirementWhat it forces

The first posts show within 2.5 seconds on a phone

This is the Largest Contentful Paint target, judged at the 75th percentile of page loads on phones. It rules out downloading all the code, then asking for the feed, then drawing: the first posts have to come in the HTML or be fetched while the code downloads, and the code that draws the first screen has to be split from the rest.

A tap answers within 200 milliseconds

This is the Interaction to Next Paint target. A like has to change on screen before the server replies, which means showing it at once and taking it back on refusal, with nothing heavy running on the main thread when the tap lands.

Scrolling stays at 60 frames a second with 100 or more posts loaded

Smoothness has to hold with 100 or more posts loaded, so the list keeps a small set of posts around the viewport in the page and reserves room for the others rather than letting the page grow with the session. It also rules out a scroll handler that measures positions on each scroll event: an intersection observer on a sentinel element requests the following page in its place.

Usable with a keyboard and a screen reader

Each post is an article inside a container with the feed role, action buttons carry labels, there are keys to move between posts, and a live region announces how many new posts arrived. Loading as the reader moves has to work from focus, not just from scroll position.

Core entities

EntityWhat it holds

Post

One item in the feed, held once in the store under its id.

Comment

A reply under a post, loaded when the reader opens the comments.

User

An author, kept once and referenced by id from posts and comments.

Feed state

What the client knows about the list as a whole, kept apart from the posts.

The API

EndpointNotes

GET /feed?cursor&limit=10 → { posts, next_cursor, has_more }

The first call sends no cursor. Each later call sends the next_cursor from the last answer, so the next page starts after a post the client already has, whatever landed at the top since. has_more false ends the paging.

GET /feed/new-count?since={cursor} → { count }

Asked on a timer with the cursor of the newest post on screen. The answer is just a count: the posts themselves are fetched when the reader taps the banner. The timer pauses when the tab is hidden.

POST /posts { text, media_ids } → post

Media is uploaded first and referenced by id. The returned post replaces the pending one in the store. A retry after a timeout is the risk here: our advice is to propose a client-made key on the request so the server can treat a repeat as the same post, and to say the signature would need that field.

POST /posts/{id}/like { liked } → { like_count }

Sends the wanted state, not a toggle, so a retry or a late duplicate lands on the same result. The returned count replaces the guessed one on the card.

POST /posts/{id}/comments { text } → comment

The comment shows at once as pending under the post, and the returned comment replaces it. On refusal it stays in the box with a message so the text is not lost.

The high-level design

postsServerData layerFeed listPost card

Step 1 of 5

Ask for a page and draw it

Start with the shortest path that shows posts: a data layer calls GET /feed, a feed list draws one card per post, and that's the page. It makes the data flow visible and it already fails in ways the rest of the round fixes: there is no next page, a like has nowhere to go but a round trip, and a post that appears twice would hold two counts.

HTMLfeedcountpagescounttapannouncewindowhydratesmeasuredpositionslikesendlazypendingmorefailedServerServer shellData layerPost store by idNew posts bannerLive regionFeed listPost cardHeight cacheSized imagesComposerBottom sentinelRetry row
The whole design

What breaks first

The deep dives

A feed that never ends. Someone scrolls for a long time and passes well over 100 posts, each with text, images and buttons. What does your page hold at that point, what gets slow first, and what do you change?

A concept that helps here: List virtualizationA concept that helps here: Pagination and infinite scrollA concept that helps here: Core Web Vitals

Loading the next page. While someone reads halfway down, new posts keep arriving at the top and the next ten posts are on their way. How does your client ask for the next page, and what happens to the screen when the new posts land?

A concept that helps here: Pagination and infinite scrollA concept that helps here: WebSockets, server-sent events and pollingA concept that helps here: Partial failure in the UI

Reacting and posting. Someone on a slow connection taps like on a post. What does the screen show in the first moment, what travels to the server, and what does the reader see if the server says no?

A concept that helps here: Optimistic updates and rollbackA concept that helps here: Client caching and normalized storesA concept that helps here: Debounce and request cancellation

The first screen. Someone opens the feed for the first time on a slow phone. What do they see first, what arrives when, and how do you know the first posts made it within 2.5 seconds?

A concept that helps here: Rendering strategies: client, server, staticA concept that helps here: Core Web VitalsA concept that helps here: Loading images

Concepts this guide uses

Sources

  1. Facebook Engineering: Rebuilding our tech stack for the new Facebook.com
  2. web.dev: Web Vitals
  3. web.dev: Virtualize large lists with react-window
  4. MDN: Intersection Observer API
  5. techinterview.org: Frontend system design, build a Twitter/X timeline
  6. Zeeshan Ali (dev.to): Frontend system design, Facebook news feed
  7. ARIA Authoring Practices Guide: Feed pattern
  8. TanStack Query: Optimistic updates
  9. Redux docs: Normalizing state shape
  10. MDN: Overview of scroll anchoring
  11. web.dev: Optimize Cumulative Layout Shift
  12. MDN: The img element (loading attribute)
Sign in to report a mistake