💧 Elixir Intermediate

How does hot code upgrading work in Elixir/Erlang?

Answer

Hot code upgrading allows updating a running BEAM system without stopping it — an Erlang/Elixir unique capability. The BEAM can load new module versions while old code continues running: two versions exist simultaneously during the transition. Releases: Elixir uses mix release to build deployable packages. Hot upgrades use appups and relups (release upgrade scripts) that describe how to transform state from the old to new version. Process code switching: running GenServers automatically switch to the new module version on their next function call. code_change callback: GenServers implement code_change to transform their state when upgraded. Practical use: while hot upgrades are powerful (Erlang telecom systems use them for zero-downtime upgrades), most Phoenix/Elixir applications use rolling deployments with fast restart instead — it is simpler and sufficient for most applications. True hot upgrades are used in embedded systems (Nerves) and telecom where any downtime is unacceptable.