Master/Slave architecture
In software architecture, Master/Slave defines a type of architecture in which we have one master node and several slave nodes, with the master exerting total control over the slave nodes. Also, the direction of communication in this architecture is always from Master to Slave (However, this may not apply in failure conditions).
The master node could control the following factors (this list is just a sample):
- Communication protocol
- Tasks assigned
- Directions on when to act upon some task
Challenges:
- Being Fault tolerant:
Let us imagine a scenario in which; the master node fails (refer above diagram). It would have a catastrophic impact on the system, since all the slaves are dependent on the master node for directions.
In such a scenario, we can have an arrangement wherein, when the master node fails, one of the slaves would take over as master without impacting the system. For example, in the above diagram, when the master node crashes, Node 3 is elevated as Master node.
How is the slave node chosen?
- Through configuration. i.e., preconfigure a slave node to act as master
- Through voting. i.e., initiate a voting process amongst the slave nodes to choose the master candidate.
To effectively implement the above fail over strategy, the slave node should be aware of the state of the master before it went down. i.e., it should periodically synchronize the master’s state with itself. The time period of synchronization would depend on the use case and the criticality of the system being built.
Reference Implementations:
Databases like MySQL could be configured in a Master- Slave setup. The master node could be read-write node whereas the slave nodes could provide read only operations.