Article · Solution Architect – role and craft · Microservices
AS-IS → TO-BE migration without downtime: transitional architecture, strangler fig and CDC
How to move a shop's critical system from an old platform to a new one without stopping sales: transitional architecture, the strangler fig pattern, feature flags and shadow mode, dual write versus CDC, data migration and reconciliation, a plan for retiring the old system, risks and rollback – using a 2009 order and warehouse system as the example.
OrderFlow is live: web orders confirmed in a second, no overselling, happy customers. Except that next to it the old shop platform is still running – a PHP monolith on MySQL from 2009, once bought from a vendor and extended over the years so much that at Bazario nobody calls it anything but Kombajn (Polish for "combine harvester"). It handles orders from older versions of the mobile app, from the B2B channel and from the old API for large sellers, plus returns, commission settlements with sellers and a nightly batch that feeds the ERP, invoices and exports to carriers. The board asks: "When do we switch Kombajn off?". Ola answers: "In two years. And without closing the shop for even an hour."
- 2004
- "Strangler fig" – Martin Fowler names the pattern after the strangler figs he saw in Queensland, Australia
- 4 steps
- of an online migration at Stripe – dual writing, switching reads, switching writes, removing old data
- ~$100M
- of Hershey orders unfulfilled (1999) – after a big-bang rollout of new systems just before Halloween
Big bang or piece by piece
A big-bang migration looks tempting: one weekend, one switchover, no more double maintenance. The problem is that everything changes at once – code, data, integrations, processes and people's habits. And once the new system accepts its first orders, going back is no longer simple.
A gradual migration costs more calendar time, but every step is small, measurable and reversible.
AS-IS, TO-BE and transitional architecture
In the HLD Ola describes three states, not two:
- AS-IS – what exists: Kombajn, its database, the batch and all the integrations, including the ones nobody remembers.
- TO-BE – the target state: OrderFlow (orders, payments, reservations) plus new returns and seller settlement services, Kafka and PostgreSQL.
- Transitional architecture – what we build only for the duration of the migration and then throw away: the facade, the change stream, the anti-corruption layer and reverse synchronisation.
Transitional elements cost money, so they go into the estimate and the plan like any other component. The most important one is the anti-corruption layer (a DDD term). The Kombajn model – tables like ZAM_NAGL, statuses "3" and "7", gross prices stored as text with a decimal comma – must not leak into the new services. A translator at the boundary turns it into events in Bazario's domain language.
Strangler fig: slice by slice
In 2004 Martin Fowler compared the gradual replacement of a system to a strangler fig. The plant sprouts in the branches of a tree, sends roots down to the ground and over the years wraps around the trunk until the old tree dies and the fig stands on its own. In a system, the role of the vines is played by a facade that takes over traffic feature by feature:
How do you choose the order of slices? Ola rates each feature on three axes: value (what the customer or the business gains), coupling (how many other features and tables it touches) and risk (money, invoices, contracts with sellers). High-value, low-coupling features go first. The cart quote – prices, discounts, VAT and delivery cost – is ideal: lots of traffic, read-only, zero impact on accounting. Commission settlements with sellers and the B2B channel go last. You can also slice by channel (web shop first, then B2B) or by customer segment (employees first, then 5% of customers).
| OrderFlow and new services | Kombajn | |
|---|---|---|
| M0 | 0 % of requests | 100 % of requests |
| M3 | 5 % of requests | 95 % of requests |
| M6 | 20 % of requests | 80 % of requests |
| M9 | 35 % of requests | 65 % of requests |
| M12 | 55 % of requests | 45 % of requests |
| M15 | 75 % of requests | 25 % of requests |
| M18 | 90 % of requests | 10 % of requests |
| M21 | 100 % of requests | 0 % of requests |
| M24 | 100 % of requests | 0 % of requests |
Feature flags and shadow mode
The facade routes requests based on feature flags. In an article on Martin Fowler's site, Pete Hodgson divides them into four kinds: release, experiment, ops and permissioning toggles. A migration mostly uses the first two, plus ops flags as an emergency switch.
Ola uses three techniques at once:
- Gradual rollout – a flag with a percentage of customers (1% → 5% → 25% → 100%), computed from a stable key, the customer ID. That way the same customer doesn't jump between systems.
- Shadow mode (shadow traffic, parallel run) – the facade answers from the old system, but in the background also asks the new one and compares the results. GitHub popularised this approach with its Scientist library. Discrepancies show up in metrics before the new system serves its first customer.
- Instant fallback – switching the flag off sends traffic back to Kombajn within seconds, without a deployment.
An example: the cart quote. The code uses OpenFeature – an open standard for flag APIs that works with different providers:
Facade: a percentage-of-customers flag and shadow mode
import { OpenFeature } from "@openfeature/server-sdk";
import { legacy, pricing } from "./clients";
import { logger, metrics } from "./telemetry";
import type { Quote } from "./model";
// Strangler facade: decides per request whether the new pricing service or legacy Kombajn answers.
const flags = OpenFeature.getClient("checkout-facade");
export async function getQuote(cartId: string, customerId: string): Promise<Quote> {
const ctx = { targetingKey: customerId }; // stable bucket for percentage rollouts
if (await flags.getBooleanValue("quotes-from-new-pricing", false, ctx)) {
return pricing.getQuote(cartId);
}
const result = await legacy.getQuote(cartId);
// Shadow mode: ask the new system too and compare, but always answer with legacy.
if (await flags.getBooleanValue("quotes-shadow-compare", false, ctx)) {
void pricing.getQuote(cartId)
.then((candidate) => compare(cartId, result, candidate))
.catch(() => metrics.increment("shadow.error", { feature: "quote" }));
}
return result;
}
function compare(cartId: string, expected: Quote, actual: Quote): void {
// Amounts are integers in minor units (grosze) – never compare money as floats.
const same = expected.totalMinor === actual.totalMinor &&
expected.deliveryMinor === actual.deliveryMinor &&
expected.lines.length === actual.lines.length &&
expected.lines.every((line, i) =>
line.sku === actual.lines[i].sku && line.totalMinor === actual.lines[i].totalMinor);
metrics.increment(same ? "shadow.match" : "shadow.mismatch", { feature: "quote" });
if (!same) logger.warn({ feature: "quote", cartId }, "shadow mismatch"); // IDs only, no personal data
}package pl.bazario.facade;
import dev.openfeature.sdk.Client;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.springframework.stereotype.Service;
// Strangler facade: per-customer routing between legacy Kombajn and the new pricing service.
@Service
public class QuoteRouter {
private final Client flags = OpenFeatureAPI.getInstance().getClient("checkout-facade");
private final LegacyClient legacy;
private final PricingClient pricing;
private final ShadowComparator comparator;
private final Executor shadowPool; // bounded pool: shadow traffic must never starve real requests
public QuoteRouter(LegacyClient legacy, PricingClient pricing,
ShadowComparator comparator, Executor shadowPool) {
this.legacy = legacy;
this.pricing = pricing;
this.comparator = comparator;
this.shadowPool = shadowPool;
}
public Quote quote(String cartId, String customerId) {
var ctx = new ImmutableContext(customerId); // targeting key → stable percentage bucket
if (flags.getBooleanValue("quotes-from-new-pricing", false, ctx)) {
return pricing.quote(cartId);
}
Quote result = legacy.quote(cartId);
if (flags.getBooleanValue("quotes-shadow-compare", false, ctx)) {
CompletableFuture.supplyAsync(() -> pricing.quote(cartId), shadowPool)
.thenAccept(candidate -> comparator.compare("quote", cartId, result, candidate))
.exceptionally(err -> { comparator.error("quote", err); return null; });
}
return result;
}
}using OpenFeature;
using OpenFeature.Model;
// Strangler facade: per-customer routing between legacy Kombajn and the new pricing service.
public sealed class QuoteRouter(ILegacyClient legacy, IPricingClient pricing, ShadowComparator comparator)
{
private readonly FeatureClient _flags = Api.Instance.GetClient("checkout-facade");
public async Task<Quote> GetQuoteAsync(string cartId, string customerId, CancellationToken ct)
{
// Targeting key → stable bucket, so a customer doesn't jump between systems.
var ctx = EvaluationContext.Builder().SetTargetingKey(customerId).Build();
if (await _flags.GetBooleanValueAsync("quotes-from-new-pricing", false, ctx))
return await pricing.GetQuoteAsync(cartId, ct);
var result = await legacy.GetQuoteAsync(cartId, ct);
if (await _flags.GetBooleanValueAsync("quotes-shadow-compare", false, ctx))
{
// Fire-and-forget shadow call: it never delays or breaks the customer's request.
_ = Task.Run(async () =>
{
try
{
var candidate = await pricing.GetQuoteAsync(cartId, CancellationToken.None);
comparator.Compare("quote", cartId, result, candidate);
}
catch (Exception ex) { comparator.Error("quote", ex); }
});
}
return result;
}
}The rest of this article is for members
Create a free account or sign in to read it all. Still ahead:
- Data synchronisation: dual write, CDC or outbox
- Data migration step by step
- The plan for retiring the old system
- Risks and rollback
- Example: what happened at Kombajn
- Trade-offs
- Check yourself
- Related topics