Best practices for Microservices with 12-factor
Posted: Tue Jan 28, 2025 6:47 am
In the previous article in this series, we explained what microservices are, what their advantages and disadvantages are, and also highlighted when you should use them. After reading this, if you believe that microservices are a good choice for your product, then continue reading this article and discover good practices to follow when adopting the architecture: the 12-factor.
A 12-step checklist
The best-known reference for good practices for service development is the so-called 12-Factor . Created by Adam Wiggins, co-founder of Heroku , it is presented as “a methodology for building software as a service”, having been created based on the experience gained in the company itself, where more than 9 million services are deployed .
In fact, the 12-factor works as a checklist of good practices, covering topics such as configuration management, internal architecture, DevOps and service lifecycle management.
The 12 factors are:
Codebase: The application code must be in a version control linkedin data system (such as Git, for example). The codebase must be capable of generating multiple deployments (for testing, staging, and production environments, etc.). Different codebases must not have duplicate code; duplicates must be treated as new applications, included through a dependency management system.
Dependencies: All dependencies must be declared accurately. An application should never assume that the libraries or tools it depends on are already present; it should always take responsibility for configuring their prerequisites.
Settings: Settings that vary for each environment, such as the connection to external services and their credentials, must be separated from the code, treated as environment variables, defined independently of the language or operating system in use.
Support services: services that the application consumes for its normal operation, such as databases, queue or messaging systems, email sending services, among others, must be treated as connected resources, that is, they must have low coupling. For example, it must be possible to change the pointer easily, without having to change code and make a new publication.
Build, release, run: Transforming a codebase into a deployment should be done in a sequence of clearly separated stages: build , release (when the build is combined with the configurations), run (when the app process is started for a specific release).
Processes: Applications must run as one or more processes, and these must be stateless and share-nothing , that is, they must not persist data beyond the current transaction, and they must not depend on the state of other processes to carry out their transaction.
A 12-step checklist
The best-known reference for good practices for service development is the so-called 12-Factor . Created by Adam Wiggins, co-founder of Heroku , it is presented as “a methodology for building software as a service”, having been created based on the experience gained in the company itself, where more than 9 million services are deployed .
In fact, the 12-factor works as a checklist of good practices, covering topics such as configuration management, internal architecture, DevOps and service lifecycle management.
The 12 factors are:
Codebase: The application code must be in a version control linkedin data system (such as Git, for example). The codebase must be capable of generating multiple deployments (for testing, staging, and production environments, etc.). Different codebases must not have duplicate code; duplicates must be treated as new applications, included through a dependency management system.
Dependencies: All dependencies must be declared accurately. An application should never assume that the libraries or tools it depends on are already present; it should always take responsibility for configuring their prerequisites.
Settings: Settings that vary for each environment, such as the connection to external services and their credentials, must be separated from the code, treated as environment variables, defined independently of the language or operating system in use.
Support services: services that the application consumes for its normal operation, such as databases, queue or messaging systems, email sending services, among others, must be treated as connected resources, that is, they must have low coupling. For example, it must be possible to change the pointer easily, without having to change code and make a new publication.
Build, release, run: Transforming a codebase into a deployment should be done in a sequence of clearly separated stages: build , release (when the build is combined with the configurations), run (when the app process is started for a specific release).
Processes: Applications must run as one or more processes, and these must be stateless and share-nothing , that is, they must not persist data beyond the current transaction, and they must not depend on the state of other processes to carry out their transaction.