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
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- A feed that never ends
- Loading the next page
- Reacting and posting
- The first screen
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
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
| Ask | Why it matters | A 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. |
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 |
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. |
Non-functional requirements
| Requirement | What 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
| Entity | What 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
| Endpoint | Notes |
|---|---|
| The first call sends no cursor. Each later call sends the |
| 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. |
| 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. |
| 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. |
| 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
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.
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?
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?
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?
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?
Concepts this guide uses
Sources
- Facebook Engineering: Rebuilding our tech stack for the new Facebook.com
- web.dev: Web Vitals
- web.dev: Virtualize large lists with react-window
- MDN: Intersection Observer API
- techinterview.org: Frontend system design, build a Twitter/X timeline
- Zeeshan Ali (dev.to): Frontend system design, Facebook news feed
- ARIA Authoring Practices Guide: Feed pattern
- TanStack Query: Optimistic updates
- Redux docs: Normalizing state shape
- MDN: Overview of scroll anchoring
- web.dev: Optimize Cumulative Layout Shift
- MDN: The img element (loading attribute)