Front End System Design Interview - User Interface Components
Find the latest version of this page on GreatFrontEnd's Front End System Design Questions.
Examples
- Autocomplete (Free)
- Image carousel (Paid)
- Dropdown menu (Paid)
- Modal dialog (Paid)
- Rich text editor (Paid)
- Poll widget (Paid)
- Tooltip
To find out more, check out GreatFrontEnd, which shows you how to approach front end system design interviews with their Front End System Design Playbook and case studies. There are also blog posts that will cover some of the following topics in more detail.
Framework
In system design interviews, candidates are supposed to lead the conversation. Here's a framework you can use to give an outline to the interviewer as to what you are going to cover (not necessarily in that order). The framework is called RADIO and it is made up of the first character of each aspect.
- Requirements exploration: Understand the problem thoroughly and determine the scope by asking a number of clarifying questions.
- Architecture / High-level design: Identify the key components of the product and how they are related to each other.
- Data model: Describe the various data entities, the fields they contain and which component(s) they belong to.
- Interface definition (API): Define the interface (API) between components in the product, functionality of each API, their parameters and responses.
- Optimizations and deep dive: Discuss about possible optimization opportunities and specific areas of interest when building the product.
You can write this structure down on the whiteboard/online editor so that you don't forget.
Requirements exploration
Every system design interview (even for non-front end as well) should start with requirements gathering/clarifying requirements about the question, which is usually left underspecified on purpose. You are recommended to spend at least a few minutes clarifying the requirements. Do not start drawing the architecture before you are clear about the requirements!
Thankfully, components have well-defined scope and not try to do too many things. You likely have used such a component yourself and possibly know what you need from such a component.
Some considerations:
- What devices should the system support? Desktop web, mobile web, etc
- What's the primary device that users will access the system on?
- Which browsers should we support?
- Do we need to support internationalization?
- How much styling customization do we want to allow?
Architecture / High-level design
Architecture for front end interviews are typically focused on the client-side architecture, and not on large scale distributed systems where databases, load balancers and servers are involved.
For components, list down the various subcomponents that will exist within it and what data is being passed among each component.
Let's take an image carousel example. Subcomponents within an image carousel would be:
- Main image: An image that displays the photo in focus
- Thumbnail: Smaller images below the (Will there be thumbnails? You will only know if you clarified requirements earlier)
- Image store: A client side cache of the list of photos to display
If you have a whiteboard/online drawing tool, it would also be helpful to draw diagrams to illustrate the entities and their relationships. Which subcomponent communicates with which when a user interaction occurs.
Data model
Data model for components will refer to the component state. The concept of state should be familiar to most front end developers who have used front end UI libraries/frameworks such as React, Angular, Vue, Svelte, etc. In every of these libraries/frameworks, state is a common concept.
Deciding what data to put in state is essential to doing well for this portion. Few factors to consider when deciding what goes into component state:
- State is allowed to change over time during the lifecycle of the component, typically as a result of user interactions.
- Each component should maintain its own independent state which allows multiple instances of the component to coexist on a single page. The state of a component instance should not affect the state of another instance.
- Components are easier to reason about (read/understand) the fewer the fields there are in the state. We should strive to reduce the amount of state needed. If a component uses a value which can be derived from another piece of state, then that value should most likely not be part of the state. For example if your component is rendering a list of items and you want to display a message when there are no items to render, there shouldn't be an additional
isEmpty
state because it can be derived from the length of theitems
. - If a component has multiple subcomponents, it'll be best if it's possible to consolidate the state within the top level and the rest of the components are pure and stateless.
Interface definition (API)
The key idea behind components is for them to be reused and abstract complexities. Good components are designed in a way that they can be reused in multiple scenarios, and users do not have to know how they work internally before using them. In the case of components, API refers to configuration options that the component developer would expose to other developers for specification.
- What are the configuration options you would allow for the component? (
props
in React). What would be reasonable defaults? - Follow the Open-closed principle - the component should be open for extension but closed for modification.
- If your component is meant to be part of a UI library that doesn't bother about the appearance and leaves the styling to the user, extra care has to go into the design of the props and to allow users to customize the look and feel of the components. There are a few ways to go about this in React:
- Composition - Props which accept React components which also promotes code reuse.
- Render props are function props that a component uses to know what to render. It also helps in reusing behavior without bothering about the appearance.
className
orstyle
props - Allows users to inject class names and/or styling attributes to inner DOM elements. This could have negative consequences but is still a common way of allowing user to customize component appearance.
- Possible configuration options:
- Lifecycle/event hooks -
onClick
,onChange
,onBlur
,onFocus
, etc.
- Lifecycle/event hooks -