Blog/Engineering

Legacy Code Nobody Wants to Touch: How a Remote Engineer Takes It Over Safely

By GauravNovember 30, 202610 min read
Legacy Code Nobody Wants to Touch: How a Remote Engineer Takes It Over Safely

Every engineering team has that part of the codebase nobody wants to look at. It's not necessarily old, though it often is. It's the part with no tests, inconsistent conventions, business logic spread across files in ways that only made sense to the person who wrote it, and comments that say "TODO: fix this" dated three years ago. When you bring in a remote engineer to take it over, the first question is how they approach the work without making things worse. The answer, more often than engineers like to admit, is slowly.

What makes legacy code actually dangerous versus just old?

Age is not the problem. Code can be ten years old and straightforward to maintain if it was written consistently, has tests, and hasn't accumulated changes from twelve different people over eight years of "quick fixes." The dangerous kind of legacy code has three characteristics. First, there are no tests, or the tests are so out of date that they test things that no longer exist. Without tests, every change is a guess about whether anything broke. Second, the business logic is not where you expect it to be. It's in a database trigger, or in a cron job that someone added years ago and hasn't been touched since, or hardcoded in a config file, or implemented differently in two places that are supposed to do the same thing. Third, there are side effects that aren't visible from reading the code. The function that updates a user record also sends an email, also logs to a third-party service, and also invalidates a cache, but none of that is documented anywhere. You change the user record logic and three other things break in ways you couldn't have predicted without knowing the full call chain.

How do you map a codebase you didn't write?

Start from the outside in. The entry points of the system (HTTP routes, background job definitions, event handlers, scheduled tasks) tell you what the system does in production. Everything else is implementation detail that only matters once you understand what it's implementing. Read each entry point and trace the execution path: what does this endpoint call, what does it write to, what does it return. You don't need to understand every detail of every path on the first pass. You need to know which paths are critical (payment flows, authentication, data integrity) and which are non-critical (cosmetic features, legacy API endpoints nobody calls anymore). Once you've mapped the entry points, read the database schema. The schema is usually the most reliable documentation of the data model because it had to match reality to work. The table names, column names, foreign keys, and constraints tell you what the system cares about preserving. After the entry points and the schema, trace the external dependencies: every API call, every integration, every place the system talks to something outside itself. These are the places that break when credentials expire or external services change, and knowing them upfront saves you from debugging production issues with no context.

What's the right approach to making changes in legacy code without breaking things?

Write tests before you change anything. Not comprehensive tests for the whole codebase, which would take weeks and would mostly test behavior you're not planning to change. Write tests for the specific behavior you're about to modify: inputs, expected outputs, side effects you know about. These tests serve two purposes. They verify that your change did what you intended. And they tell you if the code you're changing has side effects you didn't know about, because those side effects will cause your tests to fail in ways you didn't expect, which is a signal to investigate rather than force the test to pass. After writing tests, make the smallest possible change. The instinct with legacy code is to refactor the whole surrounding area while you're in there, because it looks bad and you can see how to make it better. Resist this. Every line you change is a potential regression. Make the minimum change that achieves the goal, verify the tests pass, deploy, verify in production. Then make the next minimum change. This is slower than rewriting the section, but it's faster than rewriting and spending a week debugging a regression you introduced while cleaning up code that wasn't causing any problems.

When do you refactor versus when do you leave legacy code alone?

Refactor when the code you need to change is so tangled that making a targeted change is riskier than rewriting the section cleanly. This is relatively rare in the first few months of a takeover. More commonly, the right answer is to leave the structure alone and change only what you need to change. The exception is when you're going to be working in the same section repeatedly. If a function is confusing enough that every time you need to change it you have to re-understand it from scratch, refactoring it once pays for itself in future time. If a function is confusing but you're only going to touch it once or twice a year, leaving it alone is the lower-risk choice. The other case for refactoring is when you've built enough tests around a section that you can verify the refactor didn't change behavior. Without that test coverage, refactoring is rewriting with optimism, and optimism is not a good substitute for verification in production systems.

How long does it realistically take to get comfortable in someone else's legacy code?

Longer than engineers want to admit, and longer than clients usually expect. For a typical web application of moderate complexity, a good engineer reaches "can make changes safely and predictably" in about four to six weeks. "Can make changes quickly and confidently" takes three to six months. "Understands the system well enough to make architectural decisions" can take a year. These timelines assume active work in the codebase, not occasional bug fixes. They also assume the engineer is communicating what they find, documenting the system as they learn it, and asking questions rather than guessing when something is ambiguous. The engineers who claim to "get it" in two weeks are either working on a simple codebase or skipping the understanding step and going straight to changing things, which produces regressions. Speed in legacy code comes from accumulated knowledge, not from moving fast upfront.

What kind of engineer handles legacy code well, and who avoids it?

Engineers who are patient, methodical, and genuinely curious about how systems work tend to do well with legacy code. They treat the codebase as a puzzle to understand rather than a mess to escape from. They read old commits to understand why something was done the way it was. They ask questions before making assumptions. They document as they go, partly for the team and partly to organize their own understanding. Engineers who struggle with legacy code are usually the ones who primarily want to build new things. They're energized by greenfield work, good architecture from the start, and clean code. Legacy code requires the opposite disposition: patience with imperfection, comfort with uncertainty, and willingness to work incrementally rather than redesigning everything at once. Both types of engineers are valuable; they're just valuable in different situations. When you're hiring someone specifically for a legacy takeover, you want the first type, and you should interview specifically for it rather than hiring based on technical skills alone. See what we look for when placing software engineers for how we evaluate ownership and maintenance disposition during screening. For the transition process when an agency is handing over to your new engineer, who maintains your software after the agency leaves covers the full handover workflow.

Frequently asked questions

How do you safely make changes to legacy code with no tests?
Write characterization tests first: tests that capture the current behavior of the code you're about to change, even if that behavior is wrong. This gives you a baseline to verify against. Then make your change and check whether only the intended behavior changed. If unexpected things change, that's your signal to investigate before continuing.
Should you rewrite legacy code or maintain it?
In most cases, maintain it incrementally rather than rewrite it. Rewrites take longer than expected, lose institutional knowledge embedded in the existing code, and often reproduce the same bugs with different names. The exception is when the existing code is so structurally broken that targeted changes carry unacceptable risk, and you have enough test coverage and system understanding to verify the rewrite doesn't change behavior.
What's the first thing to do when inheriting a legacy codebase?
Get it running. Local environment, test suite (if any), staging environment, deployment process. Until you can make a change and deploy it safely, you can't do anything else. This step often takes longer than expected and surfaces the first round of undocumented dependencies and configuration requirements.
How do you handle legacy code that the original developers won't document?
Read the git history. Commit messages, even bad ones, tell you when things changed and sometimes why. Read the tests if they exist. Run the code and observe what it actually does rather than what the documentation says it does. Build your own documentation as you go, which serves both future engineers and your own ability to reason about the system under pressure.
How is taking over legacy code different from starting a greenfield project?
In greenfield work, you make architectural decisions based on requirements. In legacy takeovers, the architecture is already there and your job is to understand it, preserve what works, and improve what doesn't while keeping the system running throughout. The skills are different: greenfield favors design thinking, legacy favors analytical thinking and risk management.
What makes a remote engineer particularly well-suited to legacy code takeovers?
Remote engineers who work across multiple clients and codebases see more varied systems than engineers who stay at one company. That breadth means they've encountered more patterns, more failure modes, and more edge cases, which helps them recognize what they're looking at faster in an unfamiliar codebase. The best remote maintenance engineers have strong async communication habits, which also matters for documenting a system as they learn it.

Ready to build your team?

Tell us what you are building and we will find the right engineers for your project. 48-hour matching, 1-week paid trial.