top of page

12 Factor App

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • Apr 2, 2022
  • 3 min read

The twelve-factor methodology is a set of twelve best practices to develop applications developed to run as a service. This was originally developed by Heroku for application deployed on their cloud platform.


12 Factor app is a set of principles for building independent, scalable, performant, fault tolerance, resilient enterprise application. 12-factor app principles got very popular as it aligns with Microservice principles.


12 Factor App Principles

  1. Codebase (One codebase tracked in revision control, many deploys)

  2. Dependencies (Explicitly declare and isolate the dependencies)

  3. Config (Store configurations in an environment)

  4. Backing Services (treat backing resources as attached resources)

  5. Build, release, and Run (Strictly separate build and run stages)

  6. Processes (execute the app as one or more stateless processes)

  7. Port Binding (Export services via port binding)

  8. Concurrency (Scale out via the process model)

  9. Disposability (maximize the robustness with fast startup and graceful shutdown)

  10. Dev/prod parity (Keep development, staging, and production as similar as possible)

  11. Logs (Treat logs as event streams)

  12. Admin processes (Run admin/management tasks as one-off processes)

Codebase (One codebase tracked in revision control, many deploys)

Single codebase & multiple deploy like dev, qa, staging & prod.

Codebase should be same for all environment.

Subversion, git support very well

Dependencies (Explicitly declare and isolate the dependencies)

Managing dependencies externally with dependency management tool. In the context of java, tool like maven, gradle can be used to manage dependencies .

Chef, ansible, etc. to install system-level dependencies.

For Containerized environment, Docker can be used.


Config (Store configurations in an environment)

There should not be hardcoded values for the configuration parameter in the codebase, that will create tight dependency. Such parameter should be configurable.

For example

Database connections and credentials, system integration endpoints

Credentials to external services/apps to connect

Application-specific information like IP Addresses, ports, and hostnames, etc.

Such parameter should be externalized and can be loaded based on the profile like dev qa, prod.


Backing Services (treat backing resources as attached resources)

As per 12 factor app principles, a backing service is an application/service the app consumes over the network as part of its normal operation.

For example

Database connections and credentials, system integration endpoints

Message Broker Endpoints connection, credential

Credentials to external services/apps to connect

We can make use of secret management service or Spring Cloud Config for Config & Backing Services.


Build, release, and Run (Strictly separate build and run stages)

We can make use of various tools and techniques to achieve the objective.

Tool & Techniques

Maven

Docker

Docker plugin to create images and push it to docker hub repository

Jenkin/git hub hooks for CI/CD pipeline

Integrate source code repository with Jenkin or git hub hooks

Processes (execute the app as one or more stateless processes)

Application is executed as process inside the execution environment. There can be one or more instances to serve the user demand. If we model the process as stateless, will allow us to scale it horizontally. Any state data need to be stored to persistence storage and retrieved it from there. We can make use of caching infrastructure like redis, hazalcaste to get better performance based on the requirements.


Port Binding (Export services via port binding)

12 factor app is completely self-contained and doesn't need any external webserver for execution. The web app exports HTTP as a service by binding to a port, and listening to requests coming in on that port.


For example : Spring boot export your app as HTTP service with embeded tomcat server and expose it as a service.


Concurrency (Scale out via the process model)

We can make use of containerization to scale out and scale in based on demand.


Disposability (maximize the robustness with fast startup and graceful shutdown)

With containerization, we can quickly start/graceful shutdown application.


Dev/prod parity (Keep development, staging, and production as similar as possible)

12 factor app methodology suggests keeping the gap between development and production environment as minimal as possible. This reduces the risks of showing up bugs in a specific environment.

we can make use of Spring profile for each environment.


Logs (Treat logs as event streams)

12 factor app principles advocate separating the log generation and processing the log's information. From the application logs will be written as a standard output and the execution environment takes care of capture, storage, curation, and archival of such stream should be handled by the execution environment.


We can make use of various solutions like ELK, Fluentd, Splunk.


Admin processes (Run admin/management tasks as one-off processes)

12 factor app principles advocates for keeping such administrative tasks as part of the application codebase in the repository. By doing so, one-off scripts follow the same process defined for your codebase.


Conclusion

Developing an application to be a twelve-factor app certainly has its benefits, especially when we wish to deploy them as services on the cloud. With these factors, we can develop an application which is modular, independent, portable, scalable, and observable.


It plays an important role where we need model applications to have higher throughput and lower latency with virtually no downtime and failure. With Microservices Architecture, Containerization & DevOps , We can achieve the objective.



 
 
 

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page