IX. Disposability

Maximize robustness with fast startup and graceful shutdown

“The twelve-factor app’s processes are disposable. They can be started or stopped at a moment’s notice.” – 12factor.net

When to use

Always. Especially in auto-scaling environments.

Why it matters

  • Scalability: If startup takes 10 mins, you can’t scale up quickly when traffic spikes.
  • Robustness: If you crash, you need to restart instantly.

Signs of Violation

  • Very long “warming up” phases.
  • Corrupted data if the server executes kill -9 (SIGKILL).

Explanation

Problem

Servers die; Auto-scalers kill containers. If your app fights this, you will have downtime.

Solution

  1. Fast Startup: Get ready to serve requests in seconds.
  2. Graceful Shutdown: Catch SIGTERM. Finish current request, stop listening for new ones, exit.

Real world analogy

Light bulb. You flip the switch, it’s on instantly. You flip it off, it’s off. You don’t “boot up” a light bulb for 10 minutes.

Pros and Cons

Pros Cons
  • High availability
  • Elasticity
  • Requires careful handling of long-running connections
  • Comparison

    • Crash-only software: A related concept where restart (recovery) is the only mode of starting.

    Code example

    Typescript

    Bad (Violation)

    Good (Adherence)

    PHP

    Bad (Violation)

    Good (Adherence)