What is technical debt and how to manage it?
Technical debt explained through its causes, principal, compound interest, visibility, prioritisation, repayment practices, and engineering habits that prevent new debt.
What is technical debt and how to manage it?
Every software team takes shortcuts. Sometimes it is a conscious decision to meet a deadline, sometimes it is lack of knowledge, and sometimes the requirement has changed and the design is not fitting anymore. These shortcuts are not free, we pay for them later with slower delivery, more bugs and frustrated developers. This hidden cost is called as technical debt. In this article, we are going to see what is technical debt, how it is created, why it is dangerous when it is not managed and how we can manage it in a practical way.
TL;DR Summary
- Technical debt is the future cost of choosing an easy solution now instead of a better one.
- Like financial debt, it has a principal (the work to fix it) and an interest (the extra effort we pay every day until it is fixed).
- Not all technical debt is bad, conscious and short-term debt can be a good business decision.
- Unmanaged debt slows down delivery, increases bugs and reduces the morale.
- Make the debt visible, prioritise it by interest, and pay it back regularly.
- Prevent new debt with engineering practices like code review, unit tests and CI.
Challenges
Invisible cost
The business sees the features, not the code. When the delivery is slowing down, the business only sees “the team is getting slower”. The real reason, which is the growing technical debt, is invisible to them. It is very hard to get the time to fix something which nobody can see.
Compound interest
Technical debt grows like a compound interest. One shortcut leads to another, because the new code has to work around the old shortcut. After a while, a simple feature which should take two days is taking two weeks, and nobody can estimate correctly anymore.
More bugs and longer MTTR
Messy code hides bugs. When the code is hard to understand, the fixes are also risky, and one fix creates two new bugs. When there is an issue in production, finding the root cause takes longer, hence the MTTR is increasing and the customers are impacted.
Team morale
Developers don’t like to work in a messy code base. They feel they can’t do good work. Over the period, the good developers leave and the knowledge goes with them, which makes the debt even worse.
What is Technical Debt?
Technical debt is the implied cost of additional rework caused by choosing an easy or limited solution now instead of using a better approach that would take longer. The term is coined by Ward Cunningham.
In simple terms, it is like taking a loan. You get the money (the feature) faster today, but you have to pay it back later with interest. If you keep paying only the interest and never the principal, the loan will never end, and at some point you can’t take any new loan at all.
- Principal - the effort needed to fix the shortcut properly.
- Interest - the extra effort we spend every time we work around that shortcut.
Types of Technical Debt
Martin Fowler describes the technical debt quadrant, which is useful to understand where the debt is coming from,
| Reckless | Prudent | |
|---|---|---|
| Deliberate | ”We don’t have time for design." | "We must ship now and deal with consequences.” |
| Inadvertent | ”What is layering?" | "Now we know how we should have done it.” |
- Deliberate and prudent debt can be a good business decision, as long as we plan to pay it back.
- Reckless debt is the dangerous one, it comes from ignoring the practices.
- Inadvertent and prudent debt is natural, we learn as the product evolves.
Here are some common forms of technical debt,
- Code debt - duplicated code, God objects, magic numbers, poor naming.
- Design debt - wrong layering, tight coupling, missing abstractions.
- Test debt - missing unit tests, manual regression only.
- Infrastructure debt - manual deployments, outdated frameworks and libraries.
- Documentation debt - missing or outdated documentation of APIs and architecture.
Why managing technical debt is important?
In order to keep the delivery speed predictable, to reduce the production issues and to keep the team motivated, we should manage the technical debt actively. It is not possible to have zero debt, and it is not even needed. The goal is to keep the debt at a level where the interest is not eating the team’s capacity.
How to manage Technical Debt?
Let us discuss the practical steps which we can follow.
1. Make it visible
The first step is to make the debt visible, both for the team and for the business. Create a work item for each known debt in the backlog, with a short description of the problem, the impact and the rough effort.
Example:
Debt: Fee calculation logic is duplicated in FundService, ReportService and ExportService. Impact: Every fee rule change needs three changes, last two releases had fee mismatch bugs. Effort: ~3 days to extract into a single FeeCalculator with unit tests.
Use code metrics (Visual Studio Code Metrics, or tools like NDepend and SonarQube) to support it with data, i.e. maintainability index, cyclomatic complexity and code coverage.
2. Talk in business terms
Business doesn’t care about “cyclomatic complexity”. They care about delivery speed, bugs and risk. Explain the debt in terms of its interest: “every change in pricing module takes 2x longer and caused <number> production issues in last quarter”. Then it becomes a business decision, not a developer wish.
3. Prioritise by interest
Not all debt needs to be paid. A messy module which nobody touches has almost zero interest, leave it. A messy module which changes in every sprint has a high interest, fix it first. Prioritise the debt where the code is changing frequently and where the bugs are coming from.
4. Pay it back regularly
Here are some approaches which work well,
- Reserve capacity - Keep a fixed percentage of every sprint for debt, i.e. 10-20%. It is predictable and doesn’t need negotiation every time.
- Boy Scout Rule - Leave the code better than you found it. When a feature touches a messy area, clean a small part of it as part of the feature.
- Pair with features - When a big feature is planned on a module, include the cleanup of that module in the estimate.
Avoid the “big rewrite” unless there is no other way. It takes longer than expected, the business gets no new features in the meantime and the new system starts with its own debt.
5. Prevent new debt
Paying back the debt is useless if we keep adding new debt faster. Engineering practices are the best prevention,
- Code review with a checklist.
- Unit tests and CI build on every commit.
- Coding standards and static analysis.
- Definition of done which includes tests and review.
Refer the “What is engineering practices and why do we need them?” article for detailed information.
6. Record deliberate debt
When the team decides to take a shortcut consciously, record it immediately with a work item and a // TODO comment which refers to it. Otherwise, the deliberate debt becomes forgotten debt.
// TODO: Work item <id> - temporary hard-coded fee for Index funds until fee rules are moved to database.
private const decimal IndexFundFeeRate = 0.002m;
Note: Keep in mind that the technical debt is a trade-off, not a sin. Taking a shortcut to catch a market opportunity can be the right decision. The problem is only when we don’t know we have the debt, or we never plan to pay it back.
Wrap up
In this article, we have looked at what is technical debt, the types of debt, why it is dangerous when unmanaged and how to manage it by making it visible, talking in business terms, prioritising by interest, paying back regularly and preventing new debt. Thanks for reading this article. In the next article, I will walk you through how to do TDD (Test-Driven Development).
Related Posts
Why we need Clean Code?
Why clean code matters, what makes code clean (meaningful names, small functions, guard clauses, comments that explain why) and how to bring the practice into your team.
What is a God object and how to break it?
God objects explained through their warning signs, causes, and a step-by-step refactoring approach using characterization tests, extraction, interfaces, and dependency injection.
Feature toggles - shipping unfinished code safely
Feature toggles explained through release control, toggle types, configuration, rollout, cleanup and practices for shipping unfinished code without accumulating debt.