Technical Debt Management and Refactoring Questions
Identifying, prioritizing, and paying down technical debt sustainably. Covers recognizing debt, making the case to invest in it, refactoring safely behind tests, and balancing debt reduction against feature velocity. Includes keeping a codebase maintainable over the long term.
Define test debt as a category of technical debt, and describe two practical tactics to reduce it quickly, such as targeted automation of the highest-risk paths and enforcing a test-pyramid shape. Explain how you would decide which tests to automate first.
Sample Answer
Direct answer
Test debt is the accumulated gap between the tests a codebase needs and the tests it has: missing coverage, brittle or flaky tests, and tests that pass without meaningfully verifying behavior. Two fast, practical tactics to reduce it: automate the highest-risk paths first rather than chasing a blanket coverage number, and enforce a test-pyramid shape (many fast unit tests, fewer integration tests, very few slow end-to-end tests) so the suite stays fast enough that people don't start skipping it.
Structured elaboration
- Targeted automation of critical paths: rank untested code by a combination of change frequency and business criticality (a checkout flow beats an admin settings page), and automate tests there first; this delivers risk reduction per engineer-hour far faster than chasing overall coverage percentage.
- Enforce the test pyramid: audit the current suite's shape (count of unit vs integration vs end-to-end tests and their respective run times); if end-to-end tests dominate, they're slow and flaky by nature, which erodes trust in the whole suite and is itself a source of NEW test debt as people start skipping or ignoring red builds.
Deciding what to automate first: score candidate areas on (a) how often the code changes (higher change frequency = higher risk of a regression slipping through) and (b) business criticality (revenue-path or compliance-relevant code outranks internal tooling), and start with the intersection of both being high.
Worked example
A codebase's untested areas: an admin-only reporting page (rarely changes, low criticality) and the checkout discount-code logic (changes almost every sprint, directly revenue-relevant). Despite the admin page having zero coverage and the checkout logic having partial coverage, the checkout logic is the higher-priority automation target, since its change frequency and criticality both point to it as the place most likely to regress silently and cause real damage.
Trade-offs & pitfalls
Chasing a blanket coverage percentage target ("get to 80% everywhere") often produces the OPPOSITE of risk reduction: teams write low-value tests against low-risk code to move the number, while the highest-risk, highest-change-frequency code stays under-tested because it's harder to test well. Targeted, risk-based automation is slower to show a clean percentage but faster to reduce real incident risk.
You have three debt items with estimates: flaky tests causing 10% weekly CI failures; missing data validation causing 1% production failures; and duplicated preprocessing code across services costing extra maintenance time. Given limited engineering time, prioritize these three items and justify your ordering with metrics and explicit business-impact assumptions.
Sample Answer
Direct answer
Of the three, prioritize the missing data-validation issue first: it has the smallest realized-impact footprint (1% of production runs) but the highest severity per occurrence (a silent correctness failure feeding downstream decisions), followed by the flaky tests (high frequency but bounded, non-customer-facing impact), and the duplicated preprocessing code last (a real cost, but a maintenance tax rather than an active failure mode).
Structured elaboration
Score each on severity-if-it-fires versus frequency, not on frequency alone:
| Item | Frequency | Severity per occurrence | Business-impact reasoning |
|---|---|---|---|
| Missing data validation | 1% of production runs | High: silently corrupts model inputs, may not be caught until a downstream metric looks wrong | Correctness failures compound quietly; a 1% rate against high production volume is still a meaningful absolute count, and each one can propagate into a business decision before anyone notices |
| Flaky tests | 10% of weekly CI runs | Medium: blocks developer velocity, but doesn't reach production | Costs real engineer time (re-running, investigating false failures) but has a natural ceiling on damage, since it's caught before deploy |
| Duplicated preprocessing | Constant (every maintenance touch) | Low-medium: extra effort per change, risk of the two copies silently diverging over time | A tax on every future change, not an active incident risk today, so it compounds slowly rather than causing acute harm |
Worked example
Assume 50,000 production inference runs/week: 1% missing-validation failures means roughly 500 potentially-corrupted runs weekly, each with a real (if hard to quantify precisely) chance of a bad downstream decision, versus the flaky tests costing an estimated 5 engineer-hours/week in wasted re-runs and investigation, and the duplicated preprocessing costing perhaps 2 extra engineer-hours per unrelated change (rare, but recurring). The data-validation issue wins because its downside is a silent CORRECTNESS failure with unbounded downstream cost, while the other two are bounded, visible, recoverable costs; this is the same logic that puts a rare-but-catastrophic risk ahead of a frequent-but-contained one.
Trade-offs & pitfalls
A naive read might rank by frequency alone and put the 10%-frequency flaky tests first; the corrective insight a strong candidate volunteers is that frequency times bounded-severity can still be less costly than a low-frequency, unbounded-severity failure mode, especially one (silent data corruption) that resists detection by construction.
Identify the common sources of technical debt in a software organization. For each source, give a practical indicator or metric you would monitor to detect it early, and a simple detection method you could run against an existing codebase.
Sample Answer
Direct answer
Technical debt in a real organization comes from six recurring sources: rushed delivery under deadline pressure, deferred upgrades, missing tests, duplicated solutions, knowledge loss from turnover, and shortcuts taken without a repayment plan. Each has its own early-warning signal, so detecting them requires more than one metric.
Structured elaboration
| Source | Early indicator | Detection method |
|---|---|---|
| Rushed delivery | Spike in hotfixes shortly after a release | Correlate deploy dates with incident timestamps |
| Deferred upgrades | Dependencies several major versions behind | Automated dependency-audit scan (e.g. npm outdated, pip list --outdated) run on a schedule |
| Missing tests | Coverage trending down on recently-changed files | Coverage-delta check per PR, not just a global number |
| Duplicated solutions | The same logic appears with small variations across files/services | Static duplication detection (e.g. jscpd, PMD CPD) |
| Knowledge loss | One person authors the majority of commits to a module, then leaves | Git blame / commit-author concentration analysis per module |
| Undisciplined shortcuts | "TODO" / "FIXME" / "HACK" comment density rising | Grep-based comment audit, tracked over time |
Worked example
A quarterly audit of a mid-size codebase finds: 40 unresolved TODO/FIXME comments concentrated in the billing module (undisciplined-shortcut signal), the billing module's primary contributor left the company two months prior with no documented handoff (knowledge-loss signal), and npm outdated shows the payment SDK is three major versions behind (deferred-upgrade signal). All three point at the same module, which is exactly the kind of correlated signal that should escalate a module from "routine backlog item" to "priority review," even though no single metric alone would have triggered that.
Trade-offs & pitfalls
A single detection method catches only its own blind spot: static duplication detection misses semantically duplicated logic written differently, and commit-author concentration can flag a module that's simply owned by a specialist by design, not one that's actually at knowledge risk. Combine at least two independent signals before escalating a module, rather than acting on any single metric in isolation.
Explain technical debt using the principal-and-interest loan analogy, then distinguish intentional (strategic) debt from accidental (unintentional) debt. For each, give one concrete example of how it accumulates and name which stakeholder group typically introduces or first notices it.
Sample Answer
Direct answer
The loan analogy: technical debt has a principal (the corners cut to ship faster) and interest (the ongoing tax you pay in extra effort every time you touch that code until the principal is repaid). Martin Fowler's technical debt quadrant then splits debt along two axes: deliberate versus inadvertent, and reckless versus prudent. Reckless debt is a shortcut taken without understanding or caring about the consequences (skipping error handling entirely because nobody thought about what happens when a call fails, for example); prudent debt is a deliberate, informed trade-off made with eyes open, like the hardcoded-ranking-weight example below. The distinction that matters most day to day is intentional (strategic) debt versus accidental (unintentional) debt.
Structured elaboration
Intentional (strategic) debt is a conscious trade-off: the team knows a shortcut is being taken, why, and (ideally) has a repayment plan. Accidental (unintentional) debt is debt nobody chose, it emerged from evolving requirements, from not knowing a better approach at the time, or from the codebase outgrowing its original design.
| Intentional / strategic | Accidental / unintentional | |
|---|---|---|
| Example | Hardcoding a config value to hit a launch date, with a ticket filed to fix it | A module designed for 10 users now serving 10,000, and nobody planned for the scale shift |
| Who typically introduces it | Engineering + product, jointly, under deadline pressure | Any engineer, often without realizing it, as requirements evolve |
| Who typically first notices it | The same team, since they wrote the ticket | A different engineer months later, debugging something unrelated |
| Interest rate | Usually known upfront (the team estimated the cost of the shortcut) | Usually discovered too late (the interest was compounding silently) |
Worked example
A team ships a recommendation feature using a single hardcoded ranking weight instead of the planned configurable weighting system, to hit a launch date. That's intentional debt: product and engineering both signed off, and a ticket exists to build the real system next quarter. Separately, the same codebase's user-profile module was designed assuming one profile per user; eighteen months later, a business-account feature needs multiple profiles per organization, and half the codebase implicitly assumes the one-profile invariant. Nobody "chose" that debt; it's accidental, and it's usually more expensive to unwind because it's woven through more of the system before anyone notices.
Trade-offs & pitfalls
The common mistake is treating all debt as accidental (a moral failure to avoid) or all debt as intentional (a lever always available). In practice a large majority of real debt is accidental, which is exactly why passive vigilance (waiting to notice it) fails; you need active detection (metrics, architecture reviews) because accidental debt does not announce itself the way a filed ticket does.
Your team has limited time and a backlog of technical debt in model code and data pipelines. Describe a practical prioritization framework to decide which items to fix first, including the criteria you would weigh, short-lived mitigations, and how you would communicate priorities to product and PM stakeholders.
Sample Answer
Direct answer
Prioritize debt in model code and data pipelines with the same impact/incident-probability/usage/effort criteria used generally, adapted for ML: weight incident probability heavily for anything touching training or serving correctness, since a silent data or model bug can propagate into decisions long before anyone notices.
Structured elaboration
- Criteria: impact (how many downstream consumers or business decisions depend on this pipeline/model), probability of causing an incident (data pipelines with manual, undocumented steps are higher-probability failure points than well-tested ones), usage frequency (a pipeline that runs daily carries more compounding risk than one that runs quarterly), and effort to fix.
- Short-lived mitigations: for items too large to fix immediately, add a lightweight guardrail (a sanity-check assertion on output ranges, an alert on a key statistic drifting) that catches the SYMPTOM of the underlying debt without fixing the root cause, buying time without accepting silent risk.
- Communicating to product/PM stakeholders: translate technical debt items into business-facing risk ("this pipeline feeding the recommendation model has no data validation, meaning a silent upstream schema change could degrade recommendations for weeks before anyone notices") rather than technical jargon ("we lack schema validation").
Worked example
Three candidate items: (1) a daily-run feature pipeline with no data validation, feeding a customer-facing recommendation model (high usage, high impact, currently no guardrail); (2) a manual, undocumented monthly retraining process for a lower-traffic internal model (lower usage, but high probability of human error); (3) duplicated preprocessing code across two services (moderate effort to fix, low direct incident probability, mostly a maintenance tax). Prioritization: item 1 first (highest impact times usage times current lack of any guardrail), a short-lived mitigation (a basic schema-drift check) added immediately while the full validation framework is scheduled; item 2 second (lower usage but genuinely high human-error probability, and the fix, documenting and partially automating the process, is relatively cheap); item 3 last, since it's a real but slower-compounding cost with no acute incident risk.
Trade-offs & pitfalls
The risk-based ranking here would look wrong to someone reading effort alone (item 3 might be the cheapest and most tempting to knock out first), which is exactly the trap: cheap-and-easy should never automatically outrank a high-impact, currently-unguarded, silent-failure risk like item 1, even though item 1 requires more sustained effort to fully resolve.
Unlock Full Question Bank
Get access to all 19 Technical Debt Management and Refactoring interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.