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.
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.
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.
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
--jsonand 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
-
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 -
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 -
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 -
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
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.Testin place ofuse 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.Clusterstarts 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 - 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 withmix hotcode.check, or add them to everymix credorun withmix hotcode.credo.install. A CI step fails by itself when a rule finds something.mix hotcode.check mix hotcode.check --strict --format json lib/ - 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.
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.
Where to go next
- Documentation guides, reference and checks
- Getting started install, configure, first deploy
- Hotcode on GitHub source, issues, license
- The agent skill hand it to a coding agent to adopt Hotcode for you; the skill itself is in
skills/hotcode