Skip to content

Guide

Should we rebuild or refactor our app? A decision framework

A decision framework for AI-built and other early-stage apps: the signals for stabilizing and refactoring versus rebuilding, how the strangler pattern works at startup scale, and the rebuild costs that estimates leave out.

  • Published
  • Updated
  • 10 min read
  • By Dev Talan

Key takeaways

The short version. Each point is explained in full below.

  1. 01

    Pick a route for each part of the system: stabilize, refactor, replace in parts, or rebuild. A billing module and a settings page rarely deserve the same answer.

  2. 02

    Slow pages usually come from N+1 queries, missing indexes, or lists with no limit, and releases that keep breaking usually mean no CI and no tests on the critical paths. Neither is a reason to rewrite.

  3. 03

    Before trusting a rebuild estimate, check that it prices hidden behavior, the data migration, fixes to the old app until cutover, every integration, and carrying sign-ins and sessions across.

  4. 04

    Two or more rebuild signals in the same part, such as a data model that contradicts the business and tenant data separated only by UI filters, make a strong case for replacing that part. One alone rarely does.

  5. 05

    To replace a part, route every call through one seam, compute the new result beside the old one and log every mismatch, move traffic with a feature flag, and delete the old path once mismatches stop.

The decision to rebuild or refactor your app depends on its foundations, not on how messy the code looks. Stabilize and refactor when the data model fits the business and changes can be tested. Rebuild only when the data model, security model, or platform blocks what the product must do next, and only after someone has read the code.

Many apps built too fast, with AI coding tools, a freelancer, or an agency, land in the middle: keep the data and most of the logic, and replace the worst parts one at a time. Building fast was a sensible trade for early users and evidence. This guide covers what comes next.

Should we rebuild or refactor our app?

#

Choose a route for each part of the system. A billing module and a settings page rarely deserve the same answer.

Stabilize
Add the safety net that makes change safe: CI on every pull request, error tracking, tests on the critical paths, and a rollback you have tried once. Users see no change in behavior.
Refactor
Change the structure of code without changing what it does, in small steps that each pass the tests. A plan that also changes features or the schema is more than a refactor and needs its own plan.
Replace in parts
Build a new version of one part beside the old one, move traffic to it gradually, and delete the old part once nothing calls it. This is the strangler pattern.
Rebuild
Write a new system and move users, data, and integrations to it. A rebuild can still ship in parts, and usually should.
RouteFits whenMain riskWhat the product does meanwhile
StabilizeReleases break things and nobody trusts a deployStopping too earlyKeeps shipping, slower for one sprint
RefactorThe data model fits and the problems sit in code you can test aroundEndless cleanup without a ranked listKeeps shipping
Replace in partsOne or two areas are wrong and the rest is soundTwo code paths to maintain until the old one is deletedKeeps shipping
RebuildThe foundations block the next stage, or the app is smallMissed behavior and a risky data migrationNeeds fixes and hosting until cutover
Four routes for an early-stage app

What are the signs you should refactor rather than rewrite?

#

Refactor when the problems are in the code but not in the foundations. Messy code on a sound data model is cheaper to fix than to replace, because the data model is what every screen, report, and integration depends on.

SignalPoints to stabilize and refactorPoints to rebuilding that part
Data modelTables match real customers, accounts, and money, even if the names are oddCore concepts are missing or merged, such as orders and invoices stored in one table that most queries depend on
AuthorizationSome checks are missing, but every request passes a server-side boundary, such as an API or row-level security policiesThe browser writes to the database with no row-level security, and rules such as prices and permissions live only in client code
Change containmentA fix touches a few files, and tests can pin the behavior around itSmall changes ripple into unrelated screens even with tests in place
PlatformA mainstream framework, database, and host your next hire already knowsA platform with no code export, or one that cannot meet a requirement you have today
Size and historyMonths of customer feedback encoded as edge cases across many screensA small app with a few screens and one integration, whose behavior fits on one page
Rewrite vs refactor signals, judged part by part

Symptoms that look like rebuild signals but usually are not

#

Several common complaints feel like proof that the app needs a rewrite. Each usually has a cause that refactoring fixes in place.

  • Pages got slow as customers grew. Look for N+1 queries, missing Postgres indexes, and lists with no limit, and fix them query by query.
  • Every release breaks something. That usually means no tests on the critical paths and no CI, which a safety net fixes first.
  • Nobody understands the code. That is a knowledge problem, and the architecture may be fine. Reading and documenting the code costs far less than rebuilding behavior nobody can describe.
  • The dependencies are badly out of date. Upgrades are tedious but incremental, one major version at a time.
  • The code style is inconsistent. Naming, formatting, and duplication are refactoring work. They never justify replacing behavior that works.
  • The team prefers another framework. A preference is not a requirement. Ask which customer need the current stack blocks.

Apps built with AI coding tools often show these symptoms, because each prompt optimizes for the feature in front of it. Our guide to the risks in AI-generated code shows where the gaps usually sit, and the AI-built app risk checklist is a quick self-check. Most of those gaps are fixed without a rewrite.

When should you rewrite software from scratch?

#

Rewrite when the foundations contradict what the business now needs, and fixing them in place would touch nearly every file anyway. Even then, ship the rebuild in parts where you can.

  • The data model contradicts how the business works, and correcting it changes most tables and queries.
  • Customer data is separated only by filters in the UI, and adding a real tenant boundary means rewriting most data access.
  • The platform cannot meet a requirement you have now, such as offline use or data residency, or the code cannot be exported from the tool it was built in.
  • The app is small: a handful of screens, one or two integrations, and behavior you can list on one page.
  • The product is changing direction, and most current features will not survive the next version.
  • The cost of fixing a part, estimated from the code, comes close to the cost of replacing it, migration included.

One signal alone rarely settles the question. Two or more in the same part of the system make a strong case for replacing that part. The technical debt triage checklist helps sort which problems belong to the foundations and which can wait.

Small apps are the exception

The usual advice against rewrites comes from large systems with years of hidden behavior. AWS guidance on the strangler fig pattern notes that for small applications, where the complexity of a complete rework is low, rewriting might be more efficient than migrating piece by piece. A young app with a few screens may qualify, if its behavior is written down first.

What does a rebuild cost that the estimate leaves out?

#

A rebuild estimate usually prices the new code and little else. The larger costs sit around it: finding the behavior the old app handled, moving the data, and running two systems until cutover.

CostWhy it gets missedHow to account for it
Hidden behaviorEdge cases live in the code and in customers' habits, and no spec lists themList behavior from the code, support tickets, and analytics, and decide what to drop
Data migrationThe new schema looks clean until old rows do not fit itWrite the migration as code and rehearse it on a copy of production data
Two systems at onceThe old app needs fixes and hosting until the last user movesBudget fixes on the old app for the whole length of the rebuild
Feature freezeCustomers and sales keep asking for things while the team rebuildsAgree in writing which requests wait and which ship in the old app
IntegrationsPayment webhooks, OAuth apps, email domains, and API clients point at the old systemList every integration and who owns each account
Sign-in and sessionsPassword hashes, social logins, and active sessions must carry over, or every user resetsTest the account migration with each real account type before cutover
Repeated gapsWithout tests, review, and CI, new code gathers the same debt as the oldSet up the safety net before the first new feature
Rebuild costs that rarely make the first estimate

A rebuild also attracts new features. Each one moves the cutover date and makes parity harder to check, so add features after cutover. Parity has limits too. In his note on the strangler fig application, Martin Fowler observes that much of a legacy system's behavior isn't really wanted, so copying all of it is waste. Decide what to drop before anyone writes the estimate.

Plan the cutover before the build

Write down how users, data, and integrations move, how long the old app runs alongside the new one, and how you roll back if cutover fails. A rebuild without that plan has no end date. Our guide to safe releases and rollbacks covers the release side.

How does the strangler pattern work on a startup app?

#

The strangler pattern replaces a system one part at a time: new code grows beside the old, traffic moves across gradually, and the old part is deleted once nothing calls it. In a startup app the seam is usually a route, an API endpoint, or one function that owns a business rule. It does not need to be a separate service.

  1. 01Pick the part that hurts mostChoose the files that change most, break most, or block the next feature.
  2. 02Put one seam in front of itRoute every call to that part through one function or endpoint, so there is one place to switch.
  3. 03Build the new version beside the oldWrite it against the same inputs, with tests that pin down what the old version returns today.
  4. 04Run both and compareServe the old result, compute the new one for selected organizations, and log every mismatch.
  5. 05Move traffic with a feature flagSwitch your own internal account first, then one customer, then everyone, with the flag as the rollback.
  6. 06Delete the old pathRemove the old code, the flags, and the comparison once mismatches stop. Otherwise the pattern only doubles the code.
In compare mode, customers get the old total and errors in the new code are only logged. A second flag then serves the new total, one organization at a time.typescript
import { isEnabled } from "@/lib/flags";
import { logger } from "@/lib/logger";
import { legacyInvoiceTotal } from "@/legacy/invoices";
import { invoiceTotal } from "@/billing/invoice-total";

export async function getInvoiceTotalCents(invoiceId: string, organizationId: string) {
  if (await isEnabled("billing-v2-serve", organizationId)) {
    return invoiceTotal(invoiceId);
  }

  const legacyTotal = await legacyInvoiceTotal(invoiceId);

  if (await isEnabled("billing-v2-compare", organizationId)) {
    try {
      const newTotal = await invoiceTotal(invoiceId);
      if (newTotal !== legacyTotal) {
        logger.warn({ invoiceId, legacyTotal, newTotal }, "invoice total mismatch");
      }
    } catch (error) {
      logger.error({ err: error, invoiceId }, "billing v2 comparison failed");
    }
  }

  return legacyTotal;
}

The data is usually harder to move than the code. If the new part needs a different schema, add the new tables beside the old ones, write to both, backfill the history, and switch reads last. Expand first and contract later, so every step can be undone. Fowler accepts that this transitional code gets thrown away at the end, and argues the lower risk and earlier value are worth it.

Where the strangler pattern does not fit

#
  • There is no seam. If the code cannot be exported or intercepted, as with some hosted builders, there is nowhere to put the switch.
  • The app is small. When a full rebuild costs less than the transitional code, rebuild and cut over once, with a rollback plan.
  • The schema is the problem. If every new part would still use the same broken tables, fix the schema first, then replace the code above it.

Why does the rebuild decision need someone to read the code first?

#

The rebuild decision needs a code review first because the same symptom has different causes, and only the code shows which one you have. A dashboard that takes eight seconds to load can be one missing index, or a schema that forces every query to scan every customer's data. The first is an afternoon's fix. The second is a reason to replace that part.

Opinions about a rewrite usually come from the people closest to the pain. Engineers who inherited the code often want a clean start, and founders who paid for it often want to keep it. Both are reasonable, and neither is evidence. A reviewer outside the team weighs each part on what the code and its history show. These are the places to read first.

  • The schema and migrations, compared with how the business describes customers, accounts, and money.
  • Where authorization happens: in the API and the database, or only in the UI.
  • Which critical paths have tests, and whether CI runs them on every pull request.
  • The files that change most often in git history, which is where debt costs the most.
  • Error tracking and incident history, showing which parts fail in production.
  • The deploy and rollback steps, and who can run them.
The 20 files changed in the most commits over the last six months. Files high on this list that also show up often in bug reports are where refactoring pays back first.bash
git log --since='6 months ago' --name-only --pretty=format: |
  grep -v '^$' | sort | uniq -c | sort -rn | head -20

That reading is what a software audit does in about 3 to 5 days of review. Our guide to what a software audit covers lists the areas reviewed and what the report should contain. For a rescue, the report ends in a fix-or-rebuild call for each part of the system, with the reasons and rough costs for each route.

How do you make a technical debt rebuild decision as a team?

#

Decide part by part, write the decision down, and stabilize the current app whichever route you take, because customers use it until the day of cutover.

  1. 01Write down the next 12 monthsList what the product must support: customer types, integrations, security questionnaires, and data volume.
  2. 02Triage the debt togetherSort known problems into foundations and everything else, so the discussion is about specific parts of the app.
  3. 03Get the code readAsk someone who did not build it for evidence on each part of the codebase.
  4. 04Choose a route for each partStabilize, refactor, replace in parts, or rebuild, with a rough cost next to each option.
  5. 05Record the decisionWrite the choice, the options you rejected, and the reasons in an architecture decision record, so the next engineer knows why.
  6. 06Stabilize firstCI, error tracking, and tests on the critical paths help every route. They protect the current app now, and they become the parity checks for anything that replaces it.

What should you do next?

#

Work through the technical debt triage checklist with your team this week, and sort what you find into foundations and everything else. If most of it lands outside the foundations, stabilize and refactor in place.

If the list points at the data model, the security model, or the platform, or the team can't agree, get the code read before anyone estimates a rebuild. Our software rescue work starts with that reading, then a fixed-price stabilization sprint scoped from what it found.

FAQ

Common questions

Short answers to what readers ask next about this topic.

A rebuild timeline can't be estimated honestly until someone has read the code and listed the behavior that must carry over. It depends on the number of screens, integrations, and data migrations, and on how much existing behavior you choose to drop. Add the costs from the hidden-costs table above before setting a date, especially the fixes the old app needs until the last user moves.

Partly. AI coding tools shorten the time it takes to write new code, and we use them on rebuilds too. They shorten much less of what makes a rebuild expensive: finding the behavior the old app handled, migrating data safely, testing parity, and running two systems until cutover. Faster drafting makes rebuilding a small app more attractive, but those costs remain for a larger one.

Ask for four things in writing: the requirement the current system blocks, the behavior that must carry over, the data migration plan, and what will stop the new code from gathering the same debt. A strong case answers all four with evidence from the code. A weak one rests on how the code feels to work in, which refactoring can usually fix.

Usually not. A half-finished rebuild is harder to explain than a stable app with known, ranked problems and a written plan. Diligence reviewers commonly ask about tests, CI, migrations, access control, and how decisions were made. Stabilizing those areas and recording the rebuild or refactor decision gives you honest, evidence-backed answers, whichever route you take afterward.

Yes, if the work is split well. Refactor in small pull requests close to the code each new feature touches, so the cleanup pays off straight away, and keep tests and CI running on every change. Avoid long-lived refactoring branches, which drift from the main branch and collide with feature work. For larger restructuring, follow the strangler steps above, with the new code behind a feature flag until mismatches stop.

A Pixelact rescue audit is priced as a software audit, from $2,500 and paid upfront. It covers about 3 to 5 days of review, a written report that ranks risks and fixes, a build path with rough costs, a walkthrough call, and the fix-or-rebuild call. If the audit leads to a build within 60 days, 50% of the audit fee is credited against that build.

Related

Related services, guides, and checklists.

Monthly newsletter

Get the next article by email

One short email a month on scoping, security, AI features, and releases, with links to new articles and checklists. Every issue is also published on the site, and every email has an unsubscribe link.

By subscribing, you agree to get the Pixelact newsletter by email. Every email has an unsubscribe link. Read the privacy notice.

Start a project

Tell us what you're building.

Share a few details in a short form, or book a discovery call if you're not sure where to start.

On the discovery call

  1. 01What prompted this now, and where things stand
  2. 02What a good outcome looks like
  3. 03Whether we're a fit, and what a next step could be

45 minutes. No slides, and no long questionnaire.