The Master-Slave Database Concept For Beginners

A short explanation about one of the database concepts for microservices

Visualization of an implementation

An example of the master-slave concept using Postgresql and MongoDB
An example of the master-slave concept using Postgresql and MongoDB

Wait, what?

Why is the master-slave concept a thing? Well imagine it this way, you are trying to manage a large scale system and you end up with a server bottleneck. A few debug later you find out one of the causes is the read/write traffic to your database server. You stop and think. “What now?” one of the solutions would be to apply master-slave. Sure this might not be the first thing to come to your mind, other methods such as using a Redis cluster might be enough to sustain yourself for a few years, but this concept can be another great option.

Opinions

Costs

Compared to add more clusters to Postgres/SQL Server setup I would say the master-slave concept would be cheaper and could have similar or even better results than the former.

Implementation differences

In a way, the master-slave concept can be interpreted as a method to cache data from the master to all the slave databases, so to add a simple Redis implementation to your system can technically work as a master-slave system though this concept is not entirely about caching. The initial purpose is to help users get data from the database faster, any data. To help you visualize how I would do master-slave, see the diagram below:

In my opinion, this is how I would do master-slave
In my opinion, this is how I would do master-slave
An example of caching, this is not an implementation of master-slave
An example of caching, this is not an implementation of master-slave
An example of master-slave with caching
An example of master-slave with caching

Architecture Complexity

Imagine this, you already have enough trouble having to code and keep your business afloat and now you burden yourself and your team with an additional load to constantly manage a master-slave system.

But let’s face it, sometimes an easy way out is just not fun!

We need thrill in our lives, people! The thrill of making a master-slave system would be an experience you should not pass up if had the chance.

Conclusion

To summarize master-slave database architectures are usually used to help stabilize the system. Because reading data can be done through the slave database while inserting data needs to be done to the master database. Synchronizing data from the master to slave is called data replication, and some techniques to get realtime data can involve inserting in both master and slave database to even realtime data replication depends on your needs. To help you understand more regarding master-slave database architecture here are some good resources for you to check out:

--

--

A World-Class center for innovative ICT enabling the vigorous pursuit of outstanding BINA NUSANTARA services.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store