Introduction

No-SQL Databases like MongoDB use asynchronous, statement-based replication because it’s platform independent and allows more flexibility within a replica set.

Why Replication?

Replication is extremely important because you can never assume that all your servers will always be available. It has become the core of distributed systems over the course of time.

Single Node failure

How does Replication work?

In a replicated system, there are a couple extra nodes (read: database server) on hand, and they hold copies of our data.

Database Replication

Different forms of Data replication

Data replication can take one of two forms, i.e. binary replication and statement-based replication.

Binary Replication

Suppose application is inserting a document into database system, and after process completes it has a few bytes on disk that were written to contain some new data.

Pros:

· Replicating data is smooth on the secondary nodes since they get really specific instructions on what bytes to change and what to change them to.

Cons:

· Assumption is made that OS will be consistent across replica set. However, if one set is on Windows and other is on Linux, the same binary logs cannot function.

Statement Based Replication

After a write operation is completed on the primary node, the write statement itself is stored in a specific Log and the secondary nodes sync their logs with the primary node’s log and replay any new statements on their own data.

Pros:

· This approach works regardless of the operating system or instruction set of the nodes in the replica set.

Cons:

· Process of replication is slow in comparison with Binary replication.

Full Stack developer, avid photographer and cyclist, Fitness trainer. contact: reeshabh.choudhary@gmail.com