CodeX
Published in

CodeX

Top 7 Facebook System Design Interview Questions and Answers (2022)

Practice these questions before your next Facebook interview!

Facebook System Design Interview Questions

System design interviews (SDIs) have gained a lot of attention in the past few years. All software engineering interviews now include these interviews to evaluate a candidate’s ability to design and manage complex systems.

Engineers typically struggle with SDIs, partly due to their inexperience in developing large-scale systems and partly due to the unstructured nature of SDIs. Even experienced engineers find these interviews unsettling, mostly due to the open-ended nature of the design problem that does not have a standard answer.

Today we will discuss the top 7 system design questions asked in Facebook interviews.

1. Design Facebook Status Search

Facebook is one of the largest social networking services where users can share photos, news, and text-based messages. Let’s design a service that can store and search users’ status updates.

Requirements

  • Let’s assume Facebook has 1.5 billion total users with 800 million daily active users.
  • On average, Facebook gets 400 million status updates every day.
  • The average size of a status update is 300 bytes.
  • Let’s assume there will be 500M searches every day.
  • The search query will consist of multiple words combined with AND/OR.

At the high level, we need to store all the status updates in a database and also build an index that can keep track of which word appears in which status update message. This index will help us quickly find a message that the users are trying to search for.

High-level design for Twitter search

Learn more on Designing Facebook Status Update Search.

2. Design Instagram

Design a photo-sharing service like Instagram, where users can upload photos to share them with other users.

Functional Requirements

  1. Users should be able to upload/download/view photos.
  2. Users can perform searches based on photo/video titles.
  3. Users can follow other users.
  4. The system should generate and display a user’s News Feed consisting of top photos from all the people the user follows.

Non-functional Requirements

  1. Our service needs to be highly available.
  2. The acceptable latency of the system is 200ms for News Feed generation.
  3. Consistency can take a hit (in the interest of availability) if a user doesn’t see a photo for a while; it should be fine.
  4. The system should be highly reliable; any uploaded photo or video should never be lost.

High-level solution

At a high-level, we need to support two scenarios, one to upload photos and the other to view/search photos. Our service would need some object storage servers to store photos and some database servers to store metadata information about the photos.

Learn more on Designing Instagram.

3. Design Facebook Messenger or WhatsApp

Design an instant messaging service like Facebook Messenger where users can send text messages to each other through web and mobile interfaces.

Functional Requirements:

  1. Messenger should support one-on-one conversations between users.
  2. Messenger should keep track of the online/offline statuses of its users.
  3. Messenger should support the persistent storage of chat history.

Non-functional Requirements:

  1. Users should have a real-time chatting experience with minimum latency.
  2. Our system should be highly consistent; users should see the same chat history on all their devices.
  3. Messenger’s high availability is desirable; we can tolerate lower availability in the interest of consistency.

High-level solution

At a high level, we will need a chat server that will be the central piece orchestrating all the communications between users. For example, when a user wants to send a message to another user, they will connect to the chat server and send the message to the server; the server then passes that message to the other user and also stores it in the database.

The detailed workflow would look like this:

  1. User-A sends a message to User-B through the chat server.
  2. The server receives the message and sends an acknowledgment to User-A.
  3. The server stores the message in its database and sends the message to User-B.
  4. User-B receives the message and sends the acknowledgment to the server.
  5. The server notifies User-A that the message has been delivered successfully to User-B.

Request flow for sending a message

Learn more on Designing Facebook Messenger.

4. Design Facebook’s Newsfeed

Design Facebook’s Newsfeed, which would contain posts, photos, videos, and status updates from all the people and pages a user follows.

Functional requirements:

  1. Newsfeed will be generated based on the posts from the people, pages, and groups that a user follows.
  2. A user may have many friends and follow a large number of pages/groups.
  3. Feeds may contain images, videos, or just text.
  4. Our service should support appending new posts as they arrive to the newsfeed for all active users.

Non-functional requirements:

  1. Our system should be able to generate any user’s newsfeed in real-time — maximum latency seen by the end user would be 2s.
  2. A post shouldn’t take more than 5s to make it to a user’s feed assuming a new newsfeed request comes in.

High-level solution

At a high level, we will need the following components in our Newsfeed service:

  1. Web servers: To maintain a connection with the user. This connection will be used to transfer data between the user and the server.
  2. Application server: To execute the workflows of storing new posts in the database servers. We will also need some application servers to retrieve and to push the newsfeed to the end user.
  3. Metadata database and cache: To store the metadata about Users, Pages, and Groups.
  4. Posts database and cache: To store metadata about posts and their contents.
  5. Video and photo storage, and cache: Blob storage, to store all the media included in the posts.
  6. Newsfeed generation service: To gather and rank all the relevant posts for a user to generate newsfeed and store in the cache. This service will also receive live updates and will add these newer feed items to any user’s timeline.
  7. Feed notification service: To notify the user that there are newer items available for their newsfeed.

Following is the high-level architecture diagram of our system. User B and C are following User A.

Facebook Newsfeed Architecture

Learn more on Designing Facebook’s Newsfeed.

5. Design a Web Crawler

Design a Web Crawler that will systematically browse and download the World Wide Web. Web crawlers are also known as web spiders, robots, worms, walkers, and bots.

Requirements

Let’s assume we need to crawl all of the web.

Scalability: Our service needs to be scalable such that it can crawl the entire Web and can be used to fetch hundreds of millions of Web documents.

Extensibility: Our service should be designed in a modular way with the expectation that new functionality will be added to it. There could be newer document types that need to be downloaded and processed in the future.

High-level solution

A bare minimum crawler needs at least these components:

1. URL frontier: To store the list of URLs to download and also prioritize which URLs should be crawled first.
2. HTML Fetcher: To retrieve a web page from the server.
3. Extractor: To extract links from HTML documents.
4. Duplicate Eliminator: To make sure the same content is not extracted twice unintentionally.
5. Datastore: To store retrieved pages, URLs, and other metadata.

Learn more on Designing a Web Crawler.

6. Designing Yelp or Nearby Friends or Uber

Design a Yelp like service, where users can search for nearby places like restaurants, theaters, or shopping malls, etc., and can also add/view reviews of places.

Functional Requirements:

  1. Users should be able to add/delete/update Places.
  2. Given their location (longitude/latitude), users should be able to find all nearby places within a given radius.
  3. Users should be able to add feedback/review about a place. The feedback can have pictures, text, and a rating.

Non-functional Requirements:

  1. Users should have a real-time search experience with minimum latency.
  2. Our service should support a heavy search load. There will be a lot of search requests compared to adding a new place.

High-level solution

At a high level, we need to store and index each dataset described above (places, reviews, etc.). For users to query this massive database, the indexing should be read efficient, since while searching for nearby places, users expect to see the results in real-time.

Given that the location of a place doesn’t change that often, we don’t need to worry about frequent updates of the data. As a contrast, if we intend to build a service where objects do change their location frequently, e.g., people or taxis, then we might come up with a very different design.

Learn more on Designing Yelp or Nearby Friends.

7. Design Ticketmaster

Design an online ticketing system that sells movie tickets like Ticketmaster or BookMyShow

Functional Requirements:

  1. Our ticket booking service should be able to list different cities where its affiliate cinemas are located.
  2. Once the user selects the city, the service should display the movies released in that particular city.
  3. Once the user selects a movie, the service should display the cinemas running that movie and its available showtimes.
  4. The user should be able to choose a show at a particular cinema and book their tickets.
  5. The service should be able to show the user the seating arrangement of the cinema hall. The user should be able to select multiple seats according to their preference.
  6. The user should be able to distinguish available seats from booked ones.
  7. Users should be able to put a hold on the seats for five minutes before they make a payment to finalize the booking.
  8. The user should be able to wait if there is a chance that the seats might become available, e.g., when holds by other users expire.
  9. Waiting customers should be serviced in a fair, first come, first serve manner.

Non-Functional Requirements:

  1. The system would need to be highly concurrent. There will be multiple booking requests for the same seat at any particular point in time. The service should handle this gracefully and fairly.
  2. The core thing of the service is ticket booking, which means financial transactions. This means that the system should be secure and the database ACID compliant.

High-level solution

At a high-level, our web servers will manage users’ sessions, and application servers will handle all the ticket management, storing data in the databases as well as working with the cache servers to process reservations.

Learn more on Designing Ticketmaster.

Where to go from here?

➡ Practice these questions to distinguish yourself from others!

➡ Learn more about these questions in “Grokking the System Design InterviewandGrokking the Advanced System Design Interview.”

➡ Follow me on Linkedin for tips on system design and coding interviews.

Thanks for reading

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arslan Ahmad

Arslan Ahmad

Founder www.designgurus.org | Formally a software engineer @ Facebook, Microsoft, Hulu, Formulatrix | Entrepreneur, Software Engineer, Writer.