Every dbt project that works will grow, and every growing project accumulates the same residue: the monolith model that began as a quick answer and quietly became load-bearing; the definition placed in the wrong layer before the team knew better; the name that made sense for the first consumer and misleads the fifth. This is technical debt, and it is not failure. It is the normal result of learning — the project discovering, later, what it should have built earlier.

The discipline is not to avoid debt. It is to refactor deliberately, and a refactor has a strict definition: change the project's internal structure while holding its external promises — grains, definitions, published columns — exactly constant, so consumers cannot tell the work happened, except that the project got easier to change next time.

Three kinds of change, and the disaster is confusing them

That constancy is what separates a refactor from the other two kinds of change a project undergoes. A refactor changes structure, not meaning: extract this logic into an intermediate model, rename this model to the convention, split this monolith at its natural seam. Its proof is equivalence — the rebuilt models produce the same results on the same inputs, verified by comparing outputs before and after, a comparison that separate environments make safe to run side by side.

A definition change is different in kind, however small it looks. It changes meaning, so it is not a refactor: it ships through the release and exposure machinery, with consumers consulted before it lands. A deprecation is different again: it removes a promise, and it follows its own sequence, because consumers are holding addresses that are about to stop working.

Most refactoring disasters are category errors. A meaning change gets smuggled inside a structural change, reviewed as plumbing, and shipped without the consumer consultation a meaning change requires. Nobody intended the harm; the ticket simply said "refactor," and the review proceeded on a refactor's lighter standard. So review's first question on any large diff is taxonomic: does anything a consumer can observe change? If yes, the change is not only a refactor, and it does not travel on a refactor's ticket.

Big restructures are chains of small, safe steps

Sequence is the refactor's craft. Large restructures are not performed in one heroic merge; they are done as a chain of small, individually safe steps, each merged on its own green build. The pattern has four moves: introduce the new intermediate model alongside the old path; point one consumer at it and compare; migrate the rest; then retire the old path by the deprecation sequence. Parallel run, compare, migrate, retire. The pattern scales from a single model to a rebuild of an entire layer, because each step leaves the project working and provably equivalent to where it started.

Renames obey the same pattern. A published model's name is an address consumers hold, so a rename is executed as a move with a forwarding period, never as a disappearance. Where the tooling offers deprecation and versioning features for models, the team uses them and verifies their current behavior. Tools change; the sequence is the durable part.

Debt is a portfolio, and its interest decides when to pay

Debt management, finally, is a portfolio decision, and it should be made explicitly rather than by mood. Keep a short, visible list of the project's known debt — the monolith, the misplaced logic, the tired name — and state each entry's interest payment: what the debt costs, in slower changes, recurring confusion, or incident risk, each time the team touches that area. The interest is what justifies the work, and stating it turns an argument about tidiness into an argument about cost.

The rule for timing follows. Refactor when the interest comes due — when a planned change enters the indebted area — rather than in separate purification campaigns the business will never fund. Debt with no interest, an ugly model nobody touches, can wait indefinitely, and saying so is also part of the discipline. Refactoring is an investment, justified by the changes it makes cheaper, never a moral cleanup.

This corrects the common dismissal that refactoring is self-indulgent — that the models work and rewriting working SQL risks breaking them for tidiness. The objection rests on a confusion the definition forbids: a refactor that changes results is not a refactor; it is an uncontrolled change. The work is the removal of measured friction — the monolith every change must tiptoe around, the logic in a layer that makes its tests impossible. Teams that never refactor do not preserve their working system. They preserve its first draft, and pay interest on every change until the project becomes the thing nobody dares touch.

Torvane's returns logic: the trade, made on the record

Torvane's scheduled debt makes the trade concrete. Its returns logic was written early, inside a mart, before the intermediate layer existed. It is serviceable and tested at the mart level — and it is now touched by a planned returns-reason improvement. The improvement's change plan therefore carries the refactor as its first phase: the logic is extracted to an intermediate model, at its own grain, with its own tests; outputs are compared line by line against the mart's current results across a full quarter; and only then is the improvement itself built on the clean structure.

The business gets its improvement a few days later than a hack inside the mart would have delivered it. In exchange, every returns change after this one gets cheaper, permanently. That trade is worth making only when it is made visibly and on the record, with the interest stated and the equivalence proved: the plumbing changes, the house never drains, and nobody downstream can tell anything happened at all.

Experience it, don’t just read about it

A refactor changes internal structure while holding grains, definitions, and published columns exactly constant is Concept 16 of Analytics Engineering with dbt: Model Data the Way Software Ships (Course No. 430), from Cognosco Learning, a learning company powered by AI. The course builds analytics engineering beyond this distinction — Tests as Contracts, Exposures and Ownership, and Metrics and the Semantic Layer — each worked through with an Agentic Socratic AI coach, one learner at a time. Try a Free Preview at cognoscolearning.com.

Try a Free PreviewAll Signature CoursesThe Corporate License

Navigate your own course.

← All Insights

© 2026 Cognosco Learning. All rights reserved.