I am struggling to understand how to implement database replication.
I have currently setup a master-slave replication of MySQL database.
I understand how transactional events are replicated to the slave with the binary log.
I have search everywhere for some proper information about the implementation, but everybody makes it sound like black magic!
I found this link: https://docs.oracle.com/cd/E17276_01/html/gsg_db_rep/C/repadvantage.html
It states all the good things that we all know about data replication, such as: Improved reliability, read performance, transactional commit performance etc.
However, nobody mentions how to actually achieve all of this good stuff. I cannot see how MySQL server can do all of this by itself, there must be some underlying implementation.
I am not looking for a specific implementation, I am just looking for some kind of design pattern for implementing replication properly.
My best guess is that you devide your database access into two categories, read and write. All writes goes to the master and all the reads goes to the slave.
But how do you improve the reliability if the master suddenly shutdown? Do you reroute all your trafic to the slave? And if so, is this rerouting done in a layer outside of the application? And can you write to the slave and syncronize it back to the master once it is back online?