📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Tell me about a time you joined a large legacy codebase and made it better. How did you get productive in it, how did you decide what to improve first, how did you change it safely without stopping feature work, and how did you show the improvement was real?

The 'joined a legacy codebase' story: learning an unfamiliar system fast, mapping risk and pain with data (change frequency, incidents, build time), characterisation tests, strangler-fig and boy-scout improvements alongside features, and proving the result with numbers.

Senior Behavioral Advanced characterisation-tests legacy-code real-world refactoring star-story technical-debt

🎯 Key points

  • Learn before changing: run it locally, read the incident history, ship a small fix in week one
  • Prioritise by data: churn × complexity hotspots, incident count, build and deploy time
  • Characterisation tests (xUnit + Verify snapshots) around the hotspot before touching it
  • Improve alongside features (boy-scout rule, strangler fig), never a big-bang rewrite
  • Automate the release path first: CI/CD pipeline (Azure DevOps or GitHub Actions) with tests as a gate
  • Close security and support gaps: out-of-support frameworks and packages, secrets in config, patching (Essential Eight)
  • Agree a visible budget with the product owner (e.g. 15–20% of each sprint) and respect the people who built it
  • Result with numbers: lead time, change failure rate, incidents, build time

⏱ 30-second answer

I treat a legacy codebase as a working system that earns money, not a mess to replace. First I learn before changing: run it locally, read the incident history and ship a small fix in the first week or two. Then I find the hotspots with data: files that change often and are complex, plus the ones behind incidents and slow builds.

I put characterisation tests around a hotspot before refactoring it, and improve it alongside feature work (boy-scout rule, strangler fig) inside a budget agreed with the product owner. I show the result with numbers: lead time, change failure rate, incidents, build time. The trade-off: small steady steps are slower to look impressive than a rewrite, but they never stop delivery and they rarely fail.

🗣 Full answer (senior)

How I would answer this in an interview

"When I joined [company], the core system was [a 12-year-old ASP.NET MVC 5 / WebForms application, around 400k lines, on .NET Framework 4.8]. Releases took [a full day with a manual checklist], and [roughly one in four] caused a hotfix. Nobody wanted to touch [the pricing module].

For the first [three weeks] I didn't change anything structural. I got it running locally, which alone took [two days] and turned into a setup script, read [six months] of incident reports, and fixed [two small bugs] so I'd been through the whole release path. Then I pulled git history to find files that changed most often and were also the most complex. [Three files in pricing] were in the top ten on both lists and behind [40%] of incidents. That data made the conversation with [the product owner] easy: I asked for [about 15%] of each sprint and promised every change would ride along with feature work.

Before touching pricing I wrote [around 60] characterisation tests that pinned its current behaviour, including two bugs customers relied on. Then I extracted it behind an interface, one rule at a time, while the team kept shipping. After [six months], [release time went from a day to under an hour], [hotfixes dropped from about one in four releases to one in fifteen], and pricing changes went from [the most feared ticket] to routine. The lesson I took: in legacy code, earning trust with small safe wins comes before any big idea."


The first 90 days

Phase What I do Output
Weeks 1–2: learn Run it locally, read incidents and ADRs, pair with the longest-serving dev, ship a small fix Setup script, a map of the system, trust
Weeks 3–4: measure Churn × complexity hotspots, incident tags, build/deploy time, test coverage of hotspots A ranked list with evidence
Month 2: agree Show the data to the product owner and lead; agree a budget and 2–3 goals A visible plan with targets
Month 2–3+: improve Characterisation tests, extract and replace in small steps, automate the release Measurable change each sprint

How to choose what to fix first

Signal Tool Why it matters
Change frequency (churn) git log --format=format: --name-only counts, CodeScene Debt you never touch costs nothing
Complexity Visual Studio code metrics, NDepend, cyclomatic complexity Hard to change safely
Incidents per component Incident tracker tags, Application Insights failures Direct customer cost
Build/test/deploy time Pipeline history Taxes every change

When not to improve something

Code that is ugly but stable and rarely changed stays as it is. A rewrite is only worth considering when the platform itself is end-of-life or blocks the business, and even then it is done as a strangler fig, not a big bang.

Production example

"Over [six months]: release time [1 day → 45 minutes], hotfix rate [~25% → ~7%] of releases, pricing incidents [from about 4 a month to fewer than 1], with feature delivery [unchanged or up] on the team's burn-up."

🔍 What the interviewer is checking

Checks whether the candidate can get productive in an unfamiliar system, choose improvements by evidence, change it safely while delivery continues, and prove the result.

Green flags

  • A learning phase before changing anything, and respect for the previous team
  • Hotspots chosen with data (churn, complexity, incidents)
  • Characterisation tests and small, releasable steps
  • Got explicit buy-in and kept features flowing
  • Before/after numbers and a lesson

Red flags

  • "The code was awful, so we rewrote it"
  • Blaming the people who wrote it
  • No measurement of the result
  • Improvement work hidden from the product owner

📚 Learn in depth

1. What the interviewer is really assessing

  • Humility and learning speed: do you understand before you judge?
  • Prioritisation: do you use evidence, or personal taste, to pick what to fix?
  • Risk management: do you make change safe (tests, small steps, feature flags)?
  • Influence: can you get time for improvement from a product owner who wants features?
  • Respect: do you blame the previous team? Legacy code is usually code that succeeded.

2. The safe-change loop

  pick hotspot ──► pin behaviour ──► small refactor ──► release ──► measure
       ▲          (characterisation      (one seam,          (normal        │
       │           tests, approval       one rule)           pipeline)     │
       │           tests)                                                    │
       └────────────────────────────────────────────────────────────────────┘

Michael Feathers' definition is useful in the answer: legacy code is code without tests. The technique is to find a seam (a place where you can change behaviour without editing the code there, such as an interface or virtual method), get the code under test, then change it.

3. Patterns worth naming

Pattern Use it when
Characterisation (golden master) tests You don't know the correct behaviour, only the current one
Strangler fig Replacing a module or the whole app piece by piece behind a facade or YARP proxy
Branch by abstraction Swapping an implementation inside the codebase while trunk stays releasable
Boy-scout rule Small tidy-ups in files you're already changing for a feature
Feature flags Releasing the new path to a fraction of traffic first

4. Frameworks for telling it

  • STAR: Situation, Task, Action, Result. Default for this question.
  • CAR: Context, Action, Result. Shorter, good when the interviewer is pressed for time.
  • SOAR: Situation, Obstacle, Action, Result. Good when the obstacle (no tests, no buy-in) is the interesting part.

Spend about 15% on the situation, 60–70% on your actions, and finish with a result that has a number and a lesson.

5. How answers are scored

Score What it sounds like
Weak "The code was terrible so we rewrote it" or a list of patterns with no result
OK Sensible actions, but "we", no data on why those areas, vague result
Strong Learned first, chose by evidence, made change safe, kept delivery going, numbers before and after, a lesson

6. Reusing the story

The same story answers: "How do you handle technical debt?", "Tell me about getting buy-in", "How do you onboard to a new team?" and "Tell me about improving a system". Change the emphasis, not the facts: for buy-in, lead with the data and the product owner conversation; for onboarding, lead with the first two weeks.

Try it yourself

  1. Run a churn count on a repo you know: git log --since="12 months ago" --format=format: --name-only | sort | uniq -c | sort -rn | head -20.
  2. Cross it with complexity from Visual Studio's Analyze → Calculate Code Metrics, and pick your top three hotspots.
  3. Write five characterisation tests for one hotspot method using Verify snapshots.
  4. Write your STAR story with every number as a [placeholder], then fill in the ones you can prove.
  5. Tell it out loud in under two minutes, and again in 45 seconds for a CAR version.

💻 Code

Fill-in answer template (not code):

S  Joined [company] / [team]; system: [age, size, stack]; pain: [release time, hotfix rate, feared module].
T  [My role]: get productive fast and make [the system] safer and faster to change, without stopping features.
A  Weeks 1–2: ran it locally ([setup script]), read [N months] of incidents, shipped [small fix].
   Measured: churn × complexity + incidents → [top hotspots] behind [X%] of incidents.
   Agreed [~15%] of each sprint with [PO], tied to feature work.
   [N] characterisation tests on [hotspot]; extracted it in small steps; automated [release step].
R  After [period]: [release time A → B], [hotfix rate A → B], [incidents A → B]; features [kept pace].
   Lesson: [earn trust with small safe wins before big ideas].

Illustrative only (not a real history):

Joined a team with a 10-year-old MVC 5 app; pricing caused most incidents.
Hotspot analysis + 60 characterisation tests, then extracted pricing rule by rule over 6 months.
Hotfixes fell from ~1 in 4 releases to ~1 in 15; releases from a day to under an hour.

⚠ Common mistakes

  • Mistake: Opening with how bad the code was. Why it is wrong: sounds like blame and arrogance; that code paid everyone's salary. Instead: describe the business pain neutrally (slow releases, incidents) and respect the people who built it.
  • Mistake: "We rewrote it." Why it is wrong: big-bang rewrites are a known failure mode, and it signals poor risk judgement. Instead: describe incremental change (strangler fig, branch by abstraction) with delivery continuing.
  • Mistake: Changing things in week one. Why it is wrong: you don't yet know why things are the way they are. Instead: show a learning phase and a small first fix.
  • Mistake: Choosing what to fix by taste. Why it is wrong: the interviewer can't tell good judgement from preference. Instead: name the evidence: churn, complexity, incidents, build time.
  • Mistake: Saying "we" all the way through. Why it is wrong: hides your contribution. Instead: say what you measured, proposed, wrote and led.
  • Mistake: No result, or "it was much better". Why it is wrong: unverifiable. Instead: before/after numbers, even approximate ones you can defend.
  • Mistake: Too much jargon for a non-technical panel member. Why it is wrong: loses half the room. Instead: "releases went from a day to under an hour" lands with everyone.
  • Mistake: Rambling through the system's history. Why it is wrong: uses up the time you need for actions. Instead: one or two sentences of situation, then move on.

🏛 Senior insight: trade-offs

What makes this sound senior is judgement about where not to spend effort, and influence: you turned a vague feeling ("the code is bad") into evidence a product owner could act on, got a budget, and delivered results without stopping features. Mention what you deliberately left alone, and how you made the improvement stick (tests in the pipeline, an ADR, the team owning the hotspot list), so it doesn't depend on you.

A senior also looks at risk the business can't see. Legacy systems often run on out-of-support components (.NET Framework versions before 4.6.2, old NuGet packages with known CVEs, Windows Server versions past end of support), keep secrets in web.config, and deploy by hand. Running dotnet list package --vulnerable (or a Dependabot / Defender for DevOps scan), moving secrets to Azure Key Vault, and getting the release into an Azure DevOps or GitHub Actions pipeline with tests as a gate are often the highest-value first steps, and they map directly to the ACSC Essential Eight (patch applications, restrict admin privileges) and to APP 11 security obligations if personal data is involved. The modernisation path to .NET 10 (the .NET Upgrade Assistant, or a YARP-based strangler fig with System.Web adapters) comes after that, once the code is under test.

Measure with the four DORA metrics where you can (lead time for changes, deployment frequency, change failure rate, time to restore) plus a local one such as incidents for the hotspot. Numbers you can explain beat impressive numbers you can't.

Approach When it fits Cost When not to
Boy-scout tidy-ups with features Debt spread across actively changed code Low, continuous Hotspot too risky to touch without tests
Dedicated budget (10–20% per sprint) Clear hotspots with evidence Visible capacity trade-off No measurable target to report against
Pipeline and security first Manual releases, vulnerable or unsupported dependencies Days to weeks Already automated and patched
Strangler fig to .NET 10 Module or platform blocks the business Months; two paths run side by side Code is stable and rarely changed
Full rewrite Almost never; platform truly end-of-life and small enough Very high risk Almost always

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions writing characterisation or golden-master tests. Why: Checks that they know when characterisation tests are enough to refactor safely.
    How to answer

    Good enough means the tests would notice if your change broke something. Check three things. Coverage of the change area (not the codebase): every branch you'll touch is executed, including the input grid of any golden master, the set of input combinations whose outputs you snapshot, which should include boundary values. Sensitivity: run Stryker.NET on the changed files only (--since) and explain or kill surviving mutants, or break a line by hand and confirm a test fails. Reliability and speed: run the new tests repeatedly to prove they are deterministic, and keep them fast enough to run in the PR pipeline on every commit, because a safety net that is flaky or only runs nightly won't protect the change.

  2. When: Candidate mentions agreeing a budget for improvement work with the product owner. Why: Checks how they prioritise and get time for technical debt in general.
    How to answer

    Technical debt is the future cost of a shortcut, and the interest is the extra effort or risk it adds every time we work near it. I make it visible in a debt register with each item's impact, how often we pay its interest (change frequency, incidents, delays) and a rough cost to fix. I prioritise by interest, not by how ugly the code is: debt in a hotspot that slows every feature beats a messy module nobody touches. I get time by explaining it in business terms (lead time, incident risk, cost), by reserving a steady share of capacity, and by pairing debt fixes with features that touch the same area.

  3. When: Candidate mentions extracting code behind interfaces or static helpers and singletons. Why: Checks the technical depth of incremental refactoring in a legacy .NET app.
    How to answer

    I'd use a strangler approach, not a rewrite. First, characterisation tests around the code I'll touch first. Then a single composition root (the Generic Host in modern .NET, or ServiceCollection built in the old entry point) and a bridge: the legacy ServiceLocator.Get<T>() delegates to the real IServiceProvider, so old and new code share the same instances.

    From there I convert from the edges inwards: new code and any class I touch takes constructor dependencies; statics get thin adapters behind interfaces. I track locator call count as a metric and block new usages with an analyser.

    The trade-off: for months the codebase is half old, half new, which is uglier than a rewrite plan but keeps shipping.

🛠 Real-world problems: how you handle them

Making a feared legacy module safe to change
Situation
[Company]'s core [ASP.NET MVC 5 on .NET Framework 4.8] system, [~400k lines, 10+ years old], [N] developers. Releases took [a day], [~1 in 4] needed a hotfix, and [the pricing module] was the most feared area. I joined as [senior engineer].
Signals
Long manual release checklist; hotfix rate [~25%]; incident tags pointing at [pricing]; new joiners taking [2 days] just to run the app; estimates for pricing tickets padded [2–3×].
Investigation
Ran the app locally and scripted the setup; read [6 months] of incident reports; churn analysis from git history crossed with Visual Studio code metrics; hypotheses ruled out: [the database] (Query Store showed no regressions) and [infrastructure] (incidents were logic errors, not outages). [Three pricing files] were top-ten for both churn and complexity and behind [~40%] of incidents.
Resolution
Immediately: setup script and a release checklist moved into the pipeline. Then: [~60] characterisation tests (Verify snapshots) on pricing, extraction behind an interface one rule at a time, each step released normally; [15%] of each sprint agreed with the product owner and tied to feature tickets.
Prevention
Characterisation tests run in CI; hotspot list reviewed each quarter by the team; an ADR recording the incremental approach; DORA metrics on the team dashboard.

How to tell it (STAR)

**S:** When I joined [company], the core system was [a 10-year-old MVC app]; releases took [a day] and [one in four] needed a hotfix, mostly from [pricing]. **T:** As [senior engineer] I wanted to make it safe to change without stopping feature work. **A:** I spent [three weeks] learning: I scripted the local setup, read [six months] of incidents and shipped two small fixes. Then I crossed git churn with complexity and incidents, and showed [the product owner] that [three pricing files] caused [40%] of incidents. We agreed [15%] of each sprint. I wrote [60] characterisation tests, then extracted pricing rule by rule alongside features. **R:** After [six months], hotfixes fell from [one in four releases to one in fifteen] and releases from [a day to under an hour], with features still on plan. I learned to earn trust with small safe wins first.

More in Delivery and People

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me