Data on the frontend
After today, you can design for every state a screen’s data passes through, and tell when showing one more field is really a backend question.
Dip your toes 1 min
An app spends much of its time waiting for data from servers, and every wait is a moment someone sees. When you open Instagram on a weak signal, the feed shows posts it saved earlier, then swaps in newer ones as they arrive. Each request for data passes through a few states, loading, success, empty, or failed, and each one needs a designed screen. Some actions, like tapping the heart, change the screen at once and quietly undo it if the server says no. Behind “Liked by alex and 1,204 others,” the servers check which people you follow liked that post, for every post you scroll past.
The full lesson 10 min
Why this exists
Open Instagram on a train with a weak signal. The feed appears at once, showing posts you saw this morning. A moment later, newer posts slide in at the top. You tap the heart on a photo and it turns red, even though the signal has dropped. You scroll and more posts keep appearing, as if the feed never ends.
None of that is the server being fast. It’s the app managing data: deciding when to ask, what to show while it waits, and what to do if the answer never comes. Day 10 covered the API, the backend’s side of the contract. Today is the other side, where the app makes requests and lives with the results.
A design file usually shows one moment, with the data loaded and every field filled in. The app lives through many moments. It waits, it gets partial answers, it loses the connection, and it shows data that’s a little old. Each of those moments is a screen someone sees, whether or not anyone designed it.
What it is
Data fetching is the work an app does to ask a server for data, and to handle the wait, the answer, and any failure. Every request goes through the same few states. It starts in loading, with the request sent and no answer yet. Then it lands in one of three places. It succeeds, it succeeds with nothing in it, or it fails.
Each state is a screen. Loading might be a spinner, or a skeleton, a gray outline of the layout that fills in as data arrives. Empty is what a new account sees before following anyone, and it’s a chance to explain what belongs there. Error needs a message and a way to try again.
A request can also land in a mix of states. The feed loads, but one post’s image fails, so that tile needs its own small error.
Time is part of the design too. A request that hasn’t answered after half a second feels normal. After five seconds, the same spinner starts to feel broken.
Many apps change what they show as the wait grows: first nothing, then a skeleton, then a note that the connection is slow. At some point the app gives up and calls it an error, a limit engineers call a timeout. Someone picks that number, and you can ask what it is.
Asking for the same data every time a screen opens would be slow and wasteful. So apps keep a saved copy of recent answers, called a cache. Day 19 covers caching in depth; for now, a cache is a copy kept close at hand so the app doesn’t have to ask again. The question is what to do when the saved copy might be out of date.
The most common answer is stale-while-revalidate. The app shows its saved copy at once, even though it may be stale. At the same time, it asks the server for a fresh copy in the background. When the fresh copy arrives, the app swaps it in. The name comes from a web caching standard, and popular data libraries for React, like SWR and TanStack Query, are built around the idea.
The trade is a few moments of old data in exchange for a screen that never starts blank. For a feed, that’s an easy trade. Nobody minds seeing this morning’s posts for a second. For a delivery’s arrival time or the number of items left in stock, the same trade can mislead someone. Deciding which data can be shown stale, and for how long, is a call designers and engineers should make together.
Where the first request happens matters as well. Day 11’s server rendering means a page can fetch its data on the server before any HTML leaves. That first view arrives with its data already filled in, with no loading state at all. Later requests, like the next page of a feed or a like, still come from the device. So a single screen can have some data that never shows a spinner and some that always does.
How it shows up in your work
Some interactions have to feel instant, whatever the connection. When you tap the heart on Instagram, the app can’t wait for the server before turning it red. On a slow connection that could take seconds, and the tap would feel broken. So the app makes an optimistic update. It changes the screen as if the action already worked, sends the request in the background, and undoes the change if the server says no.
Optimistic updates suit actions that almost always succeed and are cheap to undo. A like, a bookmark, or reordering a list are good fits. A payment, a booking, or deleting an account aren’t, because showing success that later reverses can do real harm.
When you design an action, decide which kind it is. For the optimistic kind, design what happens when it fails: a quiet reversal, a short message, or a retry. For the other kind, design an honest wait.
Messaging apps show a middle ground. A sent message appears in the thread at once, with a small mark that it’s still sending, and the mark changes when the server confirms.
Long lists bring their own data problem. Instagram can’t send your whole feed at once; it would take too long and use too much data. So it uses pagination, loading the list in smaller pieces called pages. Infinite scroll is pagination with the page turns hidden. As you near the end of what’s loaded, the app quietly asks for the next page.
Pagination shapes features you might take for granted. A total count, like “1,204 results,” can be expensive, because the backend has to count everything to produce it. In many systems, jumping straight to page 40 is harder than scrolling to it. And an infinite feed needs a designed ending.
In 2018, Instagram added a “You’re All Caught Up” message for when someone has seen every new post from the past two days. That was a product answer to a pagination question: what should the end of the list say?
Stale data shows up in bug reports, too. Someone changes their profile photo, and the old one keeps appearing in one corner of the app. Usually nothing is broken. One screen is showing a saved copy that hasn’t been refreshed yet.
The useful question in that thread is which copy each screen reads, and when it fetches a new one. The answer often leads to a small design change, like refreshing that one screen after an edit.
The one thing people get wrong
In a design review, someone points at a new line on a screen and calls it a small frontend change. The data is in the system somewhere, so the screen should be able to show it. Day 6 asked whether data is stored; the third case is stored but costly to compute. The hard part is the question someone has to answer to produce it, for every person, every time the screen loads.
Take the line under an Instagram post: “Liked by alex and 1,204 others.” It looks like one field. In a simplified version of what the backend does, it comes from three places.
There’s the list of everyone who liked the post, the list of everyone you follow, and the profiles that hold names. To pick “alex,” the backend has to find which of the people you follow liked this post. For a famous account, the likes list can run to millions.
Now multiply that by every post in the feed and every person scrolling. A question that’s cheap once becomes expensive at that scale. Backend teams handle it by computing answers ahead of time, saving them, or settling for an approximate answer. The count might lag by a few likes, or the name chosen might not be the friend you’d expect. Those compromises show up on screen, so designers need to know which ones the team made.
Social proof is a common place this shows up. When a design adds “3 friends are going” or “Popular with people like you,” ask two things. Where does the answer come from, and how often is it computed? If it already exists in an API response, it’s frontend work. If someone has to combine large lists to produce it, it’s a backend project, and the right design might change once you know the cost.
Showing a little less, or showing it a little late, is often the better product. A rounded count, like 1.2M instead of an exact number, is partly a style choice. It’s also a way of not promising a precision the backend can’t cheaply keep.
Ask an engineer this
“Which piece of data on this screen is the most expensive for the backend to produce, and what makes it expensive?”
Ask during a design review, with the screen in front of you both. The engineer can usually point to the costly field and name the sources behind it, like a count, a ranking, or anything personalized. Words like precomputed, cached, or approximate matter here. They mean the team already pays a cost to show it, and your design should respect the compromise. If the answer is that everything is cheap, ask which part of the screen would slow down first if traffic doubled.
Terms from today
- Data fetching
- The work an app does to ask a server for the data a screen needs, and to handle the wait, the answer, and any failure.
- Stale-while-revalidate
- A pattern where an app shows its saved copy of data at once, fetches a fresh copy in the background, and swaps it in when it arrives.
- Optimistic update
- Changing the screen as if an action succeeded before the server confirms it, and undoing the change if the server says it failed.
- Pagination
- Loading a long list in smaller pieces, called pages, and fetching the next piece only when someone is about to need it.