A “12 factor app in microservices” is any software program which can be broken down into individual, independent components. These components are all able to run on different servers or computers without any problems or downtime. This type of program is seen as more resilient, scalable, and fault-tolerant when compared to other programs that are not 12 factor apps in microservices. This type of processing also ensures that the integrity of your data will always be preserved because it operates outside any one particular locale.
Factors to include in a 12 factor app
The codebase is the source code for all functions and apps that comprise a 12 factor app in microservices. Therefore, this piece of the system is able to be manipulated by multiple users without being viewed as being shared among others. The original codebase can be changed by just anyone, but this is easily identifiable to the others who have access to it because it won’t include any of their changes or input.
The app should have separate and declared dependencies. Using a package manager or dependency injection can help to ease the burden of creating dependencies. Dependencies are defined in the app’s code, which makes it easy for others to know what they are so that they can be eliminated or updated if needed.
The app can have all its config values in a separate file so that it is not included in the codebase itself. This also helps with making it easy for others to know where configuration values are, even when updating them on their own. The config files should always be checked into version control, too, so that people will know exactly what values are being used throughout the system.
4. Backing services
The app’s dependence on a single backing service should be eliminated. In other words, don’t depend on a single instance of a database or storage service. This type of setup can cause problems if one server goes down because it will present downtime for the entire service. If you have two out of three database servers going down, then just use the remaining one and accept some amount of downtime for this event rather than having an app that doesn’t work at all.
5. Build, release, run
The app should be able to be built from scratch so that no dependencies are left behind as part of the deployment process. A 12 factor app in microservices should be able to be run with nothing more than a Git checkout. If you can run it without any system tools, then you are on the right path.
The app should have its own processes which are completely separate from any other process that is running on the server. Each of these processes will handle their own business logic, resource usage, and storage requirements. Your app will work better when it does not make assumptions about what is going on around it because this is how many apps fail when they are deployed to servers with multiple instances of operating systems or applications running on them.
7. Port Binding
The app can be bound to a port to avoid any conflicts with other programs running on the same computer. This type of approach means that all requests for your application will go through its own TCP/UDP port. Some operating systems, such as Windows, make it easy to find a specific port number allocated for your application because this number is part of the process ID for any process running on that machine.
The app should have its own, unique process that can run concurrently with other processes. It is up to the developers whether they use a single CPU core, thread pool, or custom system to achieve this type of functionality within the app.
The app should be able to move from one environment to another without being effected by any type of change in the environment it is running in. This means that the app isn’t dependent on any particular hardware, operating system, etc., and can just run in a completely different environment with no issues at all.
10. Dev/prod parity
The app should have its own development process which is completely separate from its production process. The development process needs to include all of the same monitoring, instrumentation, and debugging that will be included when it’s put into production. Dev/prod parity allows for easier deployments of apps because there are no surprises when they are actually put into use by customers or coworkers.
The app should have its own log files so that it can be monitored by its own team, but not others. This means the app can have the logs removed so that they are not publicly available on any server or system. It is important to note here that this doesn’t mean the logs are deleted, just that they are moved into a place where only the app team will see them.
12. Admin Processes
The app should have its own set of administrative processes which are used solely for managing the app. This includes inventory tools, backups, instrumentation, performance monitoring, etc.
What are the challenges of a 12 factor app?
There are a few challenges that come with a 12 factor app in microservices.
– Communication and coordination
One, is that you will be required to work within multiple development teams, all of which will need to communicate with each other. This means that your code needs to be flexible enough to be used by many different developers at once, so the code is also subject to change.
– Development time
Another challenge is ensuring that each individual component can operate within an optimal amount of time.
– Testing speed
Also, another challenge comes from the speed at which teams are able to write and test new components. If they are able to do this quickly, then your metrics will need to be monitored closely for any changes in performance over time.
It is important to note that all of these factors are not needed for every application. If your app is completely internal to your organization, then you can get away with having some or even none of these factors in place. It’s only when the app is exposed to the outside world that you begin needing some of these elements. This does not mean that your app must be exposed to the outside world in order to be considered a 12 factor app.
Read on what are microservices, why should you care?