Transcript

Use with ChatGPT / Claude Auto-scroll A

1. What Is the Twelve-Factor App

Introduces the 12 factor app as a contract between an application and its deployment platform, defines the scope of the video, and explains the history of how Heroku co-founder Adam Wiggins wrote the document in 2011.

0:00 - 1:17
So far in this playlist, I have taken a lot of decisions and prescribed a lot of ways of how a back end or an application should be built and I have never really stopped to defend them.For example, why configuration goes in environment variables, why the server binds a port, why logs go to the standard output, why processes have to be stateless, and why when you kill a process, nothing should be lost.A lot of these decisions in a lot of videos.So today now that we are approaching the end of the playlist I want to show where a lot of those decisions are coming from and a oneline answer to that is it's called a 12 factor app.It's basically 12 rules that was written in sometime 2011 by the people who are running one of the first cloud platforms which is Herio.To summarize it in two sentences, a 12 factor app is a contract between your application, your back end and the platform that runs your application.
It states what must be true about your app so that any machine, any platform and any new teammate of yours can run it, they can scale it and they can update it without any kind of surprises.Every platform that you will ever deploy to today, they assume they expect that you follow all these rules directly or indirectly.For example, it all started with Hioku.They started expecting assuming it first.Why?Because they wrote it.They wrote the original 12 factor app document.Then Docker also assumes it.Kubernetes also assumes it.Render, Railway, Fly, Cloudr Run, AppRunner, Versel, Netlifi, does not matter what cloud platform that you're using today.They all in some parts they assume that you follow these rules and some of these rules have become so common as a standard practice of our development that people don't really refer to the original source like Telactor app
when they are following these practices.They just know that these are the rules that you are supposed to follow.This is part of your development which is a good thing.It's a good thing because it has become such a standard that you don't need to remember that it is a rule.It's just how things work.So for example, when a platform says that we inject configuration through the environment or when they say write your logs to the standard output so that we can collect them.All of these things that is coming from these spread rules or the source document.If you follow these rules, these 12 factors, then every one of those platforms, operating in every one of those platforms becomes very easy because instead of fighting with them for all these standards, you are already sticking to thestandards which they expect in the first place.
This video is uh partly a history lesson but it is also a map of the contract that you are already following but we are just giving it a name giving it a concrete presence so that you have abetter mental model of thinking about the whole architecture.So before we start we need to define the scope as usual.This document this 12 factors app document.This is about apps that run as a service for example web apps, APIs or anything deployed somewhere that can be reached over a network by the internet and it can be in any language.It can use any database or any kind of queue.It does not matter.Things like desktop software or mobile apps, those are out of scope for this video because this is primarily about back end which are primarily services.The list of the 12 factors, they are mostly about the interface between the application and the platform it is running on, they are not a list of uh everything that is good in your software.
For example, principles like dry which means do not repeat yourself or kiss which means keep it stupid and simple something like that they are not the factors.Similarly, we will not make this video about uh Kubernetes operations or micros service architecture.None of that.We will stay focused on the topic itself which is understanding 12 factors themselves without going too deep into any of the branches of that.Now coming back to who exactly wrote this document and why you should take them seriously.This document was written in 2011 when Hioku, one of the first and most famous cloud deployment platform as a service platforms, they were around 3 years old at that point.Uh by the way, platform as a service means that you give the platform your code and they take care of the rest which means taking that code and building that code, preparing your environment, your configuration, your connections to
your database, your networking needs, everything until your application is live on the internet.It is reachable by anyone who types the domain name.That is what a platform as a service does for you.And since they were in that business, in the cloud platform business, they were in a very good situation or in a very good place to notice all these patterns and document them so that the rest of the industrycan also benefit from the same patterns.The Hioku team, they probably have watched hundreds and thousands of apps and code bases getting deployed, scaled, breaking in production and getting corrupted across a lot of languages and a lot of frameworks.That is exactly the kind of visibility that they got which enabled them to write such a impactful standard such an impactful document that we are still talking about after all these years.So Adam Wiggins one of the Hioku's co-founders he wrote all those patterns as 12 factors and published them at 12factor.net in 2011.

2. Deployment in 2011 and Software Erosion

Describes how painful manual server deployments were in 2011, the snowflake server problem, and software erosion. Also covers the 2024 open-sourcing of the document and the plan for walking through each factor with its modern rewrite.

Now to understand why this document needs to exist or needed to exist at that time, you have to remember what deploying an application, deploying any kind of service was like at that time.Some of you were probably around that time.Most of us including me, we were not developers at that time.So we can only read from people's experiences.So this is what it looked like.You anyone who wanted to deploy their app over the internet, this is what they had to go through.They had to rent a server or even worse, they had a physical machine in their offices because even though AWS existed back then, it was not as common as of a standard that it is today.Cloud was not as of a standard.people still operated from their local servers.Servers that were actually physically present in their premises.So they either rented a server through some service whatever was popular during that time which did not have all these features that we have today or they had a physical machine somewhere in their premises.
Then someone would install the operating system by hand something like Ubuntu or whatever Linux operating system they wanted to host their server in.Then they would have to install the language runtime by hand because whatever language they have written their service in whether it is Java or Go or Python the operating system would have to have that runtime to run theservice.Then the database has to be installed and some other supporting libraries.Then the application itself would have to be copied into the machine sometimes using FTP which is called file transfer protocol which is very famous for any kind of development work during that time.Then people would edit some kind of config file on the server itself manually using a protocol like SSH.Every server that was built like this, people would call these as snowflake.Why?Because all of them were unique.
They were handbuilt and they were impossible to reproduce because all of that was done manually step by step by some engineer.So if some other engineer tries to reproduce the same steps even through a documented manual there is a very high chance that something will go wrong or something will go different in any of those steps.If you are trying to execute all those operations by hand and even after doing all this if the machine dies for some reason then you'll have to again start from scratch either from memory or if you have documentedit then the manual.Similarly, if someone hired a new developer into their team, then just getting started with the codebase with the running app with an instance of the app running on their laptop, it used to take days and even after thatthe instance that was running in their laptop, that did not match what was running in production.
And that is where this famous phrase called it works on my machine got popular and people used to schedule their time for any kind of deployment work by freezing any other work that any of the team members weredoing.And this document the 12 actors document it has a name for like this for an app that is built and operated like this.It is called software erosion.Erosion basically means that the app eventually and slowly it stops working even though no one else changed any code.Why?For example, imagine scenarios like uh the operating system gets patched with a new release after you update your Linux distribution whatever you are using.Or maybe the same server is hosting two different apps and the other app updated a library which started affecting or breaking the second app.Or if the person who installed or maintained all these complex infrastructure, they leave the company and they did not really document every single step or every single change that they did on the app and on the infrastructure which
is very much possible.It is impossible to track down every single change that you're making especially if you're making it manually.So all in all these 12 factors are your defenses so that your software your application your infrastructure is not exposed to erosion.One note before we start with the 12 factors in the whole video is for 13 years this document was frozen.In the footer you can see that uh it says last updated 2017 and that update itself was also very small and while the document was frozen a lot of changes happened in the developer ecosystem a lot of technologieswere introduced and got popular things like containers kubernetes serverless and managed cloud infrastructure everywhere.So in November 2024, Hioku, which today is owned by Salesforce, they open sourced this document.They moved this document into a public repo under a neutral organization and they wrote a governance document and they invited maintainers from other companies including from AWS and Google cloud so that the whole community can revise it and
improve it and bring it to today's standards.This is from Hioku on stage at CubeCon November 2024 announcing the same thing.The 12 factor app is now an open-source project and the community is invited to revise it and that revision is happening right now in public on a branch called next.It still keeps all the 12 names and all the 12 oneline motors, but it rewrites every factor into a numbered list of principles and separating the timeless principles from the 2011 era and the modern principles which is moreapplicable to today's applications.As of today, the day I'm recording this, the live site still shows the classic 2011 text and the rewrite is still unmerged and still a working draft.So that's why for every factor, I will talk about the original 2011 text first because that's where it all started and then we will also see what the community's rewrite is changing about it.
what is more relevant in the modern times so that we get the history and also the modernized version of the same principles.So what is the plan for this whole video?We walk through all the factors, all the 12 factors one by one and for each one we'll see what it says in plain words, what exact problem that it was trying to fix and where have we already seenthis pattern in this playlist.And after that what exactly the rewrite changes in that.We will also see what are the factors that aged well that are still relevant and what aged badly which means that it did it does not apply to a lot of things today.

3. Factor 1: One Codebase, Many Deploys

Explains that one codebase tracked in revision control maps to many deploys, with config being the only difference between environments. Discusses the monorepo debate and the copy-paste anti-pattern.

So with that the factor one which is one code base tracked in revision control and many deploys.There are two parts here.First one codebase tracked in revision control which is the one that is very obvious today because we cannot imagine our development workflow without a tool like Git and uh GitHub, Bitbucket, GitLab, whatever that you're using as a service.But Git is the tool that pretty much all of us depend on every single day, every single hour of every single day.But it was important to write it down.it was important to document it in 2011.So you have to think about the situation about the scenarios during those times because a lot of the production servers that were written during those times they still were just a folder on someone's computer or a zip filewith a name like final v2 really final zip.
So it was important to make this a rule so that people would treat it as a standard and not keep their code in a folder and zip their teammates through email.The second one is the not so obvious idea which is called many deploys.A deploy that is the terminology here basically means one running instance of your application of your service.Production is a deploy, staging is a deploy and similarly these days we also have some advanced workflows like a separate exclusive deploy per APR but primarily speaking a lot of teams still follow production and staging but the ideais same code base different deploys and what exactly makes them different it's not the code it's never the code even though there are scenarios where the production is running an older commit as compared to the staging which isalready running the uh latest version of the code.
That can happen.But the point here is all the commits are in the same repository.They are not separate code bases.But something here has to differ between production and staging.It cannot be code.So what exactly is it that has to be different?Because in your production it talks to a real database while in local development we start local containers of uh docker posgress so that our back end can talk to that and the code that we are running in ourlocal and the code that is running in production they are still the same.So the thing that makes them different is config.That's the part that makes every deploy different.So code is one thing which is shared by every single deploy but config is the one that is unique to each deploy.Let's say your applications repository is at commit number 100 and let's say your production instance that is currently live on internet that is running the commit 97 because we deployed let's say last Friday which was 3 days ago.
Similarly, the staging instance which is only accessible to your internal team that is running the commit number 99.Why?Because we are still testing the code that is going to get released tomorrow.But your laptop runs the commit 100 plus the two commits that you have not pushed yet.So four different deploys but one codebase.Now what happens on the deployment day?staging moves to 100 then production moves to 100.Nothing about the deploys themselves changed except which commit of the same repository each one is running at one point.So the takeaway here is if you cannot describe your environment as a commit as the same codebase at these commits then the pattern is going wrong somewhere and you are going to face issues in the future.The factor also talks about two boundaries which are if your system is multiple code bases that is not considered an application that is a distributed system made of different applications and each one of those applications should follow the
12 factors on their own.Similarly, if two applications share the same code, not in the sense from the same source by code sharing but by copy paste, then that is also a violation because shared code should get refactored into some kind of libraryand it should be used through a dependency manager which is a point from factor 2 but worth a mention here.So where does it stand in 2026?The one place where it gets argued a lot is monor repos which is a very popular architecture these days because many companies they keep a lot of apps in one repositories and a lot of people interpret this factoras monor repos being an antiattern which I do not agree because if you look at the definition again which says a codebase is a repo a repository or any set of repositories which shares a root commit and the
way to test it is one to one between the codebase and the app.So as far as this factor is concerned about if a monorreo builds five different apps then it is the same as five different code bases which happen to live in the same repository but each one of them havetheir own 12 factors.What it actually restricts, what it actually considers as a bad pattern is same app existing in two places not the other way around which means the copypaste sharing of code that is the antipattern here.

4. Factor 2: Declare and Isolate Dependencies

Covers manifest files like package.json and go.mod, lock files for pinning exact versions, and isolation via virtual environments. Shows how Docker containers represent the peak of declaration and isolation.

Then comes factor two explicitly declare and isolate dependencies.Two important words there declare and isolate.Declaration means that somewhere in your repository there is a file which lists completely and accurately every library that your app depends on that your app needs to run in your environment.And we already know these files not from a rule but by how we work.So if you work in NodeJS then the file is package.json.If you work with Go, the file is go.mod.If you work with Python, then it can be something like requirements.txt or pi project depending on which tool you are using.If you are in Ruby, then it can be a gem file.What problem does it solve?If you don't have this file which we also call as a manifest file then let's say talking about your local environment if you get a new laptop or a new teammate joins your team and if they want to
set up your whole application if they want to run it then they have to dig through the whole codebase they have to read every single import statement and they have to guess which versions it should run and theversions themselves have clashings between them, a lot of issues, it can easily become a 2 to 3 days of constant setup operation.But if you have this file, if you have this manifest file which lists all the dependencies with the right versions, the pinned versions, then setting up the whole machine to start your instance is just one command which automaticallypulls, downloads all the packages, installs it and gets your app running.In the 2011 version, it mentions the popular manifest files of those times which is gem file because Ruby on Rails was very popular during that time.So a gem file with bundle installed and these days the idea has become even stronger because we not only have these manifest files which are package.json, god etc.
We also have log files to exactly pin the versions not just have a range of versions.So we have package log.json go sum file and so on.Why?Because the manifest file something like package.json or go domod it it does not really it it does not say precisely which version of the package it wants.It says it roughly needs a list of these packages.But if you have a log file then it pins the exact version of every library and every libraries libraries which means the libraries your libraries also depend on to run themselves.So even if you run your application which has a manifest file and a log file after months or years it is still going to pull and run the same versions.Now comes the second part of that phrase which is isolation.Let's say we are talking about Python here and we have a popular library called requests in Python for making HTTP related operations.
Your manifest says your requirement.xt says that it needs the requests library version two but your app runs against the systems installed Python where some other tool has already installed requests version one.And when you try to import it, the import statement finds the systems copy first.So even though you had the manifest, you still did not achieve your expected result.Your app still ran something else than what you expected.So basically declaration and isolation themselves still break.If you just declare but but do not isolate, you cannot expect it to work everywhere.Similarly, if you just isolate but there is no declaration, then you are going to spend your days and weeks trying to reproduce the same version which you might or might not achieve.Declaration is something that is still very natural because it is part of our workflow.Without it, we cannot start working or function in our day-to-day.
But isolation is something that is very easy to forget which states that nothing should leak from the machine because declaring just your dependencies is pretty useless if your application ignores it and just uses whatever is installed and availablein your system.For example, in the 2011 text, they mentioned for Ruby it should be bundle exec and for Python it should be virtual env so that you achieve isolation and they only see your declared dependencies.Similarly, they also talk about vendoring tools, which means let's say you have an app that resizes images, a backend app or service, and it uses shell commands to use whatever image magic binary version that your system has, whichis a very popular binary to resize images.And on your laptop, which is let's say a Mac OS, and you used Homebrew to install your packages.So, Homebrew installed image magic version 7 where the main binary is called magic.
But on the Ubuntu server, a installed image magic version 6 where the binary is called convert which has a different set of defaults.So the same set of code, the same snippet of code, it uses shell command on both the machines but they both do different operations because they are two separate programs since version six and version 7 since they aremajor versions they will have a lot of breaking changes a lot of different behaviors.Now comes the modern rewriting which is one of the biggest turn of behavior when it comes to the tech ecosystem which is containers.So containers completely change the power and scope of this factor because if you take a docker image then it not just freezes your libraries but it also freezes your operating system and your system tools and the runtime itself.So that is the peak of declaration and isolation that you can ever achieve.
This is why people say that docker practically solved this factor.

5. Factor 3: Store Config in the Environment

Explains what counts as config, the open-source test for detecting embedded credentials, and why environment variables are the standard mechanism. Also covers the controversy around storing secrets in environment variables and the case for secret managers.

Now comes factor three which says that store config in the environment.One of the most quoted and most argued topic in the ecosystem.But first what exactly counts as config?Config is basically everything that is likely which we have already discussed when we were talking about deploys.So config is something which is likely to be different between different deploys.For example, if we talk about the database connection, the database URL, then when it is running in your laptop, it is connected to your local host to a database which is running in a container inside docker.But in production, it is connected to let's say Amazon RDS through some kind of internal connection VPC and all those stuff.But the point is the URL itself is different in both these environments.Similarly, if you use a email provider, then in development, you might use something like a sandbox API so that the emails go from some kind of test email.
If we look at object storage, if you are using S3, then in local you might use a locally running menu instance, while in production, you'd use an actual AWS S3 instance.For radius, same in local you'd use a container.in production an actual radius instance.So in all of this the only thing that is changing is the config.Now comes the question why keep these parts outside of your code and how do you actually decide whether these parts should be part of your codebase should be part of your logic or it should be in your config.And if you go through the document, the factors document, they give a very interesting test, very useful test which says, can you open source your codebase, your production codebase, your internal codebase of your company right now at thismoment without compromising a single credential.It's not asking will you do it.
It's it's asking can you do it given a challenge even for a minute let's say.So you can take that question and you can apply it on your codebase and see what is the answer.If the answer is no then some kind of config is sitting inside your code which it should not be.Okay.Now that part is decided that config should live outside the code.But where exactly outside and the factor says that environment variables and it gives a few reasons.First, because environment variables are very easy to change between different deploys without you touching a file.Second, they cannot be checked into the repository code itself by accident, which is exactly how credentials get leaked every single day.And on top of that, environment variables are a standard that is part of the operating system itself.they are not something which is affected by any programming language or any framework.
So the same mechanism that you have for environment variables, it will work for a Go program, a NodeJS program or a Rust program, a Python program or even a very simple bash script as compared to the alternatives thatwere existing in those times.For example, Java had these things called properties files.Ruby on Rails had config/database.yiml.Every framework they had their own format and pretty much all of them at some point or another they used to get committed into the source control and credentials used to get leaked.If we look at our own codebase, one of the code bases that we wrote for one of the videos in this channel which is called tasker which is a task management app.If you look inside the config package, it declares the whole configuration the whole configuration as one gostruct the server block the database block authentication radius the email integration AWS observability chron a block for each one of them.
So in total there are like 38 config values and all of them are loaded from the environment variable and we also have a prefix called tasker.Tasker server port, tasker database host and so on.And in the G tree also it will show that the configs themselves they got changed a lot of times while the application was getting developed when we were adding new integrations or new timeouts, new hosts.But the code that reads all these values that barely changed.That is exactly what the factor expects which is config should keep changing across different deployments across time but the code should not things which have two different rates of change they should not live in one place.In the 2011 version of the document it warns that you should not group configs into named environments.For example, config/ environment/staging.rb then production.rb and so on for development test staging production etc.
Why?Because it does not scale when you keep adding more and more environments.For example, let's say someone needs a new deployment that is almost like staging but they need to point at a different database.let's say for a PR branch and because of that every time someone adds a new deployment a new environment you keep adding more and more code as compared to what the factor says that the config should be individualand granular and each one should be an independent environment variable and it should never correlate with the mode names and you should always compose a new deployment by setting the values not by choosing what mode it is turningin.And in the rewrite also in the modern version also it says that environment variables are granular controls and they should never be grouped together as environments.Now comes the controversial part here for environment variables which is environment variables are a very good use case or a very good medium when we are talking about something like a database host name.
But what about the password?are environment variables still a very good candidate for a um high security credential like a database password.So in 2017 Dio Monica who used to run security stuff at Docker wrote a very famous article in that it says that you should not use environment variables for password.Why?Because the environment leaks eventually.For example, if your app starts new child processes inside that, then each one of them will inherit the whole environment.So if you trigger some kind of shell command, then all your secrets will go there will get leaked there.In tools like crash reporters or uh debug pages, they have this pattern where they print the whole environment since it is a debugging environment.On top of that, if you are using Linux, the environment of a particular process is completely readable depending uh the person has the right access at proc and there are various tools that also log it.
So the right pattern here when it comes to secure credentials is there should be a separate secret manager service and your app reads all those sensitive credentials from the secret manager when it is starting up when it isbooting and it keeps all of that in memory not in a separate place in the operating system.So where do we stand here?The core advice of the factor which is the config should strictly be separated from the code that itself is non-negotiable.It was non-negotiable then and it is still non-negotiable and the prescribed mechanism which is environment variables that is the right default especially for everything that is not a secret that is not a high security credential but if youare dealing with secrets if you're dealing with credentials that should not be the default all all the time.Of course, if you are working uh solo or if you are working in a very small team, then uh any kind of environment variables that are injected by your uh platform's secret feature that can be fine.
I mean that is obviously better than keeping the credentials committed in the repository.But as you grow the product, as you grow your company, as more people join your company, the no-brainer path is always a secret manager for all your credentials.Something like vault or if you are using AWS, something like parameter store.During the starting phase of your application, you will fetch all those credentials and you will store it in memory and periodically you will rotate those credentials and you will also audit them in all those best practices.

6. Factor 4: Backing Services as Attached Resources

Defines backing services and resource handles, arguing that local and managed services should be interchangeable via URL plus credentials without code changes. Notes how this once-radical idea became the modern standard.

When it comes to security factor four, treat backing services as attached resources.What is a backing service?Backing service is anything that your application consumes over the network for doing any kind of operation.If we look at our day-to-day tech stack, then our database something like a posgress service that is a backing service.Similarly, your radius instance or your uh Q your background service or your SMTP service that sends your emails or your object storage service something like S3 which you use to store your files or any third party API likea payment provider.So if your app talks to it over the network through some protocol then it is called a backing service.Now what is the rule?Your codebase should not make any distinction between a backing service that you run and a backing service that is run by someone else some other company to your app.
All of them should be treated as an attached resource which is reachable through a resource handle.What is a resource handle?A resource handle is uh basically the URL plus the credentials.And in the previous factor we have already discussed that this thing should live in your config not in your code.So simply speaking what this rule is saying that it does not matter whether you are running your database inside a container your radius instance inside your local container or AWS your posgress inside a local container or AWS RDS.You should not give any special treatment in your code to handle that.The code should be the same.Does not matter what service that you're using and which environment that you're using.The only thing that should change is the resource handle itself.Resource handle means the URL to connect to that resource plus whatever credentials that come with it.
And to test this pattern inside the codebase in the 2011 text of the 12 factors document they give you this test where they say that which I already mentioned you should be able to switch your local posgress URLby any of the managed service let's say something like neon or planet scale or superbase anything or even Amazon RDS without changing a single line of code.The only thing that should change is the resource handle in your config, not your code.If that is true, then your application sticks to this factor.So what exactly does this resource handle that we keep talking about looks like?If we take a posgress resource handle, this is what it looks like which has five parts.First the scheme which says posgris to imply that it speaks the posgress wire protocol.Then comes the credentials user and password.Then the host then the port which the default port is 5432.
Then comes the database name.So this one string it has everything our application needs to attach this resource or to talk to this resource to communicate with this resource.In 2011, this factor was considered very eccentric when these Heroku people said that the database is somebody else's computer and your app just communicates to it using a URL which is true even during those times but that wasnot the standard.The standard was still that for most people the server and the database both of them were running in the same machine.So this idea that your database lives somewhere else than your server this was not something people could relate to.Fast forward to a decade and a half.This is one of the most common patterns that we see in every single codebase.In fact, your server and database running in the same server instance is considered a antiattern when it comes to scaling.
Does not matter what database that you use whether RDS or neon planet scale or even other services like for radius also we use managed red instance.For object storage we use S3 for emails instead of custom SMTP service used managed services like resend.So this factor aged very well.In fact this was kind of a prediction compared to how the world was running during those times.

7. Factor 5: Separate Build, Release, and Run

Walks through the CI/CD pipeline stages of build, release, and run, explaining how immutable builds enable instant rollbacks and prevent hot-patching production servers. Mentions the rewrite making immutability mandatory.

Then factor five strictly separate build and run stages.To understand this we have to talk a little bit about CI/CD pipelines.What typically happens in a pipeline?Roughly speaking there is stage one which is called build.In this stage, the pipeline, the runner, the program that is trying to build your application, trying to deploy your application, it takes your code by doing some kind of gitpool or some transfer operation at a particular commit sincethat is how deployments work these days.It does not happen through FTP or file transfer through SSH or anything.Everything happens through source control which means commits are the primary drivers of any deployment or build.So for a specific commit we pull the code for that commit.We fetch all the dependencies from the manifest file which we mentioned in factor 2.Then comes the compiling phase if it is a compiled language.
then we produce one executable bundle or executable binary in the document if you see this binary this bundle is called a build.So if it is a compiled language like uh something like go then it is a single binary but if it is a interpreted language something like a nodejs app then it is the whole app plus its node moduleswhich it needs to run.So in the container world in the docker world this is an image and the key property here is a build should only contain the code and its dependencies.It should not contain the configuration the config that we talked about.Then comes stage two which is release which takes the build the binary the bundle which got produced in the previous stage in stage one.Then it combines that with the deployments config depending on which deployment it is whether it is staging or production or test or a particular PR preview whatever deployment it is for that deployment's config and the result that we
get from these two is what we call a release.So an exact build plus the exact config that is ready to run.So a build combined with our production config is our production release.Same build combined with our staging config is our staging release.Then the last stage which is the run phase.What does it do?It takes the previous result which is the build the binary plus the config and it starts it launches a process from that release.That's a whole rough mapping of what a CI/CD pipeline does.But why exactly does this factor exist?Why are we being so strict about uh separating these stages?There are primarily two benefits.The first, since a release is just a build plus a different config, the builds themselves are immutable, which means if you want to do any kind of roll backs, then that costs you nothing and it is instant.
The document also says that the releases they should be an appendon ledger, which means they should not be modified, they should not be updated, they should only get appended every time.And every release should have an ID, a timestamp or some kind of incrementing number and a release should not be changed once it is created.If you want to imagine a scenario, let's say in the afternoon for your codebase, you build at commit 97 with the current config and you push a release which is release number 100.Then after 2 hours someone rotates the database password for some reason.So the config changed then that becomes a new release which is 101 which has the same build for the code itself but the config is new.Similarly, after 2 hours again you deploy some new code, you make some new changes or you merge some new PRs.
Then you push release number 102 which changes your build itself not the config.But once you push that release which is 102, you see in your dashboard that there are a lot of 405 errors in your dashboard and some of your users are complaining in your Slack channel.So instead of trying to debug in your production what exactly is going wrong while your customers are screaming in your Slack channel, what you do, you rerun the release for 101.The release which was working fine before you pushed your new code.And since we said that builds themselves are immutable, that release only takes a few seconds to go live.Once your production is back to stable, you take the bad build, the bad release and you try to debug by taking your own time.Does not matter how long it takes.And the only thing that made this possible, this whole workflow of fixing a production instant in just a few seconds is because of the property of an ideal build which is being immutable.
The release 101 still means the same thing.It meant when it was released 2 hours before the meaning of that release, the effect, the consequences of that release never changes because it is immutable.The same build and the same config.Every platform that we knows these days which uses the same patterns whether it is Heroku releases, Docker image tags or a Kubernetes rollout all of them.Now the second benefit if code only enters the pipeline at the build stage it means that no one even if they try can edit the code on production server because there is no path from the running machine backinto the build as compared to the snowflake server world that we're talking about in the start of this video.logging into the server using SSH and doing a hot patch and reloading your server.That practice was very common and that is exactly what used to cause the production environment and the code repository itself having two different states eventually.
So strict separation of the builds makes that situation impossible to happen.In the modern rewrite, it only adds one change to this factor to the original 2011 factor which is immutable which was implied in the 2011 version but now it is part of the principle.It is mandatory.So each release should be a unique and immutable snapshot.

8. Factor 6: Stateless Processes

Explains why processes should share nothing and persist state only in backing services, using sticky sessions as the classic violation. Discusses the websocket exception and the thumb rule for detecting misplaced state.

Factor six execute the app as one or more stateless processes.Which means your app should run as different different processes who do not remember anything between two different requests which is the statelessness property which we have been discussing in pretty much every other video since the start of thisplaylist.The statelessness property of our back end of our service is something that helps us scale.In the document it says share nothing between these two process which means do not share memory or disk also.Whatever that needs to get persisted, it should go in a stateful backing service which from the factor 4 we have already discussed that it should be an attached resource and you should always treat your service with the expectationthat any request at any point can be served by any of the processes and any of the process can disappear at any moment.
they can be destroyed at any moment.So is the process allowed to hold anything?Are there any exceptions?So the document says memory and local disk are fine as a cache for one transaction.Similarly, if you want to download a file, process it and you want to write the result to the database, then the temp file, temporary file that you used to store it while you are processing the file, that isfine.Why?Because after that transaction, nothing else expects that to be there.It is just one time.And since it is in a temporary directory that is anyway going to disappear at any moment in any situation.If you expect that a future request or a future process is going to depend on the presence of the file then that is where it becomes problematic otherwise it's fine.The document also mentions a very famous issue which is called sticky sessions.
Sticky session basically means that the load balancer that is in front of your API service, it remembers which instance a user should land on every time based on their past activity and it makes sure that the user isrepeatedly routed to the same instance every time so that whatever in process state that you are depending on it keeps working.It does not break.So what kind of scenarios?Let's say your application stores the logged in user session in process memory.So it works perfectly in one instance.Then if you have watched the scaling video after that let's say you scale your instance to three different instances to handle your load and you place all of them behind a load balancer and a user logs in toinstance number one.In the next request, they get routed to instance number two.And since instance number two has never heard of this user, since you are storing the session in process memory, it throws some kind of error and the user is instantly logged out randomly.
So the the loophole, the workaround people came up with to get around of this issue is making the load balancer remember which user goes to which instance based on their past requests.and they make sure they get routed to that every time.That is what we call a sticky session and this document it as you can expect is pretty against it.It states that sticky session a violation and they should never be used no matter what the situation is.Why?Because the property of being sticky, the property of sticking to one instance at the load balancer level, it completely defeats the whole purpose of having three instances in the first place.Why?If you kill one instance or one of the instances get killed because of some traffic load or because of some corruption then all the users instantly get logged out or in the next response and if to handle your
traffic load you add another instance then that does not get any existing users.People have to start over again.They have to start from login flow again.So what is the fix for this?Session data is a type of state and we already know every state goes into a backing service which means you should put your session behind something like radius or posgress or your database whatever makes you comfortable and basedon your latency requirements.Now if you remember the real time video where we talked about the process having state when we discussed websockets.Now a web socket is a state which stays in the process memories which exactly breaks this property of the statelessness and this factor that we are currently discussing and in that video we discussed that the instance that isholding the socket in that process memory that is the only instance in the world that the user who is connected through websocket can talk to and to get around that problem what we did we made use of a
publish and subscribe system so that after every event we publish it and any other instance that the user is connected to they can subscribe to it and register to the changes.So where does that land us?If we are talking about realtime systems if we are talking about websockets then the statelessness property is kind of a violation there.So in those situations in my opinion the factor this factor that we are discussing about of being stateless this is a default you apply it everywhere but you are allowed to break it when the feature that we aretalking about in this case real time or websockets that feature itself is the state then I guess we are allowed to break it.So what is the thumb rule here?If you cannot kill any process or any instance at any moment without a user losing their data, then you have a state where it does not belong.
That is the thumb rule for this factor.

9. Midpoint Recap and Factor 7: Port Binding

Recaps the first six factors and the capabilities gained so far, then covers factor seven on self-contained apps that export services by binding to a port. Discusses how serverless architecture prompted a rewrite of this factor.

Okay.So far, where do we stand?The 12 factor app is a contract between your application and the platform that runs it.And what are the things we have learned so far?What are the capabilities that we have achieved so far?Your code stays in one repository.All its dependencies, all its needs need to be declared beforehand and they need to be isolated.All the differences should live in the environment.All its neighbors, all its backing services, they should be attached through handles.The way to take it to production is through build, then release, then run.And the ideal way to run it is as a disposable and forgetful process.Six factors.And you can already see the kind of capabilities, the kind of freedom our service has already acquired.Now let's get to the last six.Factor seven.Export services via port binding.Now this will sound way too obvious for you but again we have to look at the historical angle.
In 2011 a lot of people were working on PHP.It was like the React during those times.So the PHP app itself did not run.What actually ran was Apache and the PHP app was a module which was loaded inside Apache.Similarly, a Java app did not run itself.A server called Tomcat used to run and the Java app was a file which is put inside the Tomcats folder.So the pattern was the web server Apache Tomkit these were the famous web servers.They were the programs and our applications they were just a guest inside the running program which meant that the web server's version and its configuration was part of our application's runtime environment which is part of the physical server.So we are back to the erosion area again.That is exactly what this factor is trying to prevent which says your app should be completely self-contained which means it should bring its own HTTP server as a library and how should it bring it from the factor 2's
dependency manifest that we discussed and it should export itself as a service by binding to a port and listening for connections from there.But if you notice how services work these days in 2026, that is the most obvious pattern.Every backend app, every service that we run, it binds itself to a port.Uh for example, in go one of the common ports are 8080.For NodeJS also, we use something like 4,000 or whatever port that is free.Similarly, databases also bind themselves to a default port as a service.So during development you just directly access your service through localhost col 80080 and in production there is usually a routing layer.You have your reverse proxy which forwards the public host name to whatever port your process is binding itself to.And one of the convenient consequences that we achieve with this pattern is if you export your service just by binding it to a port then any app can become a backing service for any other app.
That is exactly how we run and scale our services these days.Our database binds itself to some port.Our cache binds itself to some port.Our emailing service binds itself to some port.everything in local host and the moment we go to production we just replace those URLs those handles with production URLs which binds those services to someone else's port in someone else's computer in the cloud but the same logicthe same pattern throughout so what aged here one of those things is serverless because a lambda function if you're aware of lambda functions in AWS they do not bind themselves to a port the platform The running platform callsa function that you export through code.In 2011, the services binding themselves to a port and running 24/7 that was predicted as a pattern that will persist throughout.But of course that did not happen.
That is one of the patterns, one of the most used patterns.But these days we also have other patterns.we have a completely different category of running service which is called serverless architecture where there is no concept of a longunning portbound server.So that is why in the rewrite of this factor if you see they have kept the port binding thing as a headline but they have also tried to include serverless architecture by mentioning that the app should be self-containedand it should export its service through a declared interface.So that the same principle applies to both a longunning portbound server and also serverless infrastructure which is just an exported function run by the platform.

10. Factor 8: Scale Out via Process Model

Covers treating processes as first-class citizens with separate web, worker, and scheduler process types that scale independently. Explains process formations and why the app itself should never daemonize or manage its own lifecycle.

Now factor eight scale out via the process model.Going back to the 2011 times, how did apps exactly scale?Which means what changes people needed to make on the apps so that they could take more traffic load, more user load at any point if some kind of traffic spike happened.And every runtime, every language had its own scaling mechanism.For example, if you looked at Java, the way it scaled was it was a huge process in itself, the JVM, the Java runtime itself.And during the startup, it used to take a huge block of memory, huge block of RAM.And then it used to multiplex inside itself, inside its own runtime with threads.That's how it used to scale.PHP was the opposite of that.The Apache server on top of which PHP used to run it used to spin small child process on demand.
That's how it used to scale.So the factor says that you should keep the process as a first class citizen and you design your services you design your backends in a way that they can be scaled as different different processes from the scratch insteadof doing it on demand and the whole architecture was inspired from our Unix the Linux operating system course service model or service demons and it prescribes different kinds of process types because different kinds of work should get differenttypes of process.For example, if you are dealing with HTTP requests, then that should be categorized as a web process.Similarly, if we are talking about heavy background jobs, for example, video encoding, image resizing and all these things, then those kinds of jobs should go to worker process.Similarly, if you have a scheduleuler, let's say a email should be sent to every one of your users at 12:00 in the night, which is a scheduleuler logic.
So that should get its own process type.Then once you have different different process for different different kinds of jobs, they should scale independently of each other.How?By running their own copies.Let's say each of your process they take 500 MB of RAM roughly speaking and let's say your product it is a food delivery product then when it is lunch time obviously people will order more as compared to let'ssay sometime around 10:00 or 11:00 so during lunchtime your traffic your user load needs 10 web processes to deal with all the requests but your queue only needs two processes because the the worker jobs that is not asheavy during lunchtime as compared to the number of requests that you're getting.But if those two different kinds of jobs were part of one process, they were part of one big process.Then if you wanted to scale your web process during lunchtime to deal with all these requests which you anyway have to it means that you scale your big process into 10 different copies which means the workers also got
scaled to 10 copies.So your 5GB of web process because each one takes 500 MB they are doing their work they are appropriately scaled but the 5GB extra of the worker process that got scaled because they were part of the web processthey are not really doing any kind of work.So when you split those when you run them as their own process during lunchtime you can scale your web process to 10 while keeping the workers to two.So now instead of 10 GB you're only using 6GB of your server's resources.Then when it's night time usually during the night we run all our cues all our workers.So the number of requests which the web process deals with that gets reduced a little because during night not a lot of people order food.So during that time you keep the web process to let's say five and you scale your workers to 20 because you have a lot of background jobs to run.
So this process of setting the type and count of process let's say the web equals to three and the worker equals two.This whole process, this whole architecture, this whole mechanism is called the process formation which is something that we still use in our vocabulary.If you check any proc file and any Kubernetes deployment spec there we write replicas colon 3 that is what we call as a process formation and we write it in YAML these days.some notes here which is the process model the process they do not really forbid you from using threads if you are inside your process if you're inside one process then you're free to do any kind of multiplexing youwant to you can use threads in the JVM you can use go routines in your go app you can use event loop in your node app but the point is whenever we are talking about scaling the unit of
the scale should be the process not the threads or the go routines or the event loop.Why?Because one machine can only grow so far before you run out of your uh limit of vertical scaling.So if you have this model which says share nothing then that can be scaled across multiple machines without thinking twice.The second note is a 12 factor app.If you're saying our application is 12 factor and it should be then it in itself should never demonize it should never write to a P file.Why?Because the managing the process it since it is the process itself it should not be involved in any kind of process management job or any kind of process life cycle workflow.Managing the process lifetime that is the platform's job.If you are running on top of operating system directly then that is the operating systems job.
If you are running in Kubernetes then it is Kubernetes job or your process manager's job.Your app just runs in the foreground and it does its work and you let the platform do its own job of running you as a process.So what aged here which is the orchestrators these days pretty much the whole internet does not matter what cloud platform that you are using most of them run on top of Kubernetes or Kubernetes or any other kind oforchestrators not necessarily Kubernetes but the logic of orchestrators the mechanism of orchestrators where you just declare a formation and the platform which is running it it maintains it it kills containers it starts containers it restarts it reboots allthose life cycle things.You do not really think about any of these.So it's not that the factor got outdated.It's just it got adopted so deeply so hard that we do not really need to think about this unless of course you are deploying your application directly on top of a operating system using systemd.
In that case it still applies.

11. Factor 9: Fast Startup and Graceful Shutdown

Explains why processes must be disposable given constant deployments and scaling events, covering graceful shutdown lifecycles for web and worker processes, re-entrancy and idempotency, and crash-only design for sudden death scenarios.

Maximize robustness with fast startup and graceful shutdown which demands that your process should be disposable which means they should be built in a way that they can be started or stopped at a moment's notice and nothing bad nothingdestructive should happen in both the cases and in video 19 I think we talked a lot about graceful shutdown the whole life cycle of that so I will move fast here and if you want to cover the depthyou can refer to that video but why are we talking about uh the property of disposability if you look at who actually starts and stops your process these days if you are trying to scale if you're trying tohorizontally scale it means new process get started any moment or if you are doing any kind of deployment then old process they get killed and new process started from the new container image they replace the old ones.
So the platform which is running the orchestrator whatever it is that moves process it deletes it restarts it starts between different machines whenever it likes.So if let's say you deploy your application five times a week across 10 different instances that means 50 times your process are stopped 50 times new ones are started before we even talk about scaling itself just the deploymentpart if you deploy every day that itself is causing 50 times of stopping and starting.So a process dying is not an unnatural thing anymore.It is part of our development life cycle.It is part of our release life cycle.It is not what we consider as an incident anymore.That is the justification for why they should be disposable.Why the killing itself should be fast.Similarly, if the startup is slow, if your program takes a long time to start, then every one of those 100 events that we talked about, they themselves are slow.
So if it takes 60 seconds to boot your process to start your process then when your orchestrator is doing a rolling deploy of let's say 10 instances then it takes 10 minutes and if you have an autoscaler itwill become 1 minute late for any kind of traffic spike.If they only take 2 seconds then it is almost negligible.So the factor also demands that your startup your boot time should only be a few seconds.Similarly when we are talking about shutdown especially graceful shutdown that is where it it is coming from.If your shutdown does not really think about how it is shutting down, if it is not graceful, if it is careless in how it is shutting down, then all the in-flight requests, all the things that is currently doingbefore it shuts down, let's say it is doing some kind of background processing, at that point when the shutdown request comes, it is processing five different HTTP requests.
If it does not finish processing all the requests and if it does not follow a particular life cycle of uh finishing the existing work then stopping to take any new work and then stopping the process and all theseuh things that we discuss in the graceful shutdown part then all the in-flight requests they suddenly get errors when you do any kind of deployment.So as we discussed in the graceful shutdown video whenever we receive the term signal the web process the process which is responsible for processing all the requests it stops accepting new requests and it finishes whatever requests it's alreadyprocessing then it exits.There is a life cycle it has to follow so that the existing users they certainly do not get errors.That's exactly what our go app does on a server shutdown.Similarly, what does a graceful shutdown mean for a worker process.
Naturally, the graceful part is it should be able to return the current job back to the queue.Instead of discarding it, it should return back to the queue because uh it is time to shut down.And when we say that it should be able to return it back to the queue, we are also assuming a property which will make the next run possible which is called a re-entrancy property.What that means is the job which was currently running and because of the shutdown it had to return back to the queue when it leaves the processing it should not leave any dirty state.It should not do any operation which when performed again will cause issues.And how do you get this re-entry property?By either wrapping the whole processing inside a transaction or you can make the operation itself as item potent which means it does not matter how many times you run a particular code snippet it will always produce the same
result.So if by mistake it was processed twice then it is still safe.It does not do any kind of operation twice.It is able to detect that and it is able to skip that.That is what we call as item important.Then we get to the part where it says that it should also be robust against sudden death.Why?Because sig term our application getting the sig term signal from our platform from our runtime from our orchestrator that is a polite case.That is the case that we are prepared to handle where we get around 30 seconds or so so that we can clean up, wrap up whatever that we are doing and we can exit gracefully.That is why it's called graceful exit.We are given a time so that you can wrap up whatever you are doing and then you exit.But what happens when some kind of hardware failure happens?
Let's say your process tries to acquire way too much of a memory and the container gets killed because of the out of memory error.It does not really send a warning in that situation.It just suddenly kills your container and in turn kills your process.So we need to design in a way that any process can be shut down mid instruction any time.So the document also points at uh this particular design which is called a crash only design which says that if you are able to survive crashes then you do not really need a graceful shutdown path at all becausethe crash path itself is the shutdown path.

12. Factor 10: Dev/Prod Parity

Covers the time, personnel, and tools gaps between development and production, and why using different databases like SQLite locally versus Postgres in production causes silent bugs. Discusses the trade-offs of managed services that cannot run locally.

Factor 10 keep development staging and production as similar as possible and uh in the industry we call it as dev/road parity.Parity just means uh sameness how similar they are.In the document it mentions that in between development and production there are three major gaps.First one is the time gap which means that if you are writing some code today then it reaches production maybe on Friday or maybe next week and when we actually do that deployment it's not just your code alot of code gets merged at the same time.So the time gap also brings a lot of changes at once.Then the personal gap which means that the person who writes the code is not always necessarily the same person who deploys the code and same way it's not the person who sees the error who is the operations personand then the tools gap during development we either use something like a MacBook or a Windows machine which is running its own completely different stack whether Docker containers or native installations on Mac OS or Windows as compared to
what we are learning in our production which is a Linux machine which is connected to external servers, external backing services.So the whole architecture is completely different and a lot of times that difference causes a lot of bugs.So the document has this table which shows traditional app versus the 12 factor app.So instead of deploying every week or every 2 weeks, you deploy every few hours.Similarly, instead of different people writing the code and different people deploying the code versus the same people who write the code, they are the ones who deploy the code.So they are the ones who will look at the log lines whenever some error happens.Similarly, instead of having different different environments in local, in production, in staging, you try to keep the environments as same as possible.So if you shrink all the gaps one by one, the process of continuous deployment becomes extremely smooth.
The other gaps are something that are already closed to a lot of extent these days.But the tools gap that is something that still exists.For example, whenever we do uh some kind of database operation during development, there is this practice where people use a lightweight database instead of a full posgress.Let's say something like SQLite.Why and how?Because we have these OMS.If you are in NodeJS, you have OMS like Drizzle, Prisma.If you are in Go, you have OM like Gorm.If you are in Python, you have SQL Alchemy.So all these OMS they enable you this feature that you do not really need to worry about the database unless it's a very specific niche case where you are writing raw SQL queries and using the OM as justa database driver.But most of the times the database gets completely abstracted and you use the OM's own standards, the OM's own practices, its own patterns to write the code, to write the database code and the OM takes care of what
database that you are connecting to behind the scenes.It can be possite, it can be MySQL.So the OMS make it very convenient to use this pattern.But there are of course a lot of issues when you are using SQLite in your development and posgress in your production.For example, in Postgress, the like operator is case sensitive and I like operator is the case insensitive version.But in SQLite like is case insensitive by default for ASKI characters.So if you have implemented some kind of search feature in your local using your SQLite database through your OM and you push that to production that is going to break someday because of the assumption that you have madeand you are not aware of the assumptions or you are not aware of this distinction between the like operators in the both databases.And the dangerous part here is you do not really get any error or any kind of warning or any kind of logs.
It just completely changes the behavior.So the the advice here from the document is the backing services either the database or the cache or the Q whatever backing services that you're using it should be the same in local environment in staging environment and inproduction environment.And especially in these times that is not really an excuse because it just takes one command to start a container in your local and start communicating with it.It is not as much of a hassle as it used to be during 2011 when this factor was created.But in 2026 it is not as clean also.I mean of course we started with Docker and um for some period of time the local environment and the production environment used to be the same because of the whole Docker and Docker Compose ecosystem and us using thesame container in both the environments.
But eventually we started moving to managed services.For example, in production, if you use Dynamob, AWS Dynamob, then there is no way to run Dynamob in your local.Of course, there are emulations uh and similar implementations which try to emulate as many behaviors as possible for Dynamob.For example, the popular platform called local stack.it it enables you to use a lot of AWS services in your local but it is not the same implementation because AWS is Dynamob it is proprietary and whatever you learn about the behavior is from the documented onesso you cannot really replicate the exact technology in your local so that does create some gap and there is no straightforward advice here that you should not go for managed services and you should try to keep the environmentsame in local production.You cannot say that because managed services they do offer a lot of advantages a lot of uh convenience when it comes to scaling your services when it comes to keeping your cost down by not running your own infrastructure.
So the the nuanced takeaway from this is if the benefit of using a managed service with the trade-off of having two distinct environments in your local versus in production.If the benefits are huge, the benefits are large then we should definitely go for that.

13. Logs, One-off Tasks, and Live Demo

Explains treating logs as unbuffered event streams written to standard output with the platform handling routing and storage, and running admin tasks as one-off processes in identical environments. Concludes with a live demo of the task app showing process formations, log streams, and graceful shutdown in action.

Factor 11, treat logs as event streams.One of the first things that come to our mind whenever we are talking about logs because of the way logs were treated historically is a log file.But in this factor the document says that the file was never really the log.The file is just one of the output formats.The log itself is a stream of events which are ordered by time and they will keep flowing.The events will keep flowing.the log events will keep flowing as long as your application runs and there is no beginning to that and there is no end to that.It is directly related to your application running.So once you start treating logs as just a stream instead of uh imagining them as an output format either standard output or a file or some kind of log drain which is an external service if you just think
about them as a stream then you'll get the intuition of this factor which says that your 12 factor app should not get involved in the routing or storing of that stream.You just have to make sure that there is a log stream.It should not worry about log file paths or uh rotating the log files or anything like that which goes outside of the scope of treating logs as a stream.So what it prescribes your application writes every single event every single log event to your standard output which means uh if you are running your application in your terminal whatever output that you see right after running your applicationthat is what we call as standard output.So that's what it proves that always publish your logs, always stream your logs without keeping any kind of buffer.It should be unbuffered to the standard output and the execution environment, the execution uh platform, the orchestrator, whatever platform that you are running on top of.
It is that platform's responsibility to capture that stream and then decide where it goes.Whether it goes to a file or whether it goes to a backing service which is a log drain for further analysis or storing it's that platform's job.And why do we have this division?Why do we have this factor?There are two reasons.First, you do not need to worry about your logging needs while deploying your application because it is not the responsibility of your application anymore.So no code gets changed every time you decide to deploy your application in a different environment.It is the job of your config now.So in 2011 when this factor was prescribed all the standard output log used to go to something like SIS log and these days in production all our standard output logs go to something like Loki or data dog depending
on your uh architecture.But the pattern is still the same.Second, a stream is something that you can compose with other parts but you cannot do the same thing for files.What that means is if we talk about three different environments on your laptop when you are running your application your log stream since you are pushing it to standard output you see all your logs in your terminal andyou are able to read it live.Similarly, if you are in a container, then the runtime will be able to capture those logs, those stream and it will be able to stamp those logs by which process exactly is that log coming from and then itgives that back to the collector whichever collector process is trying to store that log, trying to uh analyze that log or whatever.Similarly, in your production environment, the platform, the orchestrator or whatever cloud platform, it takes all the streams of all your instances.
Then it merges them into one log stream which is ordered by time.So you do not have to make the distinction of which log is coming from which instance.You just have to worry about the time of when each event happened.So the whole overhead of um worrying about understanding your logs, analyzing your logs, searching in your logs when there are multiple instances that is completely gone because of this architecture.So by just pushing your logs into standard output, you can compose different different architectures from the same pattern depending on the environment.But these days of course we have much more advanced architectures when it comes to logs.We have this whole field of study or field of technology called observability which consists of logs, metrics and traces.But in the original 2011 text, it only mentions logs because the other two the metrics and traces that was not something that was practiced during those times.
So you have to take the practice of metrics, traces and all these new things as an addition instead of uh thinking that the factor itself is limiting you.And now factor 12 run admin and management tasks as oneoff process.What is a one-off process?It basically means a task that you only run once and it is run next to the uh your application's long running process and then it exits.So let's imagine a scenario you have a back end an HTTP back end which um takes as usual HTTP requests and processes and gives back responses.Apart from doing that it also needs to do other stuff.For example, it needs to run a database migration or maybe it needs to run a uh some kind of script to fix some kind of data in your production.So these kinds of things which run exactly once and they need to run side by side to your running application.
So this factor talks about where exactly we should run these one-off process, one-off tasks.And it says that a one-off process, a one of admin process, it should run in an identical environment to your original application's regular process.It should have the same codebase and it should exist in the same commit so that the deployment can take both and it should also work with the same config and the same dependency isolation model that applies to ouroriginal application.And why are we being so strict about this uh one-off script one-off process?Because in the old days when people wanted to fix a particular record, they used to do an SSH into their running server and they used to run a query either update query or a delete query or some queryand there was no process of any kind of code review or the process review, no record, no logs of what exactly did you do in production which causes a lot of drift between your production environment and what exist
in your code, what is documented.One of the most famous examples which follows this factor is our database migrations which ships with our same code and it runs as a one-off process before our application starts and it ends there.to show some of these 12 factors in practice.This is our task app that we built in one of our videos and this is the back end of that which is running in a Linux machine a hawk that we are sshing into and it is driven bya proc file which is just a file that was invented by Heroku to declare different process types.the different process types that we talked about web process worker process and then scheduuling process and so on.So one process type which is web then a process manager called overmind which starts the whole formation and if you look at the booting process there is this schema check then the background job server and then the server
binds itself to the port it was assigned to everything that we talked about in the factors in that exact order.Then it also has its own log stream which is going to standard output.Now in the second pane I'm running a one-off admin process which is uh for autoarchchiving which runs from the same code the same config and the same environment and then it exits and in the end we press CtrlC and if you look at the shutdown the connection pool closes the job server waits for all its workers to finish their jobs and the process reports a clean exit is the factor 8 9 and Elsewhere
Seek backward 5s ←
Longer seek (10s) Shift ←
Play Space Seek forward 5s →
Longer seek (10s) Shift →
0:00 Auto-scroll A Copy link at current time S

27. The Twelve-Factor App