The 12 factor methodology for application development


The 12 factor methodology for application development

In today’s world of technology, it is crucial to adapt to market demands and provide efficient solutions. In this regard, the concept of the 12 factors serves as the key guide for building efficient and adaptable applications. These factors provide clear and practical guidelines that enable the development of applications with easy and scalable deployment in different environments. By following these guidelines, development teams can ensure the rapid and frequent delivery of applications, meeting the changing needs of users in an ever-evolving technological environment.

In this article, we will explore how the 12 factores (The Twelve-Factor App) can empower and evolve our applications. We will discover how each factor triggers significant changes in the design and development of software, resulting in more resilient, scalable, and easily maintainable applications.

Join us on this journey to transform the way we build and deploy applications with the 12 factors.


The challenges of rapid delivery

In a dynamic environment, development teams face significant challenges when it comes to rapid value delivery. These challenges include maintaining code quality, managing external dependencies, and ensuring smooth deployment. It is in this context that the 12 factors stand out as an invaluable guide.

The 12 factors provide clear and practical guidelines to address these specific challenges. The factors tackle the need to adopt architectures and practices for easy and scalable deployment in various environments. They align with the principles of iterative delivery, collaboration, and adaptability.

In this article, we will explore how the 12 factors address these challenges, improve code quality and management of external dependencies. We will also see how they facilitate seamless deployments. Join us on this journey to understand the importance of the 12 factors and discover how they can transform the way we build and deploy applications in a highly competitive environment.

Factor 1: Codebase

In the 12 Factor methodology, the codebase is the repository used to version control and deploy an application. It is managed through a version control system like Git, Mercurial, or Subversion.

Each twelve-factor application has a single codebase. Sharing code between different applications is considered a violation of this methodology, and it is recommended to separate shared code into libraries.

While there may be multiple deployments of an application, they all rely on the same codebase. There may be different versions of the code in each deployment, but they are still identified as deployments of the same application.

The codebase is essential to ensure consistency and scalability of the application over time.

Factor 2: Dependencies

In the 12 Factor methodology, it is crucial to explicitly declare and isolate dependencies of an application. This is achieved by fully and explicitly declaring libraries and dependencies in a manifest file. Additionally, isolation tools are used during execution to avoid conflicts with other parts of the system.

Explicitly declaring dependencies makes it easier to set up for new developers. They only need to install the language runtime and dependency management tools. Furthermore, 12 Factor applications should not rely on external system tools. Instead, they should include them internally to ensure their availability in any environment.

In 12 Factor, the dependencies factor involves explicitly declaring and isolating the application’s dependencies to ensure consistency and portability.


Factor 3: Configuration

In the 12 Factor methodology, there is an emphasis on separating application configuration from the codebase. Configuration includes anything that may vary between different deployments, such as database resources, credentials for external services, and environment-specific values.

It is important to avoid storing configurations as constants in the code, as this violates the principle of separating configuration from code. Instead, it is recommended to store configuration in environment variables, which can be easily modified without the need to make changes to the code. Environment variables are standard across all languages and operating systems, and their use prevents the possibility of accidentally storing sensitive configuration in the code repository.

Instead of categorizing configuration into predefined groups or environments like development, test, and production, the 12 Factor methodology manages environment variables independently for each deployment. This avoids the need to constantly create new environments as the application grows, which can lead to complicated and fragile configuration management.

Factor 4: Backing Services

In the 12 Factor methodology, backing services are pluggable resources for the application, such as databases, messaging systems, email services, and caching systems, that are accessed over the network.

There is no distinction between local and third-party services; both are considered connected resources and are accessed through a URL or identification stored in the configuration. This allows for the easy substitution of local services with third-party services without modifying the code. For example, a local database can be switched to one managed by an external provider simply by updating the configuration.

Each backing service is treated as a separate resource. For example, two MySQL databases used for sharding are considered distinct resources. A 12 Factor application treats these resources as connected entities, demonstrating loose coupling with the specific deployment.

Resources can be attached and detached as needed. For example, if a database has issues, it can be switched to a new database server restored from a backup without modifying the code.

The backing services factor in 12 Factor involves treating the services used by the application as pluggable resources, regardless of whether they are local or third-party. This provides flexibility and agility in managing the underlying services without affecting the application code.

Factor 5: Build, Release, Run

In the 12 Factor methodology, the stages of building, releasing, and running code are clearly separated.

Build: The code is transformed into an executable package with all necessary dependencies.

Release: The build is combined with the configuration to create a ready-to-run distribution.

Run: The application is executed using a specific distribution.

These stages are kept separate, and no changes are made to the code during runtime. Distribution management tools are used to facilitate rolling back to previous versions.

Each time new code is deployed, a new build is created. The run phase is stable and can happen automatically, while the build phase is more complex and requires attention.

“Build, Release, Run” in twelve-factor involves separating the stages of building, releasing, and running code, ensuring an orderly and controlled deployment of the application.

Factor 6: Processes

In the 12 Factor methodology, the application runs as one or more stateless processes in the execution environment. Processes are independent and do not share information with each other.

12 Factor processes are stateless. Any information requiring persistence is stored in a stateful backing service such as a database.

Memory space and the file system are used as temporary caches for transactions. However, it should never be assumed that this information will be available to subsequent processes. Even a process restart will wipe out all local state.

Instead of relying on sticky sessions to maintain session information, it is recommended to use information stores with expiration mechanisms, such as Memcached or Redis.

In 12 Factor, processes run statelessly, and any persistent information is stored in a backing service. The reliance on memory or the file system for data storage is avoided, and appropriate external storage is used for session information.

Factor 7: Port Binding

In the Port Binding factor of 12 Factor, web applications run as standalone services without relying on a web server.

The application itself listens for requests on an assigned port and is accessed through a specific URL.

This port binding allows applications to be self-contained and act as public web services.

Additionally, different services can also utilize port binding to offer their functionalities to other applications.

Factor 8: Concurrency

In the Concurrency factor of twelve-factor, applications are executed using a process model that allows for scaling and handling diverse workloads. The running processes represent the scalability of the application, while different types of processes represent the diversity of the workload.

In 12 Factor applications, processes are treated as first-class citizens. The process model is based on the Unix process model and allows for distributing the execution of the application by assigning each type of work to a specific process type. For example, HTTP requests can be processed by one process type, while intensive tasks can be handled by threads.

It is important to note that processes should manage their internal concurrency through threads or asynchronous models. Additionally, the process model allows for horizontal scaling by dividing processes across multiple physical machines.

Factor 9: Disposability

In 12 Factor applications, processes are disposable, meaning they can start and stop quickly as needed. This allows for agile scalability, rapid deployment of changes, and increased robustness in production.

Processes should minimize startup time to facilitate distribution and scaling. They gracefully shut down by ceasing to listen on the port associated with the service.

Workers return in-progress jobs to a queue for safe completion. Processes should be prepared to handle unexpected terminations using robust queuing systems.

It is important to be able to start and stop processes without affecting the application as a whole. The use of process management tools or containers facilitates control and provides agility in delivery and error handling. In summary, disposability makes the system more robust by achieving fast starts and safe shutdowns.

Factor 10: Dev/Prod Parity

In 12 Factor applications, achieving parity between development and production environments is sought through continuous deployments and the use of the same backing services.

This involves reducing the time between deployments, involving developers in production, and minimizing tooling differences.

It is important to avoid the practice of using different services in development and production, as it can lead to errors and affect application stability.

Package management systems and virtualization tools facilitate the creation of production-like environments.

Using the same type and version of each service in all deployments is recommended.

In summary, factor 10 aims to achieve parity between development and production environments.

Factor 11: Logs

Logs in a 12 Factor application are treated as event streams that allow for observing behavior during runtime. Instead of managing log files, each process writes its events to the standard output. During development, developers can view the flow in their terminal.

In pre-production and production deployments, event streams are captured by the execution environment. They are subsequently directed to final destinations for review and archiving. These destinations are managed by the execution environment and can be open-source tools like Logplex and Fluentd.

Logs can be redirected to files or viewed in real-time. They can also be sent to analysis systems like Splunk or data storage systems like Hadoop/Hive. These systems offer the ability to search past events, create trend charts, and trigger custom alerts.

Factor 11 treats logs as event streams. This eliminates the need to manage log files and allows for real-time review and analysis.


Factor 12: Process Manager

In 12 Factor applications, management and administrative tasks are executed as independent processes that run once. These processes include database migrations, interactive consoles, and maintenance scripts.

The same isolation and environment techniques used for regular application processes are employed. The management code is shipped along with the application code to maintain synchronization.

Using languages with REPL consoles is recommended to facilitate the execution of management scripts. In local environments, they are run from the application directory’s console. In production, remote mechanisms like SSH are used.

Factor 12 states that management tasks are executed as independent processes, using the same environment and isolation techniques as regular processes.

Benefits of following the 12 factors:

Following the 12 factors provides several significant benefits. These benefits include:

  • Greater flexibility: The 12 Factor provide clear guidelines for building adaptable applications. By following these principles, applications become more flexible. They can easily adapt to changes in business requirements and adjust to changes in the operating environment.
  • Ease of scalability: The 12 Factor promote separation of concerns and the use of scalable services, facilitating application scalability. By designing the architecture according to these factors, applications can grow and adapt seamlessly, handling higher volumes of users or demand.
  • Improved maintainability: The 12 Factor emphasize modularity, code clarity, and proper dependency management. These practices lead to more maintainable applications. It becomes easier to identify and resolve issues, perform updates, and make changes without impacting other parts of the system.
  • Faster deployment: The 12 Factor encourage decoupling of environment configuration, enabling fast and consistent deployment of applications across different environments. By following these guidelines, the deployment process becomes more automated and repeatable, allowing for more efficient delivery of new application versions.
  • Greater operational efficiency: The 12 Factor foster practices such as monitoring, logging, and resource management. Implementing these factors makes applications more efficient in terms of resource utilization, issue detection, and performance optimization. This results in improved operational efficiency and reduced downtime.

In conclusion, the 12 Factor are crucial for the scalable delivery of applications.

In the current era, applying the concepts of the 12 Factor has become crucial to ensure the rapid, scalable, and smooth delivery of applications.

By following these guidelines, development teams can effectively evolve their applications and adapt to the constant changes of the current technological environment.

Adopting practices like version control, dependency management, stage separation, and the use of modern automation and infrastructure tools contribute to building robust and flexible applications.

Implementing the 12 Factor paves the way for success in delivering applications in the ever-evolving digital age.

If your organization is seeking support for implementing application development projects with subject matter experts, we cordially invite you to contact us.

Itequia Team