Elixir & Phoenix: Scalable Backend Development · Lektion

Deployments ohne Ausfallzeit und Hot Upgrades

Veröffentlichen Sie neue Elixir-Releases, ohne Verbindungen zu unterbrechen – mit Rolling Deployments, Health Checks und den Hot-Code-Upgrade-Funktionen der BEAM.

Lektion 4 von 413 Schritte

Deployments ohne Ausfallzeit und Hot Upgrades ist eine kostenlose Elixir & Phoenix: Scalable Backend Development-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Elixir & Phoenix: Scalable Backend Development-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Elixir & Phoenix: Scalable Backend Development-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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)}
end

Trade-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.

Kostenlos starten

Lerne Elixir mit einem KI-Tutor — kostenlos

Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.

Kurse
12
Lektionen
48

Häufig gestellte Fragen

Ist die Lektion „Deployments ohne Ausfallzeit und Hot Upgrades“ kostenlos?

Ja — der vollständige Text von „Deployments ohne Ausfallzeit und Hot Upgrades“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Elixir & Phoenix: Scalable Backend Development-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Elixir & Phoenix: Scalable Backend Development-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Deployments ohne Ausfallzeit und Hot Upgrades“?

Veröffentlichen Sie neue Elixir-Releases, ohne Verbindungen zu unterbrechen – mit Rolling Deployments, Health Checks und den Hot-Code-Upgrade-Funktionen der BEAM. Du übst Elixir & Phoenix: Scalable Backend Development mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Elixir & Phoenix: Scalable Backend Development zu starten?

Keine Vorkenntnisse erforderlich. Elixir & Phoenix: Scalable Backend Development auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Deployments ohne Ausfallzeit und Hot Upgrades“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Elixir & Phoenix: Scalable Backend Development-Lektion Code schreiben und ausführen?

Ja. Jede Elixir & Phoenix: Scalable Backend Development-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Releases mit Mix Release erstellen
  2. Containerisierung mit Docker
  3. Strategien für Cloud-Bereitstellungen
  4. Deployments ohne Ausfallzeit und Hot Upgrades
← Zurück zu Elixir & Phoenix: Scalable Backend Development