"Tech debt giống nợ tài chính - một chút thì leverage, nhiều quá thì phá sản." - Ward Cunningham
1. Types of Tech Debt
Deliberate vs Accidental
Deliberate (Cố ý)
Accidental (Vô tình)
Biết là nợ
"Ship trước, refactor sau"
Không nhận ra đang tạo nợ
Ví dụ
Hardcode config để kịp deadline
Copy-paste code vì không biết có utility sẵn
Quản lý
Ghi vào backlog, plan trả nợ
Phát hiện qua code review, static analysis
Reckless vs Prudent
Reckless (Liều lĩnh)
Prudent (Cân nhắc)
Deliberate
"Không có thời gian design"
"Ship nhanh, biết phải refactor"
Accidental
"Design pattern là gì?"
"Giờ mới biết cách tốt hơn"
2. Tech Debt Quadrant (Martin Fowler)
Deliberate
│
┌─────────────┼─────────────┐
│ │ │
│ RECKLESS │ PRUDENT │
│ │ │
│ "We don't │ "We must │
│ have time │ ship now │
│ for design"│ and deal │
│ │ with │
│ │ consequences│
Reckless ─┼─────────────┼─────────────┼─ Prudent
│ │ │
│ "What's │ "Now we │
│ layered │ know how │
│ architecture│ we should │
│ ?" │ have done │
│ │ it" │
│ RECKLESS │ PRUDENT │
│ │ │
└─────────────┼─────────────┘
│
Accidental
Hành động theo quadrant
Quadrant
Action
Reckless + Deliberate
Stop. Training + code review cần thiết ngay
Reckless + Accidental
Đầu tư vào learning, pair programming, mentoring
Prudent + Deliberate
OK nếu có plan trả nợ rõ ràng trong backlog
Prudent + Accidental
Tự nhiên - refactor khi touch code (Boy Scout Rule)
3. How to Identify and Catalog Tech Debt
Detection Methods
Method
Tool / Approach
What it finds
Static Analysis
SonarQube, NDepend, Roslyn Analyzers
Code smells, complexity, duplication
Code Review
Pull request reviews
Design issues, naming, patterns
Architecture Tests
ArchUnitNET
Dependency violations, layer breaches
Runtime Monitoring
Application Insights, Datadog
Performance debt, memory leaks
Developer Feedback
Survey, retro, tech debt backlog
Pain points chỉ dev biết
Dependency Scan
Dependabot, Snyk
Outdated/vulnerable packages
Tech Debt Catalog Template
markdown
## Tech Debt Item: TD-042**Title:** OrderService God Class - 2,500 lines, 47 methods
**Category:** Design Debt
**Location:**`src/Services/OrderService.cs`**Created:** 2024-01-15
**Severity:** High
### Description
OrderService đảm nhiệm quá nhiều responsibilities: order creation,
validation, payment processing, inventory check, notification.
Vi phạm Single Responsibility Principle.
### Impact- Mỗi lần thay đổi 1 feature → risk regression feature khác
- Unit test coverage chỉ 35% vì quá phức tạp để mock
- Onboarding dev mới mất 2 tuần mới hiểu file này
### Proposed Solution
Tách thành: OrderCreationService, OrderValidationService,
PaymentService, InventoryService, NotificationService.
Apply Mediator pattern cho orchestration.
### Estimated Effort- 8-13 story points (2-3 Sprint nếu làm incremental)
- Cần regression test toàn bộ order flow
### Business Risk if Not Fixed- Feature velocity giảm 30% cho order-related stories
- Bug rate tăng mỗi Sprint (3 bugs/Sprint liên quan order)
4. Quantifying Tech Debt
Time Cost Measurement
Metric
Cách đo
Target
Interest Rate
Thời gian extra mỗi Sprint vì debt
Track qua Sprint retro
Fix Time Multiplier
Bug fix mất bao lâu so với expected
< 2x = acceptable
Onboarding Time
Dev mới mất bao lâu productive
< 2 tuần cho senior
Change Failure Rate
% deployments gây incident
< 15%
Lead Time Increase
Story completion time trend
Không tăng qua Sprints
Cost Formula
Annual Cost of Debt =
(Extra hours per Sprint due to debt) x
(Number of Sprints per year) x
(Average developer hourly rate)
Ví dụ:
5 hours/Sprint x 26 Sprints/year x $50/hour = $6,500/year per item
20 items in backlog = $130,000/year đang "trả lãi"
Risk Scoring
Debt Priority Score = Impact (1-5) x Frequency (1-5) x Effort_Inverse (5/effort_in_sprints)
Ví dụ:
- God Class OrderService: Impact=5, Frequency=5, Effort=3 Sprint
Score = 5 x 5 x (5/3) = 41.7 → HIGH PRIORITY
- Outdated logging library: Impact=2, Frequency=1, Effort=0.5 Sprint
Score = 2 x 1 x (5/0.5) = 20 → MEDIUM PRIORITY
5. Prioritization Framework
Tech Debt Decision Matrix
Prioritization Criteria
Tiêu chí
Weight
Low (1)
Medium (3)
High (5)
Business Impact
30%
No user impact
Slowdown
Feature blocked
Developer Productivity
25%
Minor annoyance
Adds 1-2h/week
Adds 1+ day/Sprint
Risk
25%
Low probability
Moderate probability
Ticking time bomb
Effort to Fix
20%
> 2 Sprints
1 Sprint
< 3 days
6. Tech Debt Sprint Allocation - 20% Rule
The 20% Budget
Dành 20% Sprint capacity cho tech debt và improvements: