Back to blog
Twelve-Factor SaaS DevOps Next.js PostgreSQL Architecture

The Twelve-Factor App in a Real SaaS

By Ken B Portfolio · Published on October 29, 2026
Illustration of a developer working at a laptop

Most app problems after launch are not bugs in a feature. They are problems in how the app is run.

A setting that only lives on one laptop. A server that forgets who is logged in when it restarts. A bad release with no quick way back.

The Twelve-Factor App is a list of twelve rules that stops those problems. It was written by the team behind Heroku, and it still holds up for any web app.

This page shows how one SaaS I build measured up: a job-alert app with real users, payments and a database.

The twelve rules, in plain words

  1. One codebase. One code store. Test site and live site are copies of it, not forks.
  2. Dependencies. Every tool the app needs is written down, with its version, and installed with the app. Nothing relies on a tool that just happens to be on the machine.
  3. Config. Passwords and settings live outside the code, set per site.
  4. Backing services. The database, email and payments plug in by address. Swap one, change one setting.
  5. Build, release, run. Building, going live and running are three separate steps. Every release has a name you can go back to.
  6. Processes. The app keeps nothing in memory that it can’t lose. All lasting data sits in outside storage: the database, a file store, and so on.
  7. Port binding. The app serves itself on whatever port the host gives it.
  8. Concurrency. The app can handle more traffic by running more copies of itself. A bigger server is still allowed, but it shouldn’t be the only option.
  9. Disposability. A copy starts fast and shuts down cleanly. If one stops mid-job, the work can finish or safely run again.
  10. Dev/prod parity. My laptop, the test site and the live site run the same tools, so a test result means something.
  11. Logs. The app writes events out. The host collects them.
  12. Admin processes. One-off jobs, like database changes, run with the same code, tools and settings as the app. Starting one by hand is fine.

The first check: 8 out of 12

In September I ran a full audit of the app against all twelve. The result:

  • 8 passed
  • 3 passed only in part
  • 1 could not be proven from the code

None of the gaps had broken anything yet. Each one was the kind of thing that breaks on a busy day.

What failed, and the fix

The tool versions were not pinned. The required version of Node was only written in the setup notes. Two machines could build with two different versions. Fix: the version is now set in the project files, so the wrong one is refused.

The app ignored the host’s port. It always started on its own fixed port. On most hosting platforms that means the app starts but nobody can reach it. Fix: it now takes the port the host gives it.

A test tool was set to “latest”. The local email catcher could change under me without any code change. Fix: pinned to one version.

Nobody could prove what was live. This was the big one. The host builds the test site and the live site separately. After a release, there was no quick way to check both ran the same code, or which release to go back to. Fix:

  • Each site now reports the exact code version it runs.
  • One command checks both sites against the main code and flags any difference.
  • A written rollback plan: move the live site back to the last good release, with no rebuild.
  • A rule for when the database changed too, since old code must still work with new tables.

Writing the plan was not the end. Checking it against the live setup, line by line, found a nightly backup that had failed three nights in a row without anyone noticing. More on that check: When to roll back a release.

Where it stands now

In November I ran the check again: 8 pass, 4 pass in part, none fail. The parts still open are small, and each is written down with its fix:

  • Codebase. Some old branches still need clearing out.
  • Config. No password or key is in the code, and each site gets its own from the host. But some setting names are missing from the example file a new developer starts from.
  • Dev/prod parity. My laptop runs the same database version and add-ons as the live site. The tests run before every push, but not yet on a separate server.
  • Admin processes. Database changes run one way only, from the host’s build, never from a laptop. Anything that deletes data needs an extra yes. The rerun flagged that the nightly backup depended on a key file missing from the code store.

Two that were already strong:

  • Logs. Errors go to an error tracker with personal data removed before they leave the app.
  • Processes. One gap from the first draft of this post is closed: rate limits used to be counted in each copy’s memory, so five copies let one person go five times over the cap. The count now lives in the database, shared by every copy.

Where I bend the rules, for now

This app is still early. Following every rule to the letter costs time that is better spent on users. So a few rules are bent on purpose, and each one is written down with the point where it gets fixed.

Two builds, not one. The strict rule says: build once, then move that same build from test to live. This app builds twice, once per site, because some settings get baked in at build time and the two sites need different ones. The version check proves both builds came from the same code.

My laptop is close to live, not identical. The database runs in Docker on my laptop, same version and add-ons as live. The app itself runs straight on the laptop, because the live host’s setup can’t run on a laptop. If the app ever moves off this host, one Docker image for every stage closes this gap.

Database changes run during the build. The strict rule keeps building and changing the database apart. Here the host’s build runs any new database changes first, so no laptop holds the keys to the live database. Changes only add, never remove in the same step, so the site keeps working while the new version goes live.

Six questions to ask your developer

You don’t need to know the twelve rules to test your own app. Ask:

  1. Can a new developer start the app from the written steps alone? If it only runs on one laptop, rules 1, 2 and 3 are failing.
  2. Where do the passwords and keys live? The right answer is “with the host, per site”. Never in the code.
  3. Which version is live right now, and how do you know? A guess is a fail.
  4. How do we go back to the last good release, and when did you last try it?
  5. If the server restarts, does anyone lose work or get logged out?
  6. When did the backup last run, and who would notice if it stopped?

What a new developer should get on day one: What a good handoff includes.

You don’t need to learn the twelve rules. I run the check against your code and your live setup, fix what fails, and write down any rule bent on purpose, with the point where it gets fixed.

The short version

Twelve-factor is not about style. It decides how fast you recover when something goes wrong, and whether a new developer can run your app on day one. Check it, fix what fails, write down what you bend, and check it again later.

Which of the twelve would your app fail today?

APPSTHATSHIPSAFELY

Tell me where your app runs and how it goes live, and I'll tell you which of the twelve factors it would fail first.

More Posts

All posts