SaaS and your own product19 min read3643 wordsRedakcja dvnt
Code refactoring or a rewrite? What to do with a SaaS MVP that cracks under its first customers
SaaS MVP cracking under its first customers? Code refactoring, staged replacement or a rewrite: what to measure first and what a rewrite really costs.
A throwaway MVP? That is usually the first diagnosis when a subscription product starts to crack under its first paying customers — and it is usually premature. Code refactoring, in Martin Fowler's definition, is "a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior", a series of small transformations after each of which "the system is kept fully working" (read on 4 November 2026). A rewrite is something else: a new system built next to the old one, to which you then have to move your customers.
This text is for the founder or product owner of a SaaS product whose first version is months old, not years, and has a few dozen paying customers at most. Lists load slower and slower, someone reports seeing another company's data, every fix breaks something next to it, and the developers are reluctant to touch part of the code. You hear two pieces of advice: "we have to rewrite it from scratch" and "a refactor will do". Our thesis on the refactor vs rewrite question: in a young product the decision is made per module, not for the whole product, and only after measuring. If your problem is an old company system whose vendor is gone, you need a different article: our text on legacy software after the vendor disappears. For when to pay down debt and when to replace a system, read our article on technical debt.
Code refactoring, staged replacement, rewrite — three roads that get confused in conversation
In a conversation about repairing an MVP, three different things are discussed under two names, and which one you order decides whether the product keeps evolving in the meantime.
Refactoring. Small steps, each of which preserves the behaviour of the product: pulling duplicated code into one place, splitting a module that does five things at once, rewriting a query so that it returns the same result faster. Fowler stresses that "since each refactoring is small, it's less likely to go wrong". Customers see only the effect — something runs faster or stops breaking — and new features keep shipping in parallel.
Here is the naming trap. If a contractor proposes a "refactor of the whole thing" that will freeze new features and releases for several months, then by the definition above it is not refactoring but a rewrite under another name. One question settles it: will the product be released to customers as normal while the work is under way?
Staged replacement. When one module has to be built again and the rest of the product works, you use the technique Fowler describes as branch by abstraction: a way of making a large-scale change gradually that "allows you to release the system regularly while the change is still in-progress" (read on 4 November 2026). The old module hides behind a single interface, the new implementation is built next to it, the places in the code are switched over one by one, and finally the old one is removed. For an old company system the counterpart is the strangler fig pattern, in which the new system gradually grows around the old one from the outside; our article on legacy software without a vendor covers it in full.
Rewrite. A new system is built alongside, and customers are moved over in one day or in batches. Until then you maintain two systems, and the old one still needs fixes, because customers work on it every day.
Why an MVP cracks under its first paying customers
An MVP cracks because it was built to answer one question — will anyone pay for this? — and not to serve dozens of companies at once; in itself that does not prove anyone built it badly. How to cut such a first version is described in our article on the MVP, and the road from it to paying customers in the article on the SaaS application.
In his piece on sacrificial architecture (2014), Fowler recalls that eBay "started as a set of perl scripts built over a weekend in 1995" and observes that "often the best code you can write now is code you'll discard in a couple of years time" (read on 4 November 2026). In a growing system, he adds, "it's more effective to sacrifice individual modules". The problem is therefore not that part of an MVP has to be replaced. The problem is that nobody wrote down which parts were meant to be replaced.
Why it happens so fast is explained by another idea of Fowler's, the design stamina hypothesis (2007). Code written without attention to design delivers more features at the start, but good design keeps its productivity more constant, so that "at some point (the design payoff line) it overtakes the cumulative functionality of the no-design project". Fowler thinks that point is "much lower than most people think: usually weeks not months". He is also careful to add: "I call this a hypothesis because it is a conjecture, there is no objective proof", and the position of the line "can only be a judgment call".
In a SaaS product that has just gained its first customers, things usually break in four places:
- Database queries. A screen that loaded instantly with three test accounts now scans whole tables or asks the database separately for every row. To illustrate the mechanism: a list of 50 items fetched so that each one triggers its own query means 51 queries instead of one.
- Customer isolation added later. The identifier of the customer company is checked in some places in the code, not in all of them. Our article on multi-tenant architecture explains why bolting this on after the fact is the most expensive version of that decision.
- No tests. Nobody knows what a change will break, so every fix is a bet.
- API permissions. The screen does not show other people's data, but the programming interface does once the identifier is swapped. According to the OWASP Top 10:2025, OWASP writes of broken access control: "Maintaining its position at #1 in the Top Ten, 100% of the applications tested were found to have some form of broken access control." (read on 4 November 2026). That is OWASP's tested sample and "some form" of the flaw — it does not mean every application leaks data — but it is reason enough to check this first.
Every week in which a customer works around a bug or waits for a fix shows up later as churn, which our article on SaaS metrics describes. Which of our MVP packages include automated tests of the key paths is described on the MVP for startups page.
What to measure before anyone says "let's rewrite"
Before a decision is made you need answers to five questions, and you can get each one by measuring the running product, without downtime. We suggest two weeks. That is our recommendation, not a standard: it is enough to collect data from two full weeks of customer work, and it does not postpone the decision when customers are waiting.
1. How the product behaves today. In the Site Reliability Engineering book, Google says: "The four golden signals of monitoring are latency, traffic, errors, and saturation. If you can only measure four metrics of your user-facing system, focus on these four" (read on 4 November 2026). Two further remarks from the same chapter are useful. First: "It's important to distinguish between the latency of successful requests and the latency of failed requests", because "a slow error is even worse than a fast error!". Second: "many systems degrade in performance before they achieve 100% utilization". The control question from the book: can your service properly handle double the traffic? If you promise customers availability in a contract, the same measurements will show whether you keep that promise; contracts themselves are covered in our article on the SLA.
2. Where the time goes. In PostgreSQL, the pg_stat_statements module "provides a means for tracking planning and execution statistics of all SQL statements executed by a server". A practical note from the documentation: "a server restart is needed to add or remove the module", so plan it. For the five most expensive queries, the EXPLAIN command shows the plan the database chooses; the documentation calls choosing the right plan "absolutely critical for good performance" (read on 4 November 2026). The result is a list of queries to fix, not a verdict on the whole codebase.
3. How much change hurts. DORA, the research programme run by Google Cloud, states: "DORA has identified five software delivery performance metrics" (last updated 5 January 2026, read on 4 November 2026). Three measure throughput — change lead time, deployment frequency and failed deployment recovery time — and two measure instability: the change fail rate, "The ratio of deployments that require immediate intervention following a deployment", and the deployment rework rate, "The ratio of deployments that are unplanned but happen as a result of an incident in production". Do not compare them with other teams' results; compare the product with itself, before and after changes. A bad sign: the measures get worse from week to week.
4. Whether customer A can see customer B's data. Log in as a user of a test company A and swap the identifier of a record in the page address or in an API request for a record of company B. OWASP lists exactly this: "Permitting viewing or editing someone else's account by providing its unique identifier (insecure direct object references)" and "An accessible API with missing access controls for POST, PUT, and DELETE". Run the test on a copy of the environment with test data, not on customer data.
5. Whether it is possible to change things safely. Check that tests of the key paths exist and pass. Our standard is login, payment, form submission and the API contract. Add one organisational question: who holds the repository, the accounts and the access? If it is not you, start with what our article on vendor lock-in describes. If you are taking the code over from a previous contractor right now, the list of things to collect and a plan for the first two weeks are in our article on taking over an IT project.
Five measurement blocks in the running product, no downtime
| Question | What to measure | Bad result |
|---|---|---|
| 1How the product behaves today | What to measure
| Bad resultthe product cannot handle double the traffic |
| 2Where the time goes | What to measure
| Bad resultafter fixing the queries the time does not drop |
| 3How much change hurts | What to measure
| Bad resultthe metrics get worse from week to week |
| 4Can customer A see customer B's data | What to measure
| Bad resultcompany A can see or change company B's data |
| 5Can things be changed safely | What to measure
| Bad resultno tests, or the code and accounts sit with the contractor |
RECOMMENDATIONThe person who measures should not be the one who then gets the rewrite order.
One question remains: who should do the measuring? Our opinion: someone who will not get the rewrite order afterwards. A team that earns money by building from scratch has an interest in the measurements justifying it, even when it acts in good faith. That is why, as part of technology consulting, we carry out an audit of an existing system with a report you can use independently of any further cooperation.
Symptom, cause, road — a decision map for a SaaS product
Every symptom an owner sees usually has one typical cause in the code and one right way to fix it — and rewriting everything is the right road for only one of the five. The map below is our own work; the most important column in it is the last one: the signal that tells you the chosen road is wrong and you should move to the next.
Slow lists, reports and exports. The cause is usually queries that scan whole tables or fetch records one at a time. The road: refactoring of the queries, and indexes. An index is not free, however — the PostgreSQL documentation notes that "indexes also add overhead to the database system as a whole, so they should be used sensibly" (read on 4 November 2026). The signal that the road is wrong: after the five most expensive queries are fixed the time does not drop, because the problem sits in the data model, not in the queries.
Customers see other customers' data. The cause: the check of which company a record belongs to is scattered through the code instead of living in the data model. The road: an immediate patch, then a staged rebuild of the data layer, described in the next section. The signal that the road is wrong: every new feature needs a programmer to remember to add a filter.
Every fix breaks something else. The cause: no tests and hidden dependencies between modules. The road: first tests that pin down the current behaviour of the module — including behaviour that looks wrong — and only then changes. The signal that the road is wrong: the tests cannot be written because nobody can say how the module is supposed to work. Then the module moves to the next row.
Nobody wants to touch module X. The cause: this is a module that was meant to be sacrificed from the start, and nobody said so. The road: rebuilding the module behind an interface with branch by abstraction, while the rest of the product is released as normal. The signal that the road is wrong: the new module "while we're at it" grows new features and can never be finished.
The foundation does not fit. The cause: a platform with no path forward, or a data model that contradicts how the customers' businesses work. The road: a rewrite, still in stages — the conditions are in the section "When a rewrite is unavoidable". The signal that the road is wrong: the plan assumes recreating everything one to one and a single switchover day.
Five symptoms the owner sees
refactoringstaged replacementrewrite
| Symptom | Cause in the code | Road | Signal that the road is wrong |
|---|---|---|---|
| Slow lists, reports and exports | Cause in the codequeries scanning whole tables, fetching records one at a time | RoadRefactoringof queries, and indexes (an index adds overhead) | Signal that the road is wrongafter the five most expensive queries are fixed the time does not drop |
| Customers see other customers' data | Cause in the coderecord ownership checked selectively in code, not in the data model | RoadAn immediate patchthen staged replacement of the data layer | Signal that the road is wrongevery new feature needs someone to remember the filter |
| Every fix breaks something else | Cause in the codeno tests, hidden dependencies between modules | RoadRefactoringpreceded by tests that pin down current behaviour | Signal that the road is wrongtests cannot be written because nobody knows how the module should work |
| Nobody wants to touch the module | Cause in the codea module meant to be sacrificed from the start, and nobody said so | RoadRebuilding the modulebehind an interface (branch by abstraction) | Signal that the road is wrongthe new module grows features and cannot be finished |
| The foundation does not fit | Cause in the codea platform with no path forward or a data model that contradicts the business | RoadA rewritestill in stages | Signal that the road is wronga plan to recreate everything one to one with a single switchover day |
CONCLUSIONRewriting everything is the right road for only one of the five symptoms.
The map usually changes the question. Instead of "rewrite or not" you ask which modules to sacrifice and in what order — exactly as Fowler describes growing systems.
Multi-tenancy added after the fact — fixing it without stopping the product
If the identifier-swap test showed that company A can see company B's data, you first stop the leak and then repair the data model — and neither step requires stopping the product.
Stopping the leak comes down to three principles from OWASP (read on 4 November 2026): "Except for public resources, deny by default"; "Implement access control mechanisms once and reuse them throughout the application"; and "Model access controls should enforce record ownership rather than allowing users to create, read, update, or delete any record". In practice that means a single function through which every read and every change of data passes, instead of a condition added to each screen separately. Such a patch can be deployed quickly, because it does not change the structure of the database. If personal data is involved, agree with a lawyer or your data protection officer whether the incident has to be reported; the GDPR contains a notification duty for personal data breaches (Article 33), with the notification going to the President of the Personal Data Protection Office (UODO), and whether an incident meets its conditions is a legal assessment.
Repairing the model uses the pattern Danilo Sato describes as parallel change, "also known as expand and contract", a way "to implement backward-incompatible changes to an interface in a safe manner"; the author notes: "Most database refactorings follow the parallel change pattern." (read on 4 November 2026). Applying it to the customer identifier is our own extension of the pattern:
- Expand. A column holding the company identifier is added to the tables with customer data. On every write the code fills it in alongside the existing way of linking records; reads work as before.
- Migrate. A script fills in the identifier for historical data, and reads are switched to the new column module by module.
- Contract. The old path disappears from the code and the column becomes mandatory — a record without an owner can no longer be saved.
Each phase is a separate deployment that can be stopped or rolled back without rolling back the earlier ones — just as in branch by abstraction.
Once the column is in place, the database itself can be a second line of defence. In PostgreSQL, Row Level Security follows a default-deny rule: "If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified". The documentation also warns that "Superusers and roles with the BYPASSRLS attribute always bypass the row security system when accessing a table", and that table owners normally bypass it too, unless the owner opts in with ALTER TABLE ... FORCE ROW LEVEL SECURITY (read on 4 November 2026). The lesson for the buyer: ask which role the application uses to connect to the database — if it is the role that owns the tables, the policies protect nothing without forcing. The full treatment of isolation models and RLS is in our article on multi-tenant architecture.
First a patch, then three deployments · each can be stopped or rolled back
Before phase 1 — the patch: one access-control function for every read and write, deny by default.
1 · Expand
add alongside- Database
- a new column with the company identifier next to the existing link
- Code
- writes both, reads the old way
2 · Migrate
fill in, switch- Database
- the identifier filled in for historical data
- Code
- reads switched to the new column module by module
3 · Contract
remove the old- Database
- the column is mandatory — a record without an owner cannot be saved
- Code
- the old path removed
CONCLUSIONNo phase requires stopping the product — this is the parallel change pattern, not a rewrite.
What a rewrite of a SaaS product really costs — a mechanism, not a price list
Rewriting a product that has paying customers costs more than writing the same code a second time, because the cost has five items and building the new screens is only part of the first. We do not quote amounts: they depend on the product, and each of them can be estimated only after measuring.
- Recreating behaviour nobody wrote down. Every exception, rounding rule or workaround added after a customer complaint lives in the code, not in documentation. Joel Spolsky, in his essay "Things You Should Never Do" (2000), notes that "It's harder to read code than to write it." That is why a team would rather write afresh than read what the old code does.
- Migrating live customers' data — together with their integrations: API keys, imports, connections to other systems that customers built on top of your product.
- Two systems at once. Until the switchover day you maintain and fix the old system, and moving customers across is a separate project.
- A frozen roadmap. For the duration of the rewrite, new features wait, and customers and competitors do not.
- Rediscovering bugs that were already fixed. Spolsky writes: "Old code has been used. It has been tested." and "Lots of bugs have been found, and they've been fixed." New code starts from zero in this respect too. That is the opinion of an essay about product companies, not the result of a study.
In his piece on the strangler fig pattern (2024), Fowler writes of the simple plan of recreating a system one to one: "we've seen this simple-sounding plan go down in flames most of the time" (read on 4 November 2026). That is an observation from modernising old systems, not a statistic. More voices against rewriting are collected in our article on technical debt, and the calculation for an old company system is in our article on legacy software without a vendor.
Our conclusion for an MVP is more careful than for legacy. Code that is a few months old holds little accumulated knowledge about edge cases, so items one and five are small in it — Spolsky's argument weakens the younger and smaller the code is. Spolsky himself allows that "You may want to refactor a class to make it easier to use" and that a small part of a project can be rewritten. That is why rewriting a single module of an MVP can be cheaper than texts about old systems suggest. Rewriting everything still carries items two, three and four, which grow with the number of customers and the length of the rewrite, not with the age of the code.
Five cost components of a rewrite · ■ = what the component grows with
| Cost component | with the age of the code | with the number of customers | with the length of the rewrite |
|---|---|---|---|
| 1Recreating behaviour nobody wrote downexceptions and workarounds live in the code, not in documentation | with the age of the code | with the number of customers | with the length of the rewrite |
| 2Migrating live customers' datatogether with API keys, imports and integrations | with the age of the code | with the number of customers | with the length of the rewrite |
| 3Two systems at once and moving customers overthe old system needs fixes until the switchover day | with the age of the code | with the number of customers | with the length of the rewrite |
| 4A frozen roadmapnew features wait, customers and competitors do not | with the age of the code | with the number of customers | with the length of the rewrite |
| 5Rediscovering bugs that were already fixednew code starts without the fixes collected in the old | with the age of the code | with the number of customers | with the length of the rewrite |
In a young MVP the two components tied to the age of the code are small; the three tied to customers and rewrite length are not.
CONCLUSIONRewriting one MVP module can be cheaper than texts about old systems suggest; rewriting everything cannot.
When a rewrite is unavoidable
Rewriting the whole product makes sense in three situations — and in all three the foundation is wrong, not the execution.
- A platform with no path forward. A product built on a no-code tool from which the logic cannot be exported, or on a framework that has lost support and has no upgrade path.
- A data model that contradicts how the business really works, with most modules depending on it. For example, the product assumes that one user belongs to one company, while customers work as agencies serving many companies at once.
- The cost of every change keeps rising despite refactoring. The DORA metrics from the third measurement block do not improve after further months of tidying the code.
Even then you rewrite in stages, module by module. In the piece on sacrificial architecture Fowler writes: "Good modularity is a vital part of a healthy code base, and modularity is usually a big help when replacing a system." So the first stage of a rewrite is often to carve out module boundaries inside the old code. And rewriting "into microservices" is not a cure for performance problems: in Monolith First (2015) Fowler writes: "Almost all the successful microservice stories have started with a monolith that got too big and was broken up", while "almost all the cases where I've heard of a system that was built as a microservice system from scratch, it has ended up in serious trouble" (the author's opinion, read on 4 November 2026).
Where to start — and how we approach it
The order is always the same: stop the data leak if there is one; measure for two weeks; decide module by module and write down the reasoning for each decision. The record will be useful sooner than you think: in a year someone will ask why this module was fixed and that one replaced.
This is how we work on products we take over: first an audit of the code and architecture, then a recommendation with a cost calculation for each option — developing the existing code, staged replacement or building from scratch. The report is written so that you can use it whether or not you keep working with us. Sometimes less is needed than you assumed. How the product continues to develop after such a decision is described on the page about custom software. If you are wondering which scope of review to order, the differences between kinds of audit are described in our article on the IT audit, and how to check the next contractor in our article on choosing a software development company. More about building your own product is in the SaaS section.
Frequently asked questions about refactoring and rewriting an MVP
What is code refactoring?
Code refactoring (also called refactoring) is, in Martin Fowler's definition, restructuring an existing body of code, altering its internal structure without changing its external behaviour, done in a series of small steps after each of which the system keeps working fully. For a product owner it means that refactoring does not stop releases or change what customers see — except that something starts running faster or stops breaking.
What is the difference between refactoring and rewriting an application from scratch?
Refactoring changes existing code in small steps, and the product keeps running and is released as normal throughout. A rewrite builds a new system next to the old one and moves customers over to it — until then you maintain two systems. In between sits staged replacement: a module is hidden behind an interface, and a new implementation is built beside it and takes over tasks one by one, while the rest of the product is released regularly.
How do I check whether my MVP has to be rewritten?
Measure five things, preferably over two weeks: how the product behaves today (latency, traffic, errors, saturation), which database queries take the most time, how the DORA delivery metrics behave, whether swapping an identifier lets one company see another's data, and whether tests of the key paths exist and who holds the repository. A full rewrite follows from the measurements only when the foundation is wrong — a platform with no path forward or a data model that contradicts the business.
Can multi-tenancy be added to an existing application?
Yes, without stopping the product. First a single shared access check with a deny-by-default rule, then the parallel change pattern: a company-identifier column added alongside, historical data filled in and reads switched module by module, and finally the old path removed. Row Level Security in PostgreSQL can be a second line of defence — with the caveat that the table owner bypasses policies unless they are forced.
How much does it cost to rewrite an MVP?
There is no honest figure without measuring. The cost has five items: recreating behaviour nobody wrote down, migrating customers' data and their integrations, maintaining two systems at once, a frozen roadmap and rediscovering bugs that were already fixed. In a young MVP two of them are small, but three grow with the number of customers. That is why the calculation for each option — development, staged replacement and building from scratch — is made after a code audit.
Will a new contractor always say the product has to be rewritten?
Not always, but they have an interest in it, because building from scratch is a bigger order than fixes. That is why, in our view, the measuring should be done by someone who will not get the rewrite order afterwards, and the report should be usable without further cooperation — what it should contain is described in our article on the application audit. A good recommendation says which modules to fix, which to replace and why — not "throw the whole thing away".
Related articles
SaaS and your own product
MVP (minimum viable product) — what it is and how to cut a scope that answers one question
What is an MVP (minimum viable product), how it differs from a proof of concept and a prototype, and how to scope it with the MoSCoW method.
SaaS and your own product
Multi-tenant — what it is and how to choose a SaaS architecture for many customers
Multi-tenant SaaS: single tenant vs multi-tenant, the silo/pool/bridge models, Row Level Security, GDPR and choosing a model for an MVP.
SaaS and your own product
ARR, MRR and churn — SaaS metrics, formulas, benchmarks and measurement traps
ARR, MRR, churn, NRR, LTV:CAC and Rule of 40: formulas from ChartMogul and Stripe, benchmarks with their sample size, and the traps that make SaaS metrics lie.
SaaS and your own product
SaaS application — how to build your own product from MVP to recurring payments
A SaaS application from MVP to subscription: the five building blocks, recurring payments in Poland, the legal minimum, costs and the DVN Links example.
SaaS and your own product
Micro-SaaS examples 2026 — 35 niche tools you could build
35 concrete micro-SaaS examples grouped by industry, a niche-scoring framework, a 30-day MVP plan, and a path to your first 50 paying customers.

Web and mobile apps
Web and mobile apps for businesses — a guide to building them, decision by decision
Guides on building apps for businesses: what a web app is, how the project runs, what it costs, how to plan an MVP, and PWA vs mobile apps.