The New Default. Your hub for building smart, fast, and sustainable AI software

See now
Two hands fitting a striped gear and a matching block together, illustrating developers and clients cooperating on a legacy code refactor

Working Effectively With Legacy Code: How Developers and Clients Cooperate on a Refactor

Grzegorz Hajdukiewicz
|   Updated Nov 8, 2026

Working effectively with legacy code starts with three agreements between the development team and the client: common names for business concepts, documentation that grows out of cleaner code, and a business case for refactoring that both sides accept. Legacy code is code you inherit from earlier developers and must keep running, often with little documentation and logic that has drifted from the business.

An HR web application whose first commits date to 2015 shows why. It once had a single feature with three different names, one in the interface, one in the backend, and one used in client meetings.

Executive Summary

Refactoring legacy code is as much a communication task as a technical one. Mismatched vocabulary across UI, backend, and client conversations wastes time, so the first step is establishing a common vocabulary. Splitting tangled classes into clear use cases then makes documentation realistic. Real metrics, such as release pace, bug counts, and new-hire onboarding, show the client what changed before and after the work.

Why Does Legacy Code Get Hard to Change?

Legacy code becomes hard to change because many developers touch it over the years, business concepts shift, and teams postpone maintenance, such as documentation, in favor of features. Each shortcut seems small, and together they slow every later change.

This HR product followed that path. At first, only the product owner maintained it. Features came first, and the code accumulated outdated names along the way. When the team took it over, they chose to refactor rather than rebuild.

Most developers know this cost firsthand. A 2024 Stack Overflow survey found that technical debt troubled 62% of developers. In his essay on software quality, Martin Fowler argues that poor-quality code slows developers within a few weeks, so neglect stops saving time almost at once.

Clients feel the same slowdown as missed estimates and longer release cycles. They may not see its source because the code is invisible to them. Making that link visible is where cooperation starts.

How Do You Agree on a Common Vocabulary With the Client?

Pick one name for each business concept and use it across conversations, the UI, the code, and the tests. On the HR app, users saw a Spaceship, the backend called it TinCan, and the client called it Rocket, so every discussion about that feature required translation.

Eric Evans calls this a ubiquitous language in Domain-Driven Design, a rigorous vocabulary that developers and users share. Retrofitting one into existing code leaves three realistic options, each balancing effort and precision for codebases of different sizes.

Option

How it works

Trade-off

Rename the code

Change backend names to match the UI and client language

Feasible, though it costs time and resources

Keep a glossary

Maintain a synonym list that maps UI terms to code terms

Easiest to start, and the least precise

Run event storming

Map business events with the client in a workshop, then align names

Best when no shared language exists and code is already written

Developers pushed for event storming on the HR application before tackling bigger features, so new work would start with agreed-upon names. Miscommunication about features ended after both sides adopted it.

Alberto Brandolini came up with EventStorming in 2013 to model complex business processes quickly. Participants place domain events on orange sticky notes along a timeline, each named in the past tense, such as "order placed." The room mixes people who know the questions with people who know the answers, so the client helps choose the names.

How Does Refactoring Make Documentation Possible?

Refactoring makes documentation possible because a clear structure gives each piece of logic an obvious home and a name worth describing. On the HR project, features had always come first, so complex business rules lived in long methods with almost no written explanation.

Developers first split the code into components by use case. A single class that handled buying parts and building a rocket in one long method became a coordinator that delegates to two focused classes.

# Before: one method mixes every responsibility
class RocketFactory
  def call(order)
    # validate the order, buy parts, check stock, assemble, notify...
  end
end

# After: each use case has one job
class RocketFactory
  def call(order)
    parts = BuyParts.new.call(order)
    BuildRocket.new.call(order, parts)
  end
end

With responsibilities separated, documentation became manageable because each class now addressed a single business question. Short user stories came first, each describing what a use case does for the user. Diagrams of the main flows can extend them later.

Example Mapping keeps stories grounded. In Cucumber's version of the technique, a yellow card holds the story, blue cards hold its rules, green cards give examples, and red cards capture open questions. A developer, a tester, and a product person can map a well-sized story in about 25 minutes. On a client project, the client's product owner can take that third seat. New developers can start with those stories and check them against the code, which keeps both accurate.

How Do You Convince a Client to Pay for Refactoring?

Show the client the current code's impact on delivery speed, defects, and onboarding, then propose refactoring to reduce those numbers. The definition itself adds friction. By Fowler's definition, refactoring is a disciplined technique for restructuring existing code that changes its internal structure while leaving its external behavior intact. To a client, that can sound like paying for no change at all.

Asking for budget for something with no visible feature is hard, and the difficulty depends on four factors.

  1. Deadlines. A release date can push refactoring later, so tie it to the features that need it.

  2. Business value of current work. Refactor first where upcoming features will land.

  3. Budget. Offer small, time-boxed slices and skip large upfront estimates.

  4. Perceived value. Clients who do not see the value yet need the strongest arguments.

The HR client had built several apps before and employed its own specialists, so refactoring required no persuasion. It treated code health as the team's responsibility and committed to the product for the long haul. Other clients need data, time, and some flexibility in delivery dates.

Be upfront and never hide refactoring within feature work. Share the plan, the metrics you will track, and the point at which the client will see results. Useful metrics include lead time for a typical feature, the share of releases with defects, and the number of days a new developer needs before their first merged change.

When Should Refactoring Happen, Before a Feature or Alongside It?

Two habits from Martin Fowler's writing suit client projects. Preparatory refactoring restructures code right before a new feature, making the feature itself simple to build. Fowler quotes Kent Beck's summary, "make the change easy, then make the easy change."

Jessica Kerr, quoted in Fowler's preparatory refactoring article, compares it to a detour. Driving 20 miles north to a highway and then 100 miles east at triple speed beats cutting straight through the woods. That framing ties every hour of refactoring to a feature the client already asked for.

Opportunistic refactoring covers the rest. Anyone who spots unclear code cleans it up on the spot, following the campsite rule of leaving code better than they found it. Fowler still allows scheduled efforts for a troublesome area, such as a day or two of focused work. He also notes that a team using refactoring well should rarely need to plan it, which keeps most cleanup out of budget debates.

What Does One Legacy Code Refactoring Slice Look Like?

A slice is a short, bounded piece of refactoring tied to work the client already wants. Every slice can follow the same sequence.

  1. Pick the area where the next planned feature will land.

  2. Agree with the client on names for the concepts in that area.

  3. Cover current behavior with tests, so every later change has a safety net.

  4. Split long methods into use-case classes with one job each.

  5. Write a short user story for each new class.

  6. Report the agreed metrics in the client's terms once the slice ends.

Step three matters most. Michael Feathers, whose 2004 book Working Effectively with Legacy Code gave this topic its name, defines legacy code simply as code without tests. Without tests that pin down what the code does today, nobody can confirm that a cleanup left behavior unchanged.

Keeping slices this small limits risk because any problem stays contained within a single area. Small slices also give the client regular, visible progress to judge. Steps two and six keep the client involved, while the rest stays within the development team. A slice that runs longer than planned signals that the area should be split further.

What Does the Client Contribute to a Legacy Code Refactor?

Cooperation runs both ways, and a refactor moves faster when the client knows its part from the first slice. Four contributions matter most:

  • Someone on the client side who can join event storming and Example Mapping sessions and decide on names.

  • A ranked list of upcoming features, so each slice lands where new work will follow.

  • Support tickets and release history, which give the baseline for later comparisons.

  • Short, regular reviews where the team shows what changed and the client confirms the next area.

Each item calls for business knowledge more than technical skill. Clients who skip these steps still get cleaner code, but they lose the evidence, and the next conversation about budget starts with trust alone. A client who stays involved can explain the work to its own stakeholders in plain business language. That ability often decides whether refactoring survives the next round of budget planning.

What Results Should Both Sides Expect From a Legacy Code Refactor?

A well-run refactor speeds up feature delivery, shortens ramp-up for new hires, and reduces bugs and performance issues. For example, adding a UI button can drop from days of work to a few hours once the structure is clear.

Other gains follow. Developers see where a change belongs, test runs get shorter, and client meetings go more smoothly because everyone uses the same names. Motivation rises, too, since engineers spend less time fighting the code.

Some clients learn the value of refactoring only after paying for shortcuts. Teams can spare them that lesson by starting small and reporting results after each slice. Report in the client's terms, such as features delivered per month or support tickets per release.

When a product needs more than a cleanup, compare a rewrite with a phased upgrade before committing budget. The Cooleaf Rails refactor took the gradual route too, reworking a 65,000-line codebase one concept at a time alongside ongoing development.

Key Takeaways

  • Working effectively with legacy code starts with shared terms across UI, code, and client talks.

  • Event storming, a glossary, or renaming can retrofit a common vocabulary into existing code.

  • Use-case classes give documentation a stable structure to follow.

  • Preparatory refactoring ties each hour of cleanup to a feature the client already wants.

  • Share real metrics, such as lead time, bug rates, and ramp-up, before and after each slice.

  • Small, time-boxed refactoring slices let the client see results early.

Treat Refactoring as a Shared Project

Refactoring succeeds when the client views it as an investment in their product, with clear goals and measurable results. A common vocabulary, readable code, and regular reporting turn a technical chore into a joint decision about speed and risk.

For an inherited Rails product, Monterail's Ruby on Rails developers can review the code with you and plan the first slices. Talk to Monterail about your legacy code.

Refactoring Legacy Code FAQ

Grzegorz Hajdukiewicz avatar
Grzegorz Hajdukiewicz
Chief Delivery Officer
Linkedin
With over a decade of experience in the IT industry, Grzegorz has a proven track record of delivering complex projects on time and on budget. At Monterail, he leads a team of dozens of developers, designers, project managers, and business analysts, ensuring the successful delivery of software solutions for clients worldwide. Passionate about agile methodologies and continuous improvement, he constantly seeks new ways to optimize the delivery process.