As we start working with larger and larger systems, we often find the need to build an additional redundancy into our system in order to enable high availability and protection against unexpected downtime. When working with large systems, we will split our database into a read-and-write master and a read-only slave of a set of slaves. Typically, our applications are unaware of our database architecture, which can introduce problems when required to migrate from a new master. With Yii2, we can configure our database connection to not only be aware of our master-slave database configuration, but also intelligently handle slave unavailability.
In Yii2, we can configure a single master and multiple slaves using the following database configuration. This will result in all writes going to our declared master and all reads going to one of our declared slaves:
$config = [ 'class' => 'yii\db\Connection', // configuration for the master 'dsn' =>...