# Requirements of Quora's Design

### Requirements <a href="#requirements-0" id="requirements-0"></a>

Let’s understand the functional and non-functional requirements below:

#### Functional requirements <a href="#functional-requirements-1" id="functional-requirements-1"></a>

A user should be able to perform the following functionalities:

* **Questions and answers**: Users can ask questions and give answers. Questions and answers can include images and videos.
* **Upvote/downvote and comment**: It is possible for users to upvote, downvote, and comment on answers.
* **Search**: Users should have a search feature to find questions already asked on the platform by other users.
* **Recommendation system**: A user can view their feed, which includes topics they’re interested in. The feed can also include questions that need answers or answers that interest the reader. The system should facilitate user discovery with a recommender system.
* **Ranking answers**: We enhance user experience by ranking answers according to their usefulness. The most helpful answer will be ranked highest and listed at the top.

#### Non-functional requirements <a href="#non-functional-requirements-2" id="non-functional-requirements-2"></a>

* **Scalability**: The system should scale well as the number of features and users grow with time. It means that the performance and usability should not be impacted by an increasing number of users.
* **Consistency**: The design should ensure that different users’ views of the same content should be consistent. In particular, critical content like questions and answers should be the same for any collection of viewers. However, it is not necessary that all users of Quora see a newly posted question, answer, or comment right away.
* **Availability**: The system should have high availability. This applies to cases where servers receive a large number of concurrent requests.
* **Performance**: The system should provide a smooth experience to the user without a noticeable delay.

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2FZ0z2aHccWN88Zs8p8WYz%2FScreenshot%202023-09-03%20at%205.06.15%20AM.png?alt=media&#x26;token=eebdf366-37c0-4d39-9a69-0220818d3b55" alt=""><figcaption></figcaption></figure>

### Resource estimation <a href="#resource-estimation-0" id="resource-estimation-0"></a>

In this section, we’ll make an estimate about the resource requirements for Quora service. We’ll make assumptions to get a practical and tractable estimate. We’ll estimate the number of servers, the storage, and the bandwidth required to facilitate a large number of users.

**Assumptions**: It is important to base our estimation on some underlying assumptions. We, therefore, assume the following:

* There are a total of 1 billion users, out of which 300 million are daily active users.
* Assume 15% of questions have an image, and 5% of questions have a video embedded in them. A question cannot have both at the same time.
* We’ll assume an image is estimated to be 250 KBs, and a video is considered 5 MBs.

#### Number of servers estimation <a href="#number-of-servers-estimation-1" id="number-of-servers-estimation-1"></a>

Let’s estimate our requests per second (RPS) for our design. If there are an average of 300 million daily active users and each user can generate 20 requests per day, then the total number of requests in a day will be:

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2F6nlcQYD0cZDR5GURJ9b0%2FScreenshot%202023-09-03%20at%205.06.49%20AM.png?alt=media&#x26;token=c561ac3b-4d41-4a36-8b82-69ae4648d5b8" alt=""><figcaption></figcaption></figure>

**Estimating RPS**

| Daily active users        | 300    | million |
| ------------------------- | ------ | ------- |
| Requests per day per user | 20     |         |
| Requests Per Second (RPS) | f69444 |         |

We already established in the [back-of-the-envelope calculations](https://ylbbak99.gitbook.io/grokking-modern-system-design-interview/back-of-the-envelope-calculations/put-back-of-the-envelope-numbers-in-perspective) chapter that we’ll use the following formula to estimate a pragmatic number of servers:

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2FIpiMwkyV450AM4MvdCTO%2FScreenshot%202023-09-03%20at%205.07.37%20AM.png?alt=media&#x26;token=2af1e55d-1305-4987-a063-21a6a9c29899" alt=""><figcaption></figcaption></figure>

> Therefore, the total number of servers required to facilitate 300 million users generating an average of 69,500 requests per second will be 37,500.

#### Storage estimation <a href="#storage-estimation-0" id="storage-estimation-0"></a>

Let’s keep in mind our assumption that 15% of questions have images and 5% have videos. So, we’ll make the following assumptions to estimate the storage requirements for our design:

* Each of the 300 million active users posts 1 question in a day, and each question has 2 responses on average, 10 upvotes, and 5 comments in total.
* The collective storage required for the textual content (including the question, answer(s), and comment(s) text) of one question equals 100 ��100 KB.

**Storage Requirements Estimation Calculator**

| Questions per user                   | 1      | per day  |
| ------------------------------------ | ------ | -------- |
| Total questions per day              | f300   | millions |
| Size of textual content per question | 100    | KB       |
| Image size                           | 250    | KB       |
| Video size                           | 5      | MB       |
| Questions containing images          | 15     | percent  |
| Questions containing videos          | 5      | percent  |
| Storage for textual content          | f30    | TB       |
| Storage for image content            | f11.25 | TB       |
| Storage for video content            | f75    | TB       |

See Detailed Calculations

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2FDbYNAWxCdSd9GAgMAZc9%2FScreenshot%202023-09-03%20at%205.09.28%20AM.png?alt=media&#x26;token=3659964b-5c8a-4235-a331-a8d0bde03fd7" alt=""><figcaption></figcaption></figure>

#### Bandwidth estimation <a href="#bandwidth-estimation-0" id="bandwidth-estimation-0"></a>

The bandwidth estimate requires the calculation of incoming and outgoing data through the network.

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2FAysIimTzYVwrwDAeSZMu%2FScreenshot%202023-09-03%20at%205.10.16%20AM.png?alt=media&#x26;token=bf9655f7-05c8-4cd1-b9d5-e33da198215f" alt=""><figcaption></figcaption></figure>

**Bandwidth Requirements Estimation Calculator**

| Total storage required per day      | 116.25  | TB         |
| ----------------------------------- | ------- | ---------- |
| Incoming traffic bandwidth          | f11     | Gbps       |
| Questions viewed per user           | 20      | per day    |
| Total questions viewed              | f69444  | per second |
| Bandwidth for text of all questions | f55.56  | Gbps       |
| Bandwidth for 15% of image content  | f20.83  | Gbps       |
| Bandwidth for 5% of video content   | f138.89 | Gbps       |
| Outgoing traffic bandwidth          | f215.3  | Gbps       |

Detailed Calculations

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2FTnX5Z6rbHaAKoyab5g9v%2FScreenshot%202023-09-03%20at%205.11.13%20AM.png?alt=media&#x26;token=664743f7-a2a3-405c-b6d8-b46d1130955a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1055613405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MlQzjDKRh_AaQvZflWz%2Fuploads%2F7KtP4SR4pJY2qo0YcpfK%2FScreenshot%202023-09-03%20at%205.11.57%20AM.png?alt=media&#x26;token=00e082c8-8916-4f6a-99cb-a0ca74db3ad1" alt=""><figcaption></figcaption></figure>

* [**Load balancers**](https://ylbbak99.gitbook.io/grokking-modern-system-design-interview/load-balancers/introduction-to-load-balancers) will be used to divide the traffic load among the service hosts.
* [**Databases**](https://ylbbak99.gitbook.io/grokking-modern-system-design-interview/databases/introduction-to-databases) are essential for storing all sorts of data, such as user questions and answers, comments, and likes and dislikes. Also, user data will be stored in the databases. We may use different types of databases to store different data.
* [**A distributed caching system**](https://ylbbak99.gitbook.io/grokking-modern-system-design-interview/distributed-cache/system-design-the-distributed-cache) will be used to store frequently accessed data. We can also use caching to store our view counters for different questions.
* [**The blob store**](https://ylbbak99.gitbook.io/grokking-modern-system-design-interview/blob-store/system-design-a-blob-store) will keep images and video files.
