Update a running Elixir app without restarting it.

Hotcode sends only the code that changed to your live servers. Open connections stay open, and the data in memory stays where it is.

Get started See one change, step by step

Experimental. MIT licensed. Not on Hex yet.

A deploy restarts your servers

When you deploy a new version, each server stops and starts again. Everyone connected to it is dropped and has to reconnect. Everything the app held in memory is gone. Caches start empty. Sessions and counters start from zero.

Teams plan around this. They deploy at quiet hours, or they accept a burst of reconnects.

Erlang, the platform Elixir runs on, can already swap code inside a running system. But the upgrade files it needs are written by hand, and the standard release tools do not generate them.

Change the code while the app keeps running

Think of a shop with a queue at the till. A restart closes the shop, sends everyone home and opens again with the new price list. A hot upgrade hands the cashier the new price list while the queue keeps moving.

A restart Three connections run, then all stop together while the server is down and the memory is emptied. The connections start again afterwards and the memory is empty. With a restart connections memory server down starts empty A hot upgrade Three connections run without a break. New code arrives at one point in time and the memory bar carries on unchanged. With Hotcode connections memory new code kept
Time runs left to right. Each line is a connected user.

Hotcode compares your new build with the code running on the server and sends only the modules that changed. The server loads them in one step. Processes keep running, and their data is converted to the new shape where it needs to be. Where a process has to be replaced, Hotcode hands its data and its connections to the new one.

How a deploy works, step by step

Who it is for

A good fit

  • Long-lived connections you do not want to drop: websockets, raw TCP, Phoenix Channels.
  • Data in processes or ETS tables that is slow or costly to rebuild.
  • A team that can ask for two signatures on a deploy and keep the keys off servers.

Not a fit, or not yet

  • Anything that needs a production track record today.
  • A change that upgrades Erlang/OTP, Elixir or Hotcode itself.
  • An app with nothing to keep across a restart. A stateless server that restarts in a second gains little.

The full list of limits

What you get

Signed patches only
A server holds public keys and never a private one. It loads a patch only if the patch carries enough signatures, was made for that environment, has not been used before and is less than 15 minutes old. You can require two people to sign. Security
Undo
Every deploy can be rolled back. If something fails halfway, the server puts the old code back. If it cannot, it refuses further deploys rather than carry on in a state nobody can describe.
Health checks
A cluster is upgraded one node at a time, with a health check after each. If one fails, the nodes already done go back to the previous release. A release can also carry a signed deadline: if the cluster has not followed by then, it is undone. Clusters
Checks that catch mistakes before you ship
17 code rules for your editor and CI find the patterns that break a hot deploy. A dry run lists what would change and what is risky. On the server, new code is tried on copies of live data before it is loaded. Test helpers run a hot deploy inside your own test suite. Checks we run
One node up to 200 or more
Start with a single node. For a cluster, roll node by node. For a large fleet, deploy to a few canary nodes and the rest pull the release from each other, with a cap on how many nodes upgrade at once. This is designed for 200 nodes and more. So far it has been tested in a 200-node simulation, not on a real fleet. Large clusters
Runs from CI
Every command takes --json and exits with a code that says what happened, so a pipeline can tell “refused, nothing ran” from “rolled back”. Deploying from CI

What a change looks like

  1. Change the code

    Edit your app as usual. If a change alters what the data in a process means, add one small step that converts the old shape to the new one, and one that converts back.

    defmodule Cart do
      use Hotcode.Versioned, vsn: 3
    
      # upgrade: vN -> vN+1
      def upgrade(1, s), do: %{items: Enum.map(s.items, &{&1, 0}), total: 0}
      def upgrade(2, s), do: Map.put(s, :currency, "EUR")
    
      # downgrade: vN -> vN-1, needed for rollback
      def downgrade(3, s), do: Map.delete(s, :currency)
      def downgrade(2, s), do: %{items: Enum.map(s.items, &elem(&1, 0))}
    end
  2. Look before you ship

    A dry run lists what would change and what is risky. Nothing is touched.

    mix hotcode.deploy https://host:4747 --key alice.key --dry-run  # what changes, what is risky
  3. Roll it out

    Hotcode ships only the changed modules, node by node, and checks health after each node.

    mix hotcode.deploy https://host:4747 --key alice.key  # roll it out, node by node
  4. Undo it if you need to

    A rollback is a signed deploy too, so it needs the same signers. For two signers, one builds and signs, the other reads what is being signed, signs and pushes.

    mix hotcode.rollback https://host:4747 --key alice.key  # needs the same signers as a deploy

    Follow a whole session from version 1 to version 3 and back

Helpers for development

A hot deploy can fail in ways a normal test suite never sees. The old code works, the new code works, and the switch between them loses a process, a state field or a message. Hotcode ships tools to catch that while you write the code, long before a patch reaches a server.

Test helpers

use Hotcode.Test in place of use ExUnit.Case. A test builds the next version of a module, deploys it into the test VM while your processes run, and checks that the same process survived, that its state was migrated and that a rollback gives the exact state back. There are helpers for ETS tables, for deploying twice, and for traffic during a deploy. Every test puts the original code back afterwards, even when it fails. Hotcode.Test.Cluster starts real nodes, so you can test a cluster that is halfway through a rollout.

defmodule MyApp.CounterUpgradeTest do
  use Hotcode.Test

  test "v2 keeps the counter process and migrates its state" do
    {:ok, pid} = MyApp.Counter.start_link(count: 3)
    v2 = build("test/releases/counter_v2")

    assert_survives_deploy(pid, v2,
      state: &match?(%{count: 3, history: []}, &1),
      rollback: true
    )
  end
end

Testing your deploys · Test helpers reference

Credo rules

17 rules find the patterns that break a hot deploy, in your editor and in CI: @on_load, NIFs, anonymous functions kept in state, receive loops that stay on old code, and more. Each rule explains why it breaks a hot deploy and how to fix it. Run them on their own with mix hotcode.check, or add them to every mix credo run with mix hotcode.credo.install. A CI step fails by itself when a rule finds something.

mix hotcode.check
mix hotcode.check --strict --format json lib/

Catching mistakes early · All 17 rules

Checks

A dry run lists which modules would change and which are risky, without touching anything. When a patch reaches a node, the analyzer refuses what hot loading cannot handle, and new code is tried on copies of live state before it is loaded. After the load, health checks decide whether a rollout continues or is undone. To see where an existing project stands, the audit script reads it and lists what a hot deploy would trip on, with a fix for each, without changing a file.

Checks we run

Where it stands

Hotcode is experimental. Please read this before you rely on it.

  • It is not on Hex yet. Use a git or path dependency.
  • It has not been run on a production fleet. It has been tested on a three-node demo app (Phoenix Channels, Postgres, a Rust NIF and a raw TCP feed) that moves through eleven versions and back while clients stay connected, and in simulation with 200 nodes.
  • It needs Elixir 1.17 or later and OTP 26 to 29.
  • It does not protect against someone who holds the Erlang cookie, or a signer whose machine is compromised.
  • It is MIT licensed.

Limits · Security · Changelog