Mental Models204 cards · 12 fields

Mental Models/Computing & Information

Technical Debt

技术债

A shortcut you take today charges interest on every change you make later.

To save effort during a renovation, you leave the old wiring in place and just cap off the ends, and nothing seems wrong. But one day an electrician replacing a switch connects the wrong wire, and the old stretch of wire inside the wall suddenly goes live.

On August 1, 2012, a piece of old program like that woke up in the trading system of Knight Capital, a US trading firm. It had been retired in 2003 but never deleted, and a new feature written later reused its old on-switch. A few days earlier, the technical staff had updated the software on eight servers, missed one, and nobody double-checked.

When the US stock market opened, the switch was turned on. Seven servers started running the new feature, but the server that missed the update still had the old program, so the old program woke up. It was supposed to stop once enough of its orders had been filled, but that check had been broken long before, in a later change, so it sent orders to the market without a moment's pause. The system was shut down only after about 45 minutes, by which time the firm had lost more than 460 million dollars. Over the years, every change to this system had needed someone to remember that old program and that switch. This time nobody did, and the interest that had built up was paid all at once.

After dinner you're tired, so you leave the frying pan soaking instead of washing it, saving 10 minutes. The next day, to fry an egg, you first have to scrape off a layer of grease, which takes 5 extra minutes; by evening the grease is harder, and washing the pan takes 20 minutes. Technical debt in software works the same way: you take a shortcut to launch on time, and after that every change has to go the long way round, and the longer it piles up, the harder it is to clean up. In 1992 Ward Cunningham compared this to borrowing: the work a shortcut saves is borrowed money, each detour is interest, and a thorough cleanup is paying back the principal.

Weekly changes eat the 4 days saved in 8 weeks
Weeks to use it up8 wks
Extra per year26 days
010203001020304050WeeksExtra days, totalInterest so far4 days saved at first
010203002040WeeksExtra days, totalInterest so far4 days saved at first

Customer data in 3 tables saved 4 days; each change now costs an extra half day. Drag to 2 changes a year: 1 day of interest a year, so the debt can wait.

Work you owe charges interest every time you make a change

To launch on time, you scatter the same customer data across three tables, saving 4 days of organizing. From then on, every time one item of customer data changes, all three tables have to be checked against each other, which takes an extra half day. If it changes only 2 times a year, the interest is just 1 day, far less than the 4 days saved, and leaving the debt is fine. If it changes once a week, 8 half days make 4 days: after 8 weeks the savings are used up, and every change after that is a net loss.

The more that's built on top, the bigger the principal

The longer the debt is owed, the more reports pull data from the messy customer tables. They all have to be changed during the cleanup, with care taken not to miss any, so a thorough cleanup grows from 4 days to 6. Checking and fixing errors fill up all the time, so the team has to rush progress with more temporary patches, and new debt keeps being left behind.

Before you borrow, write down how you'll pay it back

When delivering early wins you orders, cash or key feedback, a limited debt is worth taking on. When you borrow, note down what you left undone, who will pay it back, and what signal means it's time to act. Pay back first the spot that changes most often and breaks most often; that's where the interest is highest.

The metaphor is most useful when a system has to live for several years and the same spot has to be changed again and again. A one-off script that is thrown away after it runs has no later changes, so it has no interest. Calling all the ugly code a predecessor wrote technical debt is a different use of the term: ugly code that nobody touches again doesn't owe anyone anything.

Explain
See why the same feature that took two days last year now drags on for two weeks: the shortcut taken back then has piled up interest with every change since.
Communicate
Make clear to a boss who doesn't write code why new features should pause for two weeks: those two weeks pay back the principal, and without that, the interest keeps being paid every month.
Predict
When scheduling a new feature, if it touches that old piece of unpaid debt, first add time for the detours and the checking.
  1. What did this shortcut save today, and what specific piece of work does it leave for later?
  2. Look through the commit history: how many times has this code been changed in the past six months, and how much extra time did the old way of writing it cost each time?
  3. Are the orders or feedback that early delivery bought worth this principal plus interest?

Business operations

Old crew scheduling slows the recovery

In late December 2022, winter storms threw Southwest Airlines' flights into disorder. The company's crew-scheduling technology and processes couldn't keep up with so many changes so fast, so schedulers switched to handling them by hand, recovery was slower still, and in the end more than 16,700 flights were canceled. The pilots' union had already warned that the scheduling technology was out of date.

Investing

The rent covered up the leak

You bought an old apartment to rent out, and the roof leaks. To protect that year's cash flow, you only repainted inside and kept collecting rent. In the second year water had soaked into the wall and damaged it; replacing it means three months with no rent, and the whole wall has to be redone.

Personal learning

Memorizing question types to pass the exam

When you studied statistics, you only memorized the question types in the chapter on conditional probability, and you still passed the exam. Half a year later you read a medical checkup report: it's the same calculation of the chance of having a disease, but asked a different way, and you can't do it. You have to go back and relearn that chapter, and from then on, every time you meet a probability question, you have to check your notes first.

You lead a four-person team that maintains the back office of a neighborhood group-buying app, where neighbors pool their orders. Two pieces of old code were left from rushed work back then, and this quarter there's only time for one person to clean up one of them. Over the next 26 weeks, the order-pooling rules module is expected to be changed 52 times, each costing 1 extra hour because of the old code; the finance reconciliation module is expected to be changed 6 times, each costing 3 extra hours. Cleaning up the order-pooling rules takes 3 working days (24 hours); cleaning up reconciliation takes 2 working days (16 hours).

Cleaning up only one, how do you save the most total hours over these 26 weeks (counting the cleanup itself)?

You want to buy a small shop that prints wedding invitations. To save on upgrading equipment, the seller has always used an old fixture that can only be positioned by hand, so every switch to a new design takes 2 extra hours of machine setup. In the past the shop took only big orders of a single design and switched designs only twice a month. You plan to take small orders of many designs instead, expect to switch designs 20 times a month, and will replace the old fixture after one more year, at a cost of 30,000 yuan. Labor and lost machine time during setup together cost 100 yuan an hour.

In the first year, how much will this old fixture cost you in total?

You are the product lead of a three-person team. On Friday morning a pilot customer wants to see a working demo, and they've said that if they don't see it on Friday, they'll go elsewhere. The only way to make it is to hard-code the customer's pricing rules straight into the code, saving 3 days; building a configurable version would push the demo to next week. If the pilot succeeds, a dozen or more customers will follow, each with different rules.

What's best for the team to do now?