Field note / Java
Strangling a Payments Monolith Without Stopping Payments
Moving payment flows from a legacy monolith to Spring Boot services while both run in production: routing, data, tracing, health checks and how to roll back.
The rewrite pitch always sounds the same: the monolith is slow to change, so we’ll build the new system next to it and switch over. In payments, there is no switching over. Money moves every minute, merchants and regulators expect the old behavior exactly, and “we’ll freeze features for six months” is not a plan anyone will approve.
What works is the strangler pattern: new services take over one flow at a time while the old system keeps running everything else, until there’s nothing left for it to do. I’ve worked on this kind of migration on a global payments platform, with legacy PHP and Java systems running alongside new Spring Boot and Node.js services. These are the decisions that matter most.
Pick the first flow for learning, not for impact
The tempting first candidate is the most painful part of the monolith. Don’t start there. The first flow’s job is to prove the plumbing: routing, deployment, observability, rollback. Pick something with:
- clear boundaries and few writes into shared tables,
- real production traffic, so you learn something,
- a cheap failure mode, so a mistake costs a retry and not a reconciliation.
Read-heavy flows like payment status lookups, or a single payment method in a single region, are good first candidates. Card authorization is not.
Route at the edge, with a switch you can flip
Put a routing layer in front of both systems: an API gateway, a reverse proxy or a thin routing service. It decides per request whether the monolith or the new service handles it.
Route on something you control and can narrow: a flow, a merchant, a region, a percentage. Start with internal or test merchants, then a handful of real ones, then a region. Every step is a config change, not a deploy.
The most important property of the switch is that it goes back. If error rates move, routing a merchant back to the monolith should take seconds. Teams that can roll back quickly migrate faster, because each step is less scary.
Decide who owns the data, flow by flow
This is where most migrations stall. The new service needs payment data, and the monolith’s tables are the source of truth. The options, roughly from easiest to cleanest:
- Share the database for now. The new service reads (and carefully writes) the monolith’s tables. Fast to start, but you’re coupled to a schema you don’t own. Acceptable for the first flow if you treat it as debt with a date.
- Monolith remains the owner; the service calls it. The new service asks the old system through an internal API. Slower, but the boundary is explicit.
- The service owns its data; the monolith is told. The new service writes to its own store and publishes events the monolith consumes for anything that still depends on the data, like reporting and settlement.
Whatever you pick, write down per flow who is the source of truth. Two systems that both think they own a payment’s status is how you end up reconciling by hand.
Trace one payment across both worlds
The day a merchant reports a missing payment, someone has to follow it from the gateway through the new service, into the monolith and out to the processor. If each system logs with its own ids, that’s an afternoon of grep.
Propagate one correlation id everywhere. The W3C traceparent header works across languages, so the PHP side and the Spring side can share it. Spring Boot with Micrometer Tracing picks it up and adds it to logs automatically; on the legacy side, it’s usually a small middleware that reads the header and puts it into the log context.
Log the payment id and the trace id together at every hop. That’s the minimum. A tracing backend that shows the whole request tree is better, but the shared id is what makes everything else possible.
Make health checks mean something
Load balancers route traffic based on health checks. A check that returns 200 whenever the process is running will happily send payments to an instance that can’t reach its database.
Spring Boot Actuator separates the two questions:
- Liveness: is the process alive, or should it be restarted?
- Readiness: can it serve traffic right now? Include the dependencies the flow can’t work without, like its database and the processor connection.
Keep liveness narrow, so a slow dependency doesn’t trigger restart loops, and make readiness honest, so instances leave rotation when they can’t do the job.
Run both paths before you trust one
For flows where correctness is subtle (fees, currency conversion, routing rules) run the new implementation in shadow mode first. The monolith handles the request and returns the response; the new service computes its answer in parallel, and you compare and log the differences without acting on them.
A week of zero unexplained differences on real traffic is better evidence than any test suite. Just make sure the shadow path can’t cause side effects: no calls to processors, no writes to shared data, no notifications.
Put the repeated parts in a shared library
After the second or third service, the same code shows up everywhere: the client for the monolith’s internal API, authentication between services, the logging and tracing setup, error formats. Pulling these into a small internal library made each new service faster to build and, more importantly, consistent. Every service logged the same way and propagated the trace the same way, without anyone copying it from the last one.
Keep the library boring and small. Shared infrastructure code, yes. Shared business logic, no; that’s how you rebuild the monolith in a jar.
Keep the teams talking
The technical plan is the easier half. The people maintaining the monolith know where its behavior is undocumented and surprising, and they’re often the ones being told their system is going away. Bring them into the design of each flow’s migration. The quirks they know about are exactly the ones that would otherwise become production incidents.
The checklist
- The first flow is chosen to prove the plumbing, with a cheap failure mode.
- Routing happens at the edge, per flow and per merchant or region, and rolls back with a config change.
- Each flow has a written source of truth for its data.
- One trace id follows a payment through old and new systems.
- Readiness checks reflect real dependencies; liveness stays narrow.
- Subtle flows run in shadow mode until differences are explained.
- Shared infrastructure lives in a small internal library; business logic doesn’t.
A strangler migration is slower than a rewrite on paper and much faster in practice, because it keeps shipping the whole time. The goal isn’t a big switch day. It’s the day you notice the monolith hasn’t received traffic for a month, and you turn it off without a meeting.