πŸ“šSystem Design Interview - An Insider's Guide (Volume 1

This book is about how to design the system to handle one million user.

Book Store:

Chapter 1

How to Scale Application to support Million users ?

(1) Load Balancer:

  • Able to support a lot of traffic by loading traffic to other server

  • More security because we are able to hide private ip behind load balancer and use only one public ip from load balancer

(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.

Master Database

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 .

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)

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.

Last updated