The Twelve-Factor App (Part 1)

Tram Ho


Today, software is often delivered as a service, called web apps, or software-as-a-service (SaaS). The Twelve-Factors App is a method to build SaaS with the following criteria:

  • Use the narrative format for automation settings, to cut costs and time for new developers.
  • There are clear conventions with the operating system below, providing maximum ability to switch between execution environments.
  • Suitable for deployment on cloud platforms, reducing administrative requirements for servers and systems.
  • Minimize differences between development and production environments, allowing maximum flexibility in continuous development.
  • Scalable without major changes to tools, architecture, or development method.

The Twelve-Factors method is applicable to applications written in any programming language and used in combination with any backend service. As its name suggests Twelve-Factors consists of 12 elements:

  1. Codebase (Codebase is tracked with the version management system, and multiple deployments)
  2. Dependencies (Declare and separate dependencies)
  3. Configuration (Store configuration in the environment)
  4. Support Services ( Support Services as Additional Resources)
  5. Construction, release, operation (Completely separate between construction and operation steps)
  6. Process (Operating the application as one or more stateless processes)
  7. Open network port (Provide services through network port)
  8. Synchronization (Horizontal expansion through process model)
  9. Availability (Optimized with fast startup and stable software stopping)
  10. The similarity between the development process and the actual operation (Keep the development, staging, production environment as similar as possible)
  11. Logs (Logs treated as event streams)
  12. Administrative process (Implementing the administrative task as a process)

Let’s find out more about these 12 factors:

1, Codebase

The code will always be monitored by a version control system like Git. A backup version of the database is called a code repository. A code is any individual repository (in a unified version control system like Subversion), or any group of repositories sharing the same source commit (in a decentralized version control system). like Git).

There will always be a one to one correlation between code and the application:

  • If there’s a lot of native code, it’s not an application – it’s a distributed system. For elements in a distributed system is an application, with each individual obeying the Twelve-Factor law.
  • Multiple applications sharing the same code violate the rules of the Twelve-Factor. The solution here is to consider grouping shared codes into libraries that can be embedded through the dependency manager.

Only one native code per application, but there will be multiple deploy of an application. This is a very common case of pages that have gone live. In addition, each developer will have an application store running locally, each of which is considered a deploy.

The code will be the same on deployments, although different versions may work on each deploy.

2, Dependencies

Most programming languages ​​provide a system for distributing support libraries, such as Rubygems for Ruby. Libraries installed through a package system can be installed as site packages or bundled in a directory of applications (also known as “vendoring” or “bundling”).

A 12-factor application never depends on the absolute presence of system packages. It declares all dependencies completely via dependency declaration. Furthermore, it uses a dependency separator during implementation to ensure that no absolute dependencies are “dropped” into surrounding systems. The full and clear declaration of dependencies is applied equally to both production and development systems.

For example, Ruby’s Gem Bundler provides the Gemfile dependency declaration format to declare gems and bundle exec to separate dependencies. Regardless of the tool, dependency and separator declarations must always go together

Another benefit of declaring dependencies is that it simplifies the installation process for new programmers to take over the project. New developers can get code on their development system, only with one requirement being a pre-installed programming language and a dependency manager. They can be used to set up everything needed to operate an application with a predefined compilation / build command. An example of a setup command for Ruby is bundle install

The Twelve-Factor App at the same time may not depend on any absolute system tool presence. For example, built-in tools like ImageMagick or curl. While these tools may be available on most systems, there is no guarantee they will be available on all systems where the application may run in the future, or if there is a search version. See on future systems that will be compatible with the application. If the application needs to be preinstalled as a system tool, those tools should be included with the application.


Translated documents:

Share the news now

Source : Viblo