One database can only hold so much data.
As the app scales, the database slows down because it runs out of resources.
You can buy more computing resources, but there's a limit.
Sharding bypasses this limit by splitting a database into smaller parts called shards.
The shards live on different computers, called nodes. Together, they act like one database.

How data gets split
Let's say we have a Customers table.

To split the data, you use a shard key, which is usually a column.
For example, let's use Country as the shard key.
With that key, you can group the rows:

Each of these smaller rows goes to a shard and is put into different servers
When you ask for data, the database uses the shard key to find which shard (server) has it.

To shard or not to shard
Sharding allows you to scale almost infinitely because physical resources are no longer a constraint.
But it can be a nightmare to maintain when your data is spread to many different places.
Usually, you will only consider sharding when vertical scaling, meaning getting more CPU and RAM, is impossible.
- Fee from Anime Coders
