0%
Frontend System Design Interviews: Components, Rendering, State, Caching and Performance
Walkthrough: Design a Chat Client
This lesson works through one prompt from the first minute to the last: design the client for a chat application, in the style of a web messenger or a team chat tool. You will apply the six step framework from the first lesson in order, requirements, architecture, data model and state, interface, deep dives and wrap up, and spend most of the depth on the parts that make chat hard on the client: a live connection that drops, messages that must appear in the right order, sends that feel instant but can fail, unread counts that must agree across screens, drafts that survive going offline and a message list that can grow to tens of thousands of rows.
Chat is a favourite prompt because it touches almost every building block in the course at once. The networking lesson covered WebSockets, server sent events, reconnection and offline queues in general terms, and the performance lesson covered virtualization and main thread budgets. This walkthrough does not re-teach those mechanisms. It shows how to combine them into one coherent design and how to talk about the combination under interview time pressure.
Opening the interview and settling the boundary
The interviewer says: design a chat client for the web. Your first move is the boundary question. Should the server be treated as given, with an API you can define, or do they also want the delivery backend? For a frontend round the usual answer is that the backend exists, it can push events over a WebSocket and it exposes REST endpoints for history. You may propose the shape of those endpoints and events, because the client depends on them, but you will not design message storage or fan out across server nodes.
Next, pin down the product. Is this one to one messaging, group chat or both? Is it a consumer messenger or a workplace tool with channels and threads? Do users run it in several tabs at once? Is there a mobile web audience on weak networks? Each answer changes the design. A workplace tool with hundreds of channels needs efficient unread tracking across all of them. A consumer messenger with heavy mobile use needs aggressive attention to reconnection and battery.
Assume the interviewer answers like this: one to one and group conversations, groups up to a few hundred members, desktop and mobile browsers, users often keep two or three tabs open, text messages plus image attachments, and threads and voice calls are out of scope.
Functional requirements
Write the functional requirements as a short list and read it back.
- See a list of conversations sorted by most recent activity, each with a preview of the last message and an unread count.
- Open a conversation and see its recent history, with older messages loading as the user scrolls up.
- Receive new messages in real time, in the open conversation and as updates to the list.
- Send text messages that appear instantly and show their delivery state: sending, sent, delivered and read.
- Retry or discard messages that failed to send.
- Keep a draft per conversation, so switching conversations or closing the tab does not lose typed text.
- Show typing indicators and basic presence, as a lower priority.
- Attach images, with a preview while uploading, also lower priority.
Ranking matters. Say out loud that items one to five are the core and that typing, presence and attachments will get a sentence each unless time allows more. That protects the deep dives.
Non functional requirements
The non functional list is where a frontend answer starts to differ from a backend one. Messages should appear within a few hundred milliseconds of being sent by the other party when both are online. Sending should feel instant: the user's own message must be on screen within one frame of pressing enter, not after a round trip. The client must survive flaky networks without losing a message or showing one twice. Ordering must be consistent: two users looking at the same conversation should see the same order once everything has arrived. The app should stay responsive with long histories, which means scrolling at sixty frames per second through thousands of messages on a mid range phone. It must be accessible: new messages announced to screen reader users without flooding them, full keyboard use and visible focus. And because messages contain user generated text, rendering must be safe against script injection, which the security lesson covered.
Search engine visibility does not matter; chat sits behind a login. That frees you to render on the client after a fast shell, so rendering strategy is not a deep dive here.
Numbers that shape the client
A few rough numbers make later decisions concrete. A heavy user might belong to two hundred conversations, with thirty active on a given day. A busy group might produce a few messages per second at peak. A long conversation might hold fifty thousand messages, of which the user will scroll through a few hundred in a session. A history page of fifty messages at about half a kilobyte each is around twenty five kilobytes, cheap to fetch and to keep in memory. Keeping every message of every conversation in memory is not reasonable, so the client keeps recent windows and evicts the rest.
These numbers justify three design choices before you draw anything: a single multiplexed socket rather than one per conversation, paginated history rather than full download, and a virtualized list rather than one DOM node per message.
The wireframe
Sketch the main screen. On wide screens there are three regions: a conversation list on the left, a message pane in the centre and a composer pinned to the bottom of the pane. On narrow screens the list and the pane become two routes, and the back button returns to the list. A small header in the pane shows the conversation name, member count and presence.
Point at each region and say what it needs. The list needs the last message preview, timestamp, unread count and a sort by recent activity. The pane needs history, live messages, delivery state per own message, a jump to latest button when the user has scrolled up, and a new messages divider at the first unread message. The composer needs the draft, send on enter, a newline on shift and enter, and a disabled or queued state when offline.
What is out of scope, stated explicitly
Close the requirements step by listing what you will not design: the server's storage and fan out, push notifications when the tab is closed beyond a mention, end to end encryption, voice and video, threads and message search. Saying this takes fifteen seconds and prevents the interviewer from wondering whether you forgot them. It also leaves you room to bring one of them back as an extension in the wrap up.
What the interviewer is checking in step one
The interviewer is watching for three things in these first minutes. First, whether you ask about the product before you design it. A candidate who starts drawing a WebSocket diagram before knowing whether groups exist, or whether users keep several tabs open, will have to redo work later, and the interviewer knows it. Second, whether your requirements are specific enough to be tested. Messages should appear quickly is not testable; the user's own message is on screen within one frame and other people's within a few hundred milliseconds is. The second form gives you a yardstick to point at during the deep dives. Third, whether you notice the requirements that are unusual for chat compared with a feed or a search box. Chat is bidirectional, it is stateful over a long session, and it promises users that nothing they type will be lost. Those three properties, more than any feature, decide the shape of the client.
A short way to show all three is to end step one with a sentence such as: the hard parts here are keeping one reliable live connection, never losing or duplicating a message across reconnects, and rendering long histories smoothly, so those are where I expect to spend the deep dives. That sentence sets the agenda for the rest of the interview, and it tells the interviewer that you are driving rather than waiting for questions. If they would rather you focus on something else, such as attachments or accessibility, this is the moment they will say so, and you have lost nothing by asking.
Mark sending, receiving, ordering, delivery state and history as core, and typing, presence and attachments as secondary. When time runs short you can then compress the secondary items to a sentence each without the interviewer thinking you missed them.
That was the last lesson. What next?
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my course