Zero-Downtime Deploys and Hot Upgrades
Ship new Elixir releases without dropping connections using rolling deploys, health checks, and the BEAM's hot code upgrade capabilities.
Zero-Downtime Deploys and Hot Upgrades is a free Elixir & Phoenix: Scalable Backend Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Elixir & Phoenix: Scalable Backend Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Zero Downtime Matters
Restarting a server drops in-flight requests and live WebSocket connections. Zero-downtime deploys roll out new code while users stay connected and unaware.
Two Strategies
The BEAM supports two upgrade paths:
- Rolling deploys: start new nodes, drain old ones — simple and common
- Hot code upgrades: swap code inside a running node without restart — powerful but complex
Rolling Deploys
A rolling deploy boots a new release alongside the old, shifts traffic over via a load balancer, then shuts the old one down. Most teams use this because it is straightforward and tooling-friendly.
Health Check Endpoints
Load balancers need to know when a new node is ready. Expose a lightweight health endpoint that returns 200 only when the app can serve traffic.
get "/healthz", HealthController, :check
# def check(conn, _), do: send_resp(conn, 200, "ok")Connection Draining
Before stopping an old node, stop accepting new requests but let active ones finish. This draining avoids cutting users off mid-request.
config :my_app, MyAppWeb.Endpoint,
drainer: [shutdown: 30_000]Database Migrations Safely
Old and new code run side by side during a rolling deploy, so migrations must be backward compatible. Add columns before using them; never rename or drop in a single deploy.
Hot Code Upgrades
The BEAM can replace a module's code in a live system. :code.load_file/1 loads the new version; running processes switch over on their next function call.
:code.purge(MyModule)
:code.load_file(MyModule)Appups and Relups
For full hot upgrades of a release, the BEAM uses appup files (per-application upgrade instructions) and relup files (release-level). Tools like Distillery could generate these.
code_change Callbacks
A long-lived GenServer can migrate its state during a hot upgrade via the code_change/3 callback, reshaping old state into the new format.
def code_change(_old_vsn, state, _extra) do
{:ok, Map.put(state, :version, 2)}
endTrade-offs
Hot upgrades avoid any restart but are hard to test and reason about. Most teams prefer rolling deploys for predictability, reserving hot upgrades for embedded or always-on telecom-style systems.
Rollback Plans
Always have a rollback ready:
- Keep the previous release artifact
- Make migrations reversible or additive only
- Automate rollback in your deploy pipeline
Quick Check
Test your zero-downtime knowledge.
Recap
You learned zero-downtime deployment:
- Rolling deploys drain old nodes while new ones serve
- Health checks tell the load balancer when a node is ready
- Migrations must be backward compatible
- Hot code upgrades swap code live via appup/relup and
code_change - Always keep a rollback plan
Users stay connected through every release.
Frequently asked questions
Is the “Zero-Downtime Deploys and Hot Upgrades” lesson free?
Yes — the full text of “Zero-Downtime Deploys and Hot Upgrades” is free to read here on the web, and the Elixir & Phoenix: Scalable Backend Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Elixir & Phoenix: Scalable Backend Development course, upgrade to CoddyKit PRO.
What will I learn in “Zero-Downtime Deploys and Hot Upgrades”?
Ship new Elixir releases without dropping connections using rolling deploys, health checks, and the BEAM's hot code upgrade capabilities. You practise Elixir & Phoenix: Scalable Backend Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Elixir & Phoenix: Scalable Backend Development?
No prior experience is required. Elixir & Phoenix: Scalable Backend Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Zero-Downtime Deploys and Hot Upgrades” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Elixir & Phoenix: Scalable Backend Development lesson?
Yes. Every Elixir & Phoenix: Scalable Backend Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Building Releases with Mix Release
- Containerization with Docker
- Cloud Deployment Strategies
- Zero-Downtime Deploys and Hot Upgrades