Database Scaling through Sharding and Partitioning

aditya goel
4 min readNov 27, 2022

Question #1.) What is a Database ?

Question #2.) What’s the normal way of database serving the application needs ?

Question #3.) What would happen, if load on DB increases ?

Answer →

  • We can perform Vertical-Scaling of the DB-Server i.e. increasing the CPU cores, power, RAM and HDD.
  • We can also setup the replica-DB for master database.

Question #4.) Once Load on DB Server increases beyond a certain limit, what do we do ?

Answer → We now perform Sharding. One possible way of doing the sharding is to divide the data based upon region. For e.g.

  • Data for ASIA region would live on DB-Server-1.
  • Data for AMERICA region would live on DB-Server-2.

Question #5.) What is a Shard ?

Question #6.) Explain what is a Shard and what is a Partition ?

Question #7.) Explain the difference between the Sharding and Partitioning ?

Question #8.) How data can be sharded on production ?

Answer → One possible option of sharding the data is based upon the Regions. For example :-

  • For data belonging to Asia region, we can house all the data at Shard-A.
  • For data belonging to Europe region, we can house all the data at Shard-B.
  • For data belonging to America region, we can house this data at Shard-C.
  • For data belonging to Africa region, we can house this data at Shard-D.
  • For data belonging to Atlantic region, we can house this data at Shard-E.

Question #9.) Show some other example for Sharding the data at production ?

Answer → We can also shard the data based upon userName’s first character :-

  • Data from Aaron to Frances, can live on Shard-A i.e. Database Cluster-A.
  • Data from Frances to Nancy, can live on Shard-B i.e. Database Cluster-B.
  • Data from Nancy to Zed, can live on Shard-C i.e. Database Cluster-C.

Question #10.) What are Advantages & DisAdvantages of Sharding ?

Question #11.) Explain concept of Vertical Sharding ?

Question #12.) Vertical Sharding is related to Micro-Services architecture ?

Question #13.) How to communicate to Application-Servers about the exact owner of the particular table ?

Answer → We use Zookeeper for the same.

Question #14.) How to move one tables from one MySql to another ?

Step #1.)

Step #2.)

Step #3.)

Step #4.)

Step #5.) Once the changes are made to the ZooKeeper, they are reactively sent to the API-Servers, which then starts connecting to the DB2 for table T2.

That’s all in this blog. We will see you in next series. If you liked reading this blog, do clap on this blog.

--

--

aditya goel

Software Engineer for Big Data distributed systems