Ch1 - Scale from zero to millions of users
DB
Non-relational DB might be right if:
- Your application requires super-low latency
- Your data are unstrctured, or you do not have any relationship data.
- You only need to serialize and desrialize data(JSON, XML, YAML, etc.)
- You need to store a massive amount of data.
Scaling
Vertical Scaling: Add power to your server(RAM, CPU, etc.)
Horizontal Scaling: Add number of servers in pool.
Vertical Scaling better fit low traffic case.
Advantages:
- Simplicity.
Disadvantages:
- Vertical has limit, no unlimited CPU power...
- Vertical does not have failover and redundancy.
Horizontal scaling better for large scale app. If rootcuase is traffic increasing cause custoemr experience slower use load balancer better.
Load balancer
For better security, private IPs are used for communication between servers. A private IP is an IP address reachable only between servers in same network.
With load balancer and second server we now can cover failover case.
DB replication
A manager DB generally only supports write operations. A worker DB gets copies of data from manager and only support read operations.
Most app requires a much higher ratio of read to writes; thus, the number of worker DB in system is usually larger than number of manager DB.
Advantages for DB replication:
- Better performance: Allow more queries to be processed in parallel.
- Reliability: natural disaster such as typhoon.
- High availabiity: if one database is offlice you can access by others.
What if one DB is offline?
- If only one worker DB offline, read operations will be directed to manager DB temporarily. If other woker still online, read operation redirect to good ones and new DB replace stale one.
- If manager DB offline, a worker will be promoted. One new worker DB will be created. In prod system, promoting is complicated as data might be not up to date. Missing data need to be updated with recovery script. Although some other replicaiton method might help but way more complicated.
** Not finished**
评论
发表评论