DEV Community

Carlos Loredo
Carlos Loredo

Posted on

SaaS: The Twelve-Factor app methodology explained

The Twelve-Factor App methodology is a methodology for building software-as-a-service applications. These best practices are designed to enable applications to be built with portability and resilience when deployed to the web.

12-factors_img
To understand this methodology we can divide the twelve factors into 3 key components:
12-factors-3-components
Next, we'll see the best practices that you should follow for every factor to comply with what this methodology says.

Code Factors:

Factor 1 - CodeBase:

codebase_img

  • Code must be tracked in a version control system (VCS) like Github, BitBucket, etc.
  • One-to-One relationship between the CodeBase and the application.
  • There can be multiple deploys of the application.
  • Different versions of the CodeBase can be in each deployment.

Factor 5 - Build, release and run:

build_release_run_img

  • Build: Transform a CodeBase into an executable unit called build.
  • Release: Combine build with configuration so that it's ready to run.
  • Run: Runs the application.

Factor 10 - Dev/Prod parity:

dev_prod_img

  • Minimize differences between deployment and production environments.
  • Back-end services should be the same across environments (dev/prod)

Deploy Factors:

Factor 2 - Dependencies:

dependecy_img

  • Be aware that an app is only reliable as its least reliable dependency.
  • Be sure that code explicitly declares any dependency.

Factor 3 - Config:

config_img

  • Config contains everything that varies between deploys such as credentials and backing services locations.
  • Configs must be kept separate from the code
  • Store config in environment variables.

Factor 4 - Backing services:

back_end_img

  • Applications should not distinguish between local and third-party back-end services.
  • All services should be accessed by URL and credentials so that can be swapped without changing the code.

Factor 6 - Processes:

process_img

  • Stateless and share nothing.
  • Backing services store persistent data since memory and filesystems are not shared across processes.
  • Data is centrally stored.

Factor 7 - Port binding:

ports_img

  • Export services by port binding. HTTP and other services are exported in this way.
  • To bind a port usually you must declare a web server library.
  • Applications can be backing services for other applications.

Factor 9 - Disposability:

disposability_img

  • Applications should have minimal process start-time and graceful termination.
  • Quickly deploy code and configure changes.
  • Easily scale applications.

Factor 11 - Logs:

logs_img

  • Applications should not concern themselves with storing logs.
  • Applications should trend logs as event stream written to stdout.
  • Execution environment captures the stream for all apps aggregates the logs and routes logs to their destination.

Operate Factors:

Factor 8 - Concurrency:

concurrency_img

  • Concurrent processes can be used to scale the application.
  • Stateless processes can be spun up without creating dependencies on other processes.

Factor 12 - Admin processes:

admin_process_img

  • Enable one-off application management processes such as database migration.
  • Run against a release using the same CodeBase configuration.
  • Are included in the application code.

Sources:

  • The Twelve-Factors Methodology website: 12factor

Top comments (1)

Collapse
 
endymion1818 profile image
Ben Read

This is so much clearer to understand than the website you referenced ... thank you!