The Twelve-Factor App Manifesto

repository·next·Indexed 25 days ago

https://github.com/twelve-factor/twelve-factor

A set of principles for building scalable, maintainable, and portable software-as-a-service applications. The manifesto covers key architectural patterns including the strict separation of config from code, the use of environment variables, the process model for concurrency, and the three stages of deployment (build, release, and run).

Tokens
5.9K
Snippets
1
Records
40
Agent score
82%

What's inside Twelve-Factor App

  1. What is the Twelve-Factor App methodology?

    next

    The Twelve-Factor App is a methodology for building software-as-a-service (SaaS) applications. It provides a set of principles designed to create apps that are portable, scalable, and easy to deploy on modern cloud platforms.

    Key goals of the methodology include:

    • Setup Automation: Using declarative formats to minimize onboarding time for new developers.
    • Portability: Maintaining a clean contract with the underlying operating system to ensure maximum portability between environments.
    • Cloud Readiness: Designing apps suitable for deployment on modern cloud platforms to reduce the need for manual systems administration.
    • Environment Parity: Minimizing divergence between development and production environments to enable continuous deployment.
    • Scalability: Ensuring the application can scale up without requiring significant changes to architecture, tooling, or development practices.
  2. Access the Twelve-Factor Manifesto text

    next
    The text of the updated Twelve-Factor Manifesto is located in the content directory of this repository. Note that updates are currently being managed in the next branch until the current round of updates is finalized by the maintainers.
  3. The Twelve-Factor Manifesto Overview

    next
    The Twelve-Factor Manifesto is a methodology for building software-as-a-service (SaaS) applications. It consists of twelve core principles designed to ensure scalability, portability, and maintainability. These factors cover aspects ranging from codebase management and dependency isolation to configuration, backing services, and process models.
  4. Run admin/management tasks as one-off processes

    next

    A twelve-factor app distinguishes between regular business processes (e.g., handling web requests) and one-off administrative or maintenance tasks. Administrative tasks should be treated as separate, ad hoc processes rather than being integrated into the long-running application processes.

    Common examples of administrative tasks include:

    • Running database migrations (e.g., manage.py migrate in Django or rake db:migrate in Rails).
    • Launching a REPL (Read-Eval-Print Loop) shell to execute arbitrary code or inspect models against the live database.
    • Executing one-time scripts committed to the repository (e.g., php scripts/fix_bad_records.php).
  5. Maintain a one-to-one correlation between codebase and app

    next

    To comply with the Twelve-Factor methodology, there must be exactly one codebase per app.

    • If you have multiple codebases: You are building a distributed system, not a single app. Each component in that system should be treated as an individual app that can independently comply with Twelve-Factor.
    • If multiple apps share the same codebase: This is a violation.

    How to share code: If multiple apps require shared functionality, do not share a codebase. Instead, factor the shared code into libraries and include them via a dependency manager.

  6. Decouple log routing and storage from the application

    next

    To maintain twelve-factor compliance, an application must never attempt to write to or manage logfiles directly. The responsibility for capturing, routing, and storing log streams belongs entirely to the execution environment.

    Benefits of Decoupling

    By delegating log management to the environment (using tools like Logplex or Fluentd), you can route streams to various destinations without changing application code, such as:

    • Log Indexing and Analysis Systems (e.g., Splunk): For finding specific past events and active alerting.
    • Data Warehousing Systems (e.g., Hadoop/Hive): For large-scale graphing of trends like requests per minute.
    • Real-time viewing: Using tail in a terminal.
    • Long-term archival: Managed by the environment for historical introspection.
  7. Store config in environment variables

    next

    Instead of using constants in code or language-specific config files (like config/database.yml), a twelve-factor app stores configuration in environment variables (env vars).

    Benefits of environment variables:

    • Ease of change: They can be changed between deploys without modifying any code.
    • Security: There is little chance of accidentally checking them into revision control.
    • Portability: They are a language- and OS-agnostic standard, unlike framework-specific config files or Java System Properties.
  8. Ensure each release is a unique, immutable snapshot

    next

    To support reliable deployments and rollbacks, every release must be treated as an immutable, append-only entry in a ledger.

    • Immutability: Once a release is created, it cannot be modified.
    • Uniqueness: Every release must have a unique identifier, such as a timestamp (e.g., 2011-04-06-20:32:17) or an incrementing version number (e.g., v100).
    • Changes: Any change to the code or the configuration must result in the creation of an entirely new release.
  9. Treat env vars as granular controls, not grouped by environment

    next

    Avoid grouping configuration into named batches or 'environments' (e.g., development, test, production). Grouping by environment leads to a combinatorial explosion of configuration as you add new deploys like staging, qa, or personal developer environments (e.g., joes-staging).

    In a twelve-factor app, environment variables are managed as granular controls that are independently set for each deploy. This model scales smoothly as the number of deploys increases.

  10. Explicitly declare and isolate dependencies

    next

    To satisfy the Twelve-Factor methodology for dependencies, an application must be built and run in deterministic environments. This involves two critical steps:

    1. Explicit Declaration: All dependencies must be declared completely and exactly in a dependency declaration manifest. This allows new developers to set up the environment using only the language runtime and a dependency manager.
    2. Isolation: The application must use a dependency isolation tool during execution to ensure that no implicit dependencies from the surrounding system "leak in."

    Dependency declaration and isolation must be used together; using only one is insufficient. The same specification must be applied uniformly to both production and development environments.

  11. Track the codebase in a version control system

    next

    A twelve-factor app must always be tracked in a version control system. The copy of the revision tracking database is referred to as a code repository (or code repo).

    • In centralized systems (like Subversion), a codebase is any single repo.
    • In decentralized systems (like Git), a codebase is any set of repos that share a root commit.