Twelve-Factor App | Disposability

The ninth factor of the Twelve-Factor App methodology emphasizes disposability. 

Why Maximize Robustness with Fast Startup and Graceful Shutdown?

Disposability ensures that processes can be started or stopped at a moment's notice without negative impacts.

  • Resilience: Reduces downtime and allows for easy recovery from crashes.
  • Scalability: Facilitates dynamic scaling to adapt to changing loads.
  • Maintainability: Simplifies updates and maintenance tasks.

How to Achieve Fast Startup and Graceful Shutdown

Design for Quick Initialization

Processes should be designed to start quickly, minimizing the time to become ready to handle requests.

Example: Lazy Initialization in a Web Application

Initialize heavy resources on the first request rather than during startup.

Implement Graceful Shutdown

Processes should be able to stop gracefully, completing current tasks and releasing resources properly.

Example: Graceful Shutdown in a Node.js Application
process.on('SIGTERM', () => {
  server.close(() => {
    console.log('Process terminated');
Utilize Health Checks

Health checks can be used to monitor process readiness and liveliness.

Example: Kubernetes Readiness Probe
    path: /health
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10

Deployment Strategies with Disposability

In an environment, disposability facilitates continuous deployment and robust operation.

  • Deployment Stage: Use orchestration tools that support graceful scaling and updates.
  • Monitoring Stage: Implement health checks to monitor process health and readiness.
  • Recovery Stage: Ensure quick recovery from failures through automated restarts.

Disposability, characterized by fast startup and graceful shutdown, is vital to modern, cloud-native applications.