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.
