Upgrading Code

Learn about a couple of important code upgrading tools like hot code upgrades and blue-green deployment.

Hot code upgrades

Now that we’ve deployed our code to production, eventually, we’ll need to update your production systems, whether we’re using Mix or releases. We may even have heard that the Erlang VM is capable of performing hot code upgrades. This feature provides the ability to upgrade code live in production without bringing the system down. To do so, we need to build releases first.

In practice, hot code upgrades are tricky, as they require developers to carefully maintain code and upgrade the state of all changed processes in all running applications. For example, imagine on v1.0, we have a process with a map and the keys :first_name and :last_name as a state. In v1.1, we decided to merge those keys under a new one called :name. We need to remember to implement the code_change callback and appropriately upgrade the server state. The VM cannot upgrade all processes at once, since that would imply the system needs to stop running for a while. Therefore, we need to carefully identify each group of processes we need to upgrade together or make sure processes can handle messages from both v1.0 and v1.1. This is because there will be a period where both versions run at the same ...