In this post, I'll show how to simulate a multi-master synchronization with and is a using so the database file is not locked during writes (this helps performances). Conflicts are reported and managed at application level.
thanks to based on the Apache CouchDB )
What's a multi-master synchronization
Quoting
It's worth note, in this schema, that the synchronization is bidirectional:
- Alpha and Beta synchronize data bidirectionally
- Alpha and Gamma synchronize data bidirectionally
- Beta and Gamma don't need to be synchronized because they're already synchronized with Alpha, in this way I save network bandwidth.
- Nothing prevents to implement data replication between Beta and Gamma, but in my case I prefer to save network bandwidth (so it's a precise architectural choice).
POC
Following I'll show all steps to simulate a multi-master synchronization. After tested the data replication, I'll consider an off-line scenario putting a database off-line.
Multi-master synchronization: Running all instances of CouchDB
To implement the scenario described above, I'll use published on ):
[chttpd]
port = 5984
bind_address = 0.0.0.0
Finally, I've mapped on the host file system (in the folder ./db/[alpha|beta|gamma]/) each database.
Now we can start the databases:
am@animus:~$docker-compose up -d
Multi-master synchronization: Creating databases to be synchronized
Using for Alpha installation
for Gamma installation
For each installation, Select Databases from side menu and then Create Database, type the name of the database (in my case mydb) and click on create button like shown below:
In this page we can create the replications.
Wait few seconds and the document you've just created is sent to other databases (here we go!).
Multi-master synchronization: Creating documents off-line
I turn off database Alpha and Gamma running the following commands:
am@animus:~$docker kill couchdb_couchserveralfa_1 && docker kill couchdb_couchserverbeta_1
On database gamma I create the document while the other databases are off-line.
After the creation of the new document I turn on the other databases running:
am@animus:~$docker-compose up -d
Wait few seconds and the document you've just created on Gamma database is sent while the other databases were off-line. So we've just proved that the synchonization works when they return on-line (here we go!).
Conclusions
In this article, I've shown how to simulate the multi-master synchronization of CouchDB and how to simulate an off-line scenario where I show that data keep on to be available for local operations and then be synchronized when the database returns on-line.
In these scenarios, CouchDB turned out a good solution.
Suggestions and corrections are welcome.
SOCIAL SHARE CARD GENERATOR