12-Factor App Principle #9: Disposability



This content originally appeared on DEV Community and was authored by Naval Kishor Upadhyay

Principle #9: Disposability

Goal: Maximize robustness and agility by making processes fast to start and stop, and able to shut down gracefully without losing work.

What It Means

  • Fast startup: Processes should initialize quickly so they can be brought online rapidly when demand increases.
  • Graceful shutdown: When a process is stopped, it should finish ongoing work or save necessary state before exiting.
  • Crash resilience: Processes can be stopped or restarted at any time without causing data loss or application failure.
  • Support for scaling: Fast start/stop makes it easier to scale up and down in response to demand.

Why It Matters

  • High availability: Quickly replace failed processes to keep the app running smoothly.
  • Efficient scaling: Add or remove capacity instantly.
  • Reliable deployments: Rolling updates happen faster and with less downtime.
  • Better recovery: System can recover from failures with minimal disruption.

Example

A payment processing system:

  • Worker processes handle payment requests from a queue.
  • When scaling down, the process finishes processing the current payment before shutting down.
  • New processes can start within seconds to handle sudden spikes in transactions.

Best Practices

  1. Design processes to start within seconds.
  2. Ensure processes handle termination signals gracefully.
  3. Avoid long-running in-memory tasks; use external queues or storage.
  4. Test scaling scenarios regularly.
  5. Use orchestration tools to manage process lifecycle.

Takeaway: Fast, disposable processes improve scalability, reduce downtime, and make your application more resilient to change and failure.


This content originally appeared on DEV Community and was authored by Naval Kishor Upadhyay