Technical

Make an Undocumented System Safe to Change: A Two-Week Plan

Inherited codebase with no documentation? A plan for the first two weeks: a tested restore, a rollback and a characterization test, all before any rewrite.

Nemanja Marjanov
Co-Founder & CEO
| · 10 min read
Make an Undocumented System Safe to Change: A Two-Week Plan

An undocumented system is safe to change when you can do three things on demand: restore its data from a tested backup, undo a release, and prove with a test that a change did not alter behavior you depend on. You can set up all three in about two weeks, before any refactoring or rewrite, and in that order.

The plan below is for an inherited codebase with no documentation. It runs day by day, with templates you can copy, in the order we would work in. Most of what we run, we built from the first line.

It is for an operations or engineering lead whose system still runs and earns money, but nobody dares to change it: the original developer is gone, nobody knows how it works, or a change just broke production.

Why does nobody dare to touch an undocumented system?

The fear is rational. You cannot say what a deploy will break, whether the backup restores, or who can log in to what, so the cost of any change has no ceiling. Changing nothing looks like the careful choice, until a failure or a must-have change request takes the choice away.

What is missing is a safety net, not a rewrite. A rewrite is a very large change made without that net: it swaps a system you cannot change safely for one you cannot yet trust. Our stance is to stabilize first and decide about a rewrite later, with evidence.

In what order do you make it safe, and what stays out?

In our judgment the order is restore, undo, prove, then change, and each step makes the next one safe.

  • Restore first. It caps the worst outcome: with a tested restore, a mistake costs time, not data.
  • Undo second. Once a bad release can be reversed within a time limit you set, shipping a test or a fix stops being a bet on the whole business.
  • Prove third. A test shows what a change did to behavior before your users find out, and a failing test is cheap when the way back already exists.

Two days of groundwork come first, because you cannot restore, roll back or test a system you cannot build. Refactoring, upgrades and new features stay out of the two weeks: each changes behavior or the environment, and the net does not exist yet.

The day counts are our rule of thumb for one system with one database. A larger system takes longer; the order does not change. If you forward one part of this post to whoever holds the budget, forward this table.

Days Step What you end up with Done when
1 to 2 Clean build and access inventory A build recipe for an empty machine, and a list of every account, secret and domain A newcomer builds it from the recipe alone, and every listed item has an owner or is marked unknown
3 to 5 Restore drill A restore log with the elapsed time The latest backup is restored into a clean environment and the system runs on it
6 to 8 Rollback A written procedure with an owner and a time limit Someone other than its author rolls back a harmless release inside the time limit
9 to 11 First characterization test A test that pins today’s behavior of the module you will change The test passes today and fails when that behavior changes
12 to 14 Risk list and one safe change A risk list, worst first, and one change in production An alert reached a named person, and the change shipped with restore, rollback and the test behind it

Days 1 to 2: How do you get a clean build and find who holds the keys?

Build the system on an empty machine: a fresh virtual machine, or a laptop that has never held the project. Follow whatever instructions exist, and each time you hit a gap, write it down and fix the recipe: a tool version, an environment variable, a private package login, a file that lived only on one person’s laptop. Then find out which version is running in production. Do not assume it matches the main branch.

Next, list every account, secret and domain, and who controls each one. Work read-only and change nothing yet: rotating a secret you do not understand is how a quiet system becomes an outage. The full inventory is in our post on the first days after a developer leaves.

Days 3 to 5: How do you know the backup restores?

A backup nobody has restored is a hope. Take the latest one, restore it into a clean environment that is not production, switch off outbound email, payments and webhooks there, then start the system against it and check a few facts the business cares about: yesterday’s records exist, a known user can sign in. Time the whole run.

Guard the copy like production data. When the restore does not work, the missing piece is not always the database: it can be uploaded files, an encryption key nobody holds, a scheduled job or a secret. Fix each gap and run the drill again; the second clean run is your evidence.

Google’s SRE book makes the general point in its chapter on emergency response: “Don’t rely on assumptions or what you can’t or haven’t tested.” The log below is a template, not a record of a real drill.

RESTORE DRILL LOG (template)
Date:
Run by:
What was restored (system, backup timestamp):
Restored into (environment):
Elapsed time (first command to working system):
Checks that passed:
What was missing:
What was fixed:

Days 6 to 8: How do you undo a release?

Write the rollback down as a procedure with an owner, a time limit and exact steps. Then test it on a harmless release, in staging if you have one: ship a trivial change, such as a version string, and have someone who did not write the procedure undo it by following the written steps.

Keep the previous version where you can reach it; you cannot go back to something you cannot rebuild, which is why the clean build comes first. The hard case is a release that changes the database schema. Splitting it into phases, so old and new versions run side by side, is one well-known answer, described by Danilo Sato as parallel change.

An untested rollback can fail when you need it. In one incident in the SRE chapter, an attempt to roll back a permissions change was unsuccessful, and among the lessons Google listed: “Because we hadn’t tested our rollback procedures in a test environment, these procedures were flawed, which lengthened the outage.”

On BELGRAND ScoreMaster, the software we built for live LED scoreboards, desktop releases go through more than 1,700 automated tests and a beta channel, with the previous version kept for rollback. The template below is generic, not BELGRAND’s procedure.

ROLLBACK PROCEDURE (template)
System and environment:
Owner and backup owner:
Time limit (decision to previous version serving users):
Who may order a rollback:
Where the previous version lives:
Steps (exact commands, in order):
Does this release change the database? If yes, the way back:
How we confirm it worked:
Last tested (date, by whom, elapsed time):

Days 9 to 11: How do you prove a change did not alter behavior?

A characterization test records what the code does today, bugs included, not what it should do. Michael Feathers, who wrote Working Effectively with Legacy Code (2004), describes the idea in a 2016 article: “When a system goes into production, in a way, it becomes its own specification.”

Here is an invented example in Go, part of our home stack: a function nobody documented.

func InvoiceTotal(unitCents, qty int) int {
	total := unitCents * qty
	if qty >= 10 {
		total -= total * 5 / 100
	}
	return total
}

First, call it with an input and a placeholder expected value, run the test, and read the real answer from the failure: InvoiceTotal(1999, 10) = 18991, want 0. Then pin what you recorded, including the edge at ten units.

func TestInvoiceTotalToday(t *testing.T) {
	// Recorded from the code as it runs today, not from a spec.
	cases := []struct{ unit, qty, want int }{
		{1999, 9, 17991},
		{1999, 10, 18991},
		{995, 10, 9453},
	}
	for _, c := range cases {
		if got := InvoiceTotal(c.unit, c.qty); got != c.want {
			t.Errorf("InvoiceTotal(%d, %d) = %d, want %d", c.unit, c.qty, got, c.want)
		}
	}
}

Now someone tidies the discount so it rounds half up, with total -= (total*5 + 50) / 100. The test fails with two messages (file and line prefixes trimmed):

InvoiceTotal(1999, 10) = 18990, want 18991
InvoiceTotal(995, 10) = 9452, want 9453

The gap is one cent, and neither answer is obviously right: the old code drops the fraction of a cent and the new code rounds it. If invoices already went out at the old amounts, your customers’ records depend on the old arithmetic. The test decided nothing for you; it made the change visible while it is still cheap to undo.

Feathers says the hardest part is breaking the code’s dependencies well enough to call it from a test. If you cannot, test one level up: record what an endpoint or a report returns for fixed inputs from the copy you restored in days 3 to 5, with personal details removed.

How many tests is enough? Enough to cover the module you are about to change. We know of no universal number.

Characterization tests are for code whose behavior nobody wrote down. Once a module is understood, tests that state what it should do can take their place. For the wider picture, see our testing and QA strategy guide.

Days 12 to 14: What do you fix first?

List the risks, worst first, ranked by business impact and not by how ugly the code looks: a module that sends invoices outranks an ugly one nobody has touched in years. To rank technical debt itself, see our technical debt guide. The table is a template with two invented example rows.

Risk Impact Likelihood Evidence Fix Reversible
Billing job fails without an alert Customers are not invoiced High Job log shows failures, nobody notified Send the failure alert to a named person Yes
Database engine past end of support Known flaws stay unpatched Medium Version older than the vendor’s support list Upgrade after the two weeks, behind tests and a fresh backup No

Then check that alerts reach a person. Trigger the one that matters most, such as a failed backup or a down service, and confirm that a named human sees it. An alert sent to a mailbox nobody reads is not an alert.

Finally, ship one small change with restore, rollback and the test behind it. Pick the highest risk that is cheap and reversible to fix, take a fresh backup and release through the clean build. If any part of the net fails here, you found a gap while the stakes were small.

What happens after the two weeks?

You now have a system you can change in small steps and undo. That is the moment to decide about a rewrite, because a rewrite decision made before the safety net exists is a guess. With the net, you can see how long a change takes, how often a release needs the way back, and which modules keep failing. For the rewrite-versus-modernize question itself, see our legacy system modernization guide.

What if you would rather not do this alone?

A Technical Review is one to two weeks with read-only access. You get a map of the system and a list of its risks, worst first, then a plan and a fixed price for what comes next. You can stop there. The fee is fixed, agreed in writing before we start and scaled to the size of the system. If a rewrite is the better call, you will hear it in the review, not after the contract.

What a review report contains, and what vendors say they charge, is in our post on review reports and vendor prices.

The code, the accounts and the data stay in your name, with no lock-in. The steps we follow after a review are on the ownership page, and what we have not done yet is on what we have not built.

What should be true before you change anything?

  • The system builds from an empty machine, and you know which version runs in production.
  • Every account, secret and domain has an owner or is marked unknown.
  • A backup has been restored into a clean environment, and the elapsed time is in a log.
  • Someone other than the author has rolled back a release inside the time limit.
  • A test pins the behavior of the module you are about to change, and production alerts reach a person.

Where do you go from here?

If any line above is still untrue and you cannot close it alone, the ownership page explains how we work with a system you already run. You can also tell us about your system in a few lines.

Want Your System Read Before Anything Changes?

Our Technical Review takes one to two weeks with read-only access. You get a map of the system and a list of its risks, worst first, then a plan and a fixed price for what comes next. You can stop there.

Share

Get insights like this in your inbox

Practical tips on software development, AI automation, and tech strategy, delivered weekly.

No spam. Unsubscribe anytime.

Keep the System. Hand Us the Responsibility.

We stabilize live software and keep it shipping, without a rewrite. Most of what we run, we built from the first line and still maintain.

Nemanja Marjanov

Co-Founder & CEO

Software architect behind Arhivix, the in-house system that automates document processes, used by 500+ companies. Leads Notix engineering across 50+ shipped projects.