B. Blue Green a software delivery tutorial
Vol. I § Zero-downtime series § A series for junior developers
Zero-downtime delivery · 2 / 10 ·

Two slots, one of them live

The simplest fix for the stop-start gap: never take down your only copy of the app. The Titik Terang lab uses two names, blue and green. Both are containers from the same image, on different host ports.

One thing matters from the start: this is not double capacity. Only one slot receives traffic at any moment. The other is idle — deliberately empty, waiting for the next deploy.

Ports that stay on loopback

  • The app inside the container listens on :3000.
  • The blue slot maps to 127.0.0.1:18080.
  • The green slot maps to 127.0.0.1:18081.
  • Caddy listens on :8080 and picks one of those two ports.

Mapping to 127.0.0.1 keeps the slots local. Public readers only ever see Caddy.

Slot playground · two-slots
readerCaddy :8080blue :18080 · upgreen :18081 · down
Blue is live on :18080. Green sits idle on :18081.
  1. Blue is live on :18080. Green sits idle on :18081.
  2. Green can become live. Only one slot receives traffic.
state.jsonlive · last_deployed · rollback_versionstate.json remembers the live slot and the rollback version.

state.json

This small file remembers which slot is live and which version can be rolled back. The playbook reads it before it works — it is the single source of truth. Change the live key in the explainer below to see which idle slot it would pick.

explainer · state
Explanation

The live slot is blue. The playbook will deploy to green on port 18081.

Quick recap

  • Two slots means one live and one idle; capacity stays at one.
  • Slots only listen on 127.0.0.1 — the public may only ever find Caddy.
  • state.json is the source of truth for which slot is live.
  • Bonus: the old slot stays up briefly after a switch — that is the capital for rollback in chapter 10.

Reader notes

Chapter discussion appears once Giscus is connected to the site repository.