# System Design Interview - An Insider's Guide (Volume 1

**Book Store:**

{% embed url="<https://www.amazon.com/System-Design-Interview-insiders-Second/dp/B08CMF2CQF/ref=sr_1_1?adgrpid=163431054676&dib=eyJ2IjoiMSJ9.CZwZ7txhICEtME2JuLCqj9Bkde4opffmKt_uE1rHfEJ3EilPewmtPesRNcCRlRAth5yOhkCbj3-ishPVYlGstYMhV-7gsXBMlFeAdtvfQr73yhkbd0qg0q5QuN0l6wCaIqC6Ht-bchUodmWQ-I3dEaTHAYU5xZ63bVyM33VGhKMtECXr5lMtFzTUJT4TN9kynitcy2F5q9ArWFNXkqrhjQuHlX9W6U8DRkMtmHHuI6c.ho7rv18J90eCQRgVjmMpHcDz-VpRse5FCFpdot5_1X4&dib_tag=se&hvadid=701919865327&hvdev=c&hvlocphy=9212230&hvnetw=g&hvqmt=e&hvrand=1746824901898651011&hvtargid=kwd-298507968466&hydadcr=18311_13683616&keywords=system+design+interview&qid=1728926102&sr=8-1>" %}

## Chapter 1

*How to Scale Application to support Million users ?*<br>

**(1) Load Balancer:**&#x20;

* Able to support a lot of traffic by loading traffic to other server
* &#x20;More security because we are able to hide private ip behind load balancer and use only one public ip from load balancer

\
\&#xNAN;**(2) Database Replication**

We will manage database to have one master database and the copies of it called slave .\
\
**Benefits:**

* Allow more queries to be process in parallel.
* Reliability: If one database is destroyed, data is still preserved.
* High availability: You can access data stored in another database server. when the main one is down.&#x20;

**Master Database** &#x20;

It is only one database that allow to do write opereration. If it goes down , slave database will be promoted to be the new master.

**Slave database**

It is database that replicated from master and allow only read operation.

**(3) Cache Tier**

Cache is temporary stoage for expensive responses or frequesntly accessed data. Access data from cache tier faster than database. This mechanism is able to reduce database workloads . <br>

**Process**

After receiving request, a web server checks if the cache has available response , it sends data back to client if not it queries the database and store the response in cache. (called **read through cache**)&#x20;

**Considerations for using cache**

* Decide when to use cache -> cause cache data is stored in volatile memory , if cache server restart all the data in memory is lost then important data should be saved in the persistent data stores.
* Expiration -> the expiration too short this will cause the system reload data from the database frequently, but if it too long then data can become stale.
* Consistency -> because the data modifying operation on the data store then it can be inconsistency.
* Eviction -> once the cache is full. the existing data might be removed we will use 2 technique 1. LRU (least-recently-used) is most popular cache evict policy 2. FIFO (first in first out)

**(4) Content Delivery network (CDN)**

It is able to cache static content like html page. The user will get the content fasther because we have CDN server closest because data cache until the end of TTL. This approach is the similar strategy as cache some behavior and issue can use the same solution.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev7days.gitbook.io/dev7days/book/system-design-interview-an-insiders-guide-volume-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
