Strategic Software Design: Invest in the Code You Need Today

A customer sees one total in the cart and a different total on the invoice. Both calculations can look perfectly reasonable in isolation. They disagree because a business rule has more than one implementation.

Take a small, illustrative checkout system that sells seats at a fixed price. It already offers a volume discount, calculated separately in the cart, the order endpoint, and invoice generation. The next feature is a discount for eligible nonprofits. The product rule is simple: give the larger discount; do not stack them.

An engineer could add the new condition in all three places. Or they could first give the existing calculation one implementation and migrate its callers. The second option takes additional work now. It also needs a better justification than “this would be cleaner.”

This is the everyday choice behind strategic software design: complete the current feature while deciding which obligations to remove from the next change. The challenge is choosing an investment small enough to finish and useful enough to defend, without building a speculative pricing platform.

We will work through the TypeScript calculation, the migration, and the boundaries it must preserve. The goal is a reviewable decision about today's repeated rule, including what to do when the release cannot accommodate the whole improvement.

On this page

The Shortcut Is Often Locally Reasonable

Suppose the application sells one kind of seat at a fixed unit price. An order of ten or more seats receives a ten-percent volume discount. The current calculation appears in several request paths:

function existingTotalCents(unitPriceCents: number, quantity: number): number {
  const subtotalCents = unitPriceCents * quantity
  const discountPercent = quantity >= 10 ? 10 : 0
  const discountCents = Math.round((subtotalCents * discountPercent) / 100)

  return subtotalCents - discountCents
}

The new requirement gives eligible nonprofits twenty percent off. Discounts do not stack; the customer receives the larger applicable discount.

A local patch looks straightforward:

const discountPercent = nonprofit ? 20 : quantity >= 10 ? 10 : 0

There is nothing inherently confusing about that expression. The problem is the obligation to reproduce it correctly in every place that independently determines a price. Tests may cover the cart while a less frequently exercised invoice path retains the old rule.

The choice gets harder near a deadline. Three familiar edits look easier to review than a new shared function plus a caller migration. “We can consolidate it later” can be a reasonable description of a temporary compromise. It becomes a problem when every pricing request makes the same compromise.

Repeatedly choosing the local patch can produce a tactical development pattern. Each task contributes a small complication. Later work encounters those complications and adds another workaround because removing them appears too expensive for the current task.

The relevant unit is the repeated decision, not the character of the engineer making it. A planning system that rewards only immediately visible feature completion gives people a practical reason to defer improvements whose benefits appear in subsequent changes.

Choose an Investment That Completes the Current Mechanism

For this requirement, a bounded investment is to establish one pricing calculation and move the existing price-producing paths to it.

That is already enough work to require care. There is no need to add a rule language, plugin registry, coupon service, or administrator-authored pricing engine to demonstrate strategic thinking.

Here is a possible calculation for the deliberately limited example:

type PricingInput = {
  unitPriceCents: number
  quantity: number
  nonprofit: boolean
}

type Quote = {
  subtotalCents: number
  discountPercent: number
  discountCents: number
  totalCents: number
}

function calculateQuote(input: PricingInput): Quote {
  const subtotalCents = input.unitPriceCents * input.quantity
  const volumePercent = input.quantity >= 10 ? 10 : 0
  const nonprofitPercent = input.nonprofit ? 20 : 0
  const discountPercent = Math.max(volumePercent, nonprofitPercent)
  const discountCents = Math.round((subtotalCents * discountPercent) / 100)

  return {
    subtotalCents,
    discountPercent,
    discountCents,
    totalCents: subtotalCents - discountCents,
  }
}

The inputs in this example are validated upstream: a nonnegative integer price and a positive integer quantity within the application's supported limits. Intermediate arithmetic must remain safely representable. The calculation concerns one currency and one line item; taxes, currency conversion, refunds, and payment processing are outside this example.

Returning the breakdown makes an existing product need explicit. The cart and invoice can display the same subtotal, discount, and final total without separately reconstructing the calculation.

For ten seats at 1,000 cents each, an ordinary customer receives a 1,000-cent discount and pays 9,000 cents. An eligible nonprofit receives a 2,000-cent discount and pays 8,000 cents. These are arithmetic examples, not production measurements.

This implementation improves a mechanism already required by the product. Its value does not depend on guessing which promotion the business might introduce next year.

Improve the Current Design Without Speculating About Features

Strategic investment and YAGNI can support the same decision.

YAGNI challenges functionality built for hypothetical requirements. Continuous design investment asks whether implementing today's functionality is making today's system harder to maintain than necessary.

In the pricing example, the requirement already demands consistent discount behavior across several consumers. Consolidating that behavior addresses a present obligation. A generic pricing workflow editor would need a separate argument based on actual product requirements.

A useful boundary is to state the improvement in terms of a problem that exists:

The same pricing decision is implemented three times. This change will give those paths one calculation and preserve their current request and persistence behavior.

Contrast that with a promise that the design will support every conceivable promotion. The second statement has no clear completion point, and the current feature provides little evidence for choosing such a broad mechanism.

An investment should have a finish line. For this one, the calculation owns the agreed discount rules, the existing callers use it, and tests describe the supported cases. That is sufficient to review without requiring a prediction of the whole product roadmap.

Migration Is Part of the Investment

The engineer now has a shared calculation. The pull request can still leave the original problem intact: cart, order, and invoice may continue producing their own totals beside it. Shipping the helper is not the finish line.

A practical implementation sequence could be:

  1. Record the current supported prices and rounding behavior in focused tests.
  2. Move the existing volume calculation into the shared function.
  3. Replace each existing calculation and check that behavior is preserved.
  4. Add nonprofit eligibility and the non-stacking rule.
  5. Check the breakdown at the actual purchase and invoice boundaries.

Separating behavior-preserving movement from the new rule makes review easier. It gives reviewers a way to see whether an unexpected difference comes from migration or from an intentional business change.

The sequence also exposes product questions that code movement cannot answer. Should an invoice retain the price agreed when an order was placed, or recalculate against current policy? Usually an historical invoice needs its recorded amounts, but the correct rule belongs to the product's financial contract. Consolidating code must not silently replace that contract with recalculation.

Similarly, a browser may use a calculation for a preview, but the server must establish the authoritative quote using trusted prices and eligibility. Shared code does not make browser-supplied totals trustworthy, and separately deployed consumers can still run different versions.

These boundaries matter because an investment can accidentally expand while looking like cleanup. Preserve existing contracts unless changing them is an explicit part of the requirement.

Make the Tradeoff Visible in the Work

Design investment is easier to discuss when a review identifies both its immediate cost and its removed obligation.

For example:

  • Current risk: three price-producing paths must agree on discount precedence and rounding.
  • Additional work: migrate those paths to one calculation and check their existing behavior.
  • Removed obligation: subsequent rule changes no longer require editing three independent calculations.
  • Limit: no new pricing administration, new promotion types, or changes to historical invoice semantics.

This description is more useful than saying the implementation is cleaner. It allows another engineer to challenge whether all three paths really calculate the same thing, whether deployment constraints complicate sharing, or whether the proposed scope is too large for the immediate requirement.

It also gives a team something to inspect later. Did the next pricing change actually require fewer coordinated edits? Did the common calculation clarify the rule, or did it collect unrelated responsibilities? Design investment remains a hypothesis about the code's future use, even when its present motivation is concrete.

Choose Investments With Reviewable Evidence

An improvement needs a concrete reason beyond a prediction that cleaner code will eventually make development faster. Identify an existing obligation, the proposed change, its migration cost, and the behavior that must remain intact.

For the pricing feature, the evidence is visible: three paths independently implement the same calculation. Moving them to one mechanism removes a specific coordination requirement, provided the migration actually reaches every caller.

The future benefit still needs to be checked. When the next pricing rule arrives, inspect which code changes and what the engineer must understand. If the shared calculation has accumulated unrelated policies or callers still work around it, revisit the boundary instead of defending the refactoring as an investment already made.

Frequently changed code and a manageable migration can strengthen the case for an improvement. They do not establish a guaranteed speed increase or a universal payback date. Keep the decision tied to observable obligations and review its result against subsequent work.

Pressure Changes the Size of an Investment

An urgent production incident may require a narrow repair. A prototype may exist to answer a short-lived product question. Neither situation requires pretending that every desirable cleanup belongs in the immediate patch.

The danger is letting the temporary decision become the default explanation for every future change. A deferred improvement needs a discoverable description of the problem, the consequence of leaving it, and a specific place to reconsider it. A vague promise to clean up someday supplies none of those things.

For the pricing feature, an especially risky migration might be split into a behavior-preserving change first and the new rule second. If the release cannot accommodate both, document which consumers still own pricing rules and what keeps them consistent in the interim.

That does not erase the debt. It makes the remaining obligation visible, so the next engineer does not confuse a partial migration with a completed design improvement.

Review What the Change Leaves Behind

At the end of the nonprofit feature, compare the customer's purchase path again: cart, accepted order, invoice. Then ask what the next pricing change will have to coordinate.

The answer should be specific. A useful result might be one documented calculation, explicit precedence and rounding, callers that consume its breakdown, and purchase boundaries that still enforce authoritative prices.

A weaker result might be three new conditions and another note that the calculations should eventually be unified.

Both results may pass a test for the current nonprofit discount. Approve the investment when the present duplication is real, the callers can be migrated safely, and the change has a clear finish line. If the deadline permits only part of it, leave an explicit account of the remaining independent calculations.

The next engineer should be able to tell whether one pricing rule really has one implementation. A new function name is not enough evidence.