# Scalability for Dummies - Part 2: Database

> Ref: [https://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database](https://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database)

After following Part 1 of this series, your servers can now **horizontally scale** and you can already serve thousands of concurrent requests. But somewhere down the road your application gets slower and slower and finally breaks down. The reason: your database. It’s MySQL, isn’t it?

> horizontally scale - 增加更多的机器。
>
> 接下来的问题是：数据库变成了一个瓶颈，当 requests 越来越大的时候。

Now the required changes are more radical than just adding more cloned servers and may even require some boldness. In the end, you can choose from 2 paths:

## 方案 1：雇一个 DBA，加内存。

Path #1 is to **stick with MySQL and keep the “beast” running**. Hire a database administrator (DBA,) tell him to do master-slave replication (read from slaves, write to master) and upgrade your master server by adding RAM, RAM and more RAM. In some months, your DBA will come up with words like “sharding”, “denormalization” and “SQL tuning” and will look worried about the necessary overtime during the next weeks. At that point every new action to keep your database running will be more expensive and time consuming than the previous one. You might have been better off if you had chosen Path #2 while your dataset was still small and easy to migrate.

> **master-slave replication**: 从 slave 读取数据，往 master 写数据。

## 方案 2：立马开始 denormalize 数据库。比如换成 NoSQL。

Path #2 means to **denormalize** right from the beginning and include no more Joins in any database query. You can stay with MySQL, and use it like a NoSQL database, or you can switch to a better and easier to scale **NoSQL database** like MongoDB or CouchDB. Joins will now need to be done in your application code. The sooner you do this step the less code you will have to change in the future. But even if you successfully switch to the latest and greatest NoSQL database and let your app do the dataset-joins, soon your database requests will again be slower and slower. You will need to introduce a cache.
