Skip to content
Notifications
Clear all

ELI5: Technical debt. How does SonarQube calculate it, and is that number useful?

4 Posts
4 Users
0 Reactions
1 Views
(@kellyh)
Trusted Member
Joined: 1 week ago
Posts: 59
Topic starter   [#8592]

Technical debt is a powerful metaphor, but its quantification often feels abstract. SonarQube attempts to make it concrete, and its methodology is both insightful and, in my view, flawed for direct project management use.

SonarQube calculates technical debt primarily through its concept of the **"Clean Code" principle**. It breaks down debt into three key metrics, which are then translated into time:

1. **Reliability:** Bugs and potential vulnerabilities. Each has a defined "remediation effort" (e.g., `BLOCKER` = 120 minutes, `CRITICAL` = 60 minutes).
2. **Security:** Vulnerabilities, weighted similarly.
3. **Maintainability:** This is the most complex component. It's based on "Code Smells." The effort here is derived from the **"Debt Ratio,"** which compares the cost to fix all code smells against the cost to write the code from scratch. The formula is essentially:
`Technical Debt = (Cost to Fix Code Smells) + (Cost to Fix Bugs/Vulnerabilities)`

The final output is a **time-based figure**, like "5 days, 3 hours," representing the estimated effort to fix all issues to meet SonarQube's quality gate.

So, is the number useful?
* **As a trending indicator:** Yes. Watching this number increase or decrease over sprints can signal if you're accumulating or paying down debt.
* **As an absolute, project-management metric:** No, and here's why:
* The remediation times are standardized and don't account for context. Fixing a "Blocker" bug in a simple service vs. a legacy monolith takes vastly different effort.
* It assumes all technical debt is of equal priority, which is never true. A minor code smell in a rarely-touched module is not the same as a security flaw in a core authentication service.
* It cannot capture architectural debt, which is often the most costly.

I find the number most useful when combined with other views. For example, focusing the "debt" lens specifically on **new code** introduced in the last 30 days gives a far more actionable metric for a development team. It tells you if your current pace is sustainable.

- kelly


Data is not optional.


   
Quote
(@devops_grunt)
Estimable Member
Joined: 4 months ago
Posts: 159
 

Agree on it being a flawed project management metric. The time estimate is a fantasy if your team hasn't actually validated those remediation efforts against your specific codebase. I've seen teams panic over a "2-week" debt number that was really just a thousand duplicated lines in generated protobuf files - trivial to fix, but it skewed everything.

Where it *does* work is in the pipeline. You can set a quality gate to fail a build if new code introduces a "BLOCKER" bug or security vulnerability. That stops new debt from piling on. The aggregate number is noise, but the per-issue severity and type are actionable.


Automate everything. Twice.


   
ReplyQuote
(@devops_shift_worker)
Estimable Member
Joined: 2 months ago
Posts: 104
 

Yeah, the trending indicator is about the only thing I'd trust from that number. Watching it go up or down over time tells you something. The absolute value? Not so much.

> "Technical Debt = (Cost to Fix Code Smells) + (Cost to Fix Bugs/Vulnerabilities)"

That formula breaks down fast when you hit a thousand generated files or a massive auto-formatter change. The "cost to fix code smells" in SonarQube is just a lookup table of default hours per rule. It doesn't know your team's velocity, doesn't know if that smell is a genuine headache or a nitpick from a config you can't change.

I've seen a "2 week" debt number that was 90% from a single rule flagging long variable names across a legacy monolith. Refactoring that would have introduced way more risk than the debt claimed. The team spent more time arguing about the number than actually fixing anything useful.

Where I do find it practical: treat the SQALE rating (the letter grade) as a canary. If you drop from A to B in a sprint, you probably shipped something sloppy. But the time estimate? I'd rather spend that brainpower reading the actual issues list.


NightOps


   
ReplyQuote
(@ci_cd_mechanic_7)
Estimable Member
Joined: 3 months ago
Posts: 108
 

Good breakdown. You're right about the project management flaw.

The trending indicator only works if you *never* change the analysis scope or rule profile. Adding a new microservice or turning on a new security rule will spike the "debt" instantly, breaking the trend. It's a lagging indicator of your own configuration choices as much as code quality.

The time figure is worse than useless, it's dangerous. Management sees "5 days" and asks why we haven't fixed it. They don't see that it's 2 days of trivial renaming and 3 days of rewriting a core, stable module because of a complexity rule.



   
ReplyQuote