Quick revision
The short answer
We start by mapping billing's tables, code dependencies and every transaction that spans billing and other modules. Inside the monolith we introduce an internal billing API and events and remove other modules' direct access to billing tables. We then build the new service with its own schema, keep data in sync with change data capture or a controlled dual-write behind a feature flag, run old and new paths side by side in shadow mode and compare results, cut over gradually such as by customer segment while keeping rollback possible, and finally remove the old code and tables so the monolith really shrinks.
What to remember
In this answer, we planned the extraction of billing from a ten-year-old monolith: map tables, code and cross-module transactions, build an internal billing API and events with enforced boundaries, create the new service with its own schema and sync data with CDC or a flagged dual-write, run shadow mode for a full billing cycle, cut over by customer segment with reverse sync for rollback, and finally delete the old code and tables. Cross-module transactions become outbox-driven sagas.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We start by mapping billing's tables, code dependencies and every transaction that spans billing and other modules. Inside the monolith we introduce an internal billing API and events and remove other modules' direct access to billing tables. We then build the new service with its own schema, keep data in sync with change data capture or a controlled dual-write behind a feature flag, run old and new paths side by side in shadow mode and compare results, cut over gradually such as by customer segment while keeping rollback possible, and finally remove the old code and tables so the monolith really shrinks.
Why this question is asked
Billing is one of the hardest modules to extract. It is tangled with orders, customers and accounting through a shared schema, it handles money, so errors are costly and visible, and after ten years nobody knows every place that reads its tables. Interviewers ask this design question to see whether a candidate can plan a long, risky migration in safe, reversible steps. In this answer, we will go from boundary analysis through the internal API, the new service and data sync, shadow mode and gradual cutover to the final cleanup, and then deal with transactions that span billing and orders.
1Boundary Analysis: Tables, Code and Transactions
We first find out what billing really is in this monolith. On the data side, we list the tables billing owns, such as invoice, invoice_line, payment and credit_note, and every query from other modules that touches them. Oracle helps here: the data dictionary shows foreign keys, and statement history or auditing shows which code reads which tables. On the code side, a dependency analysis with tools such as ArchUnit or the IDE shows which packages call billing classes and which billing classes call others.
The most important item is transactions that span billing and other modules. For example, placing an order might insert an order row and an invoice row in one @Transactional method, so both commit or neither does. Each such transaction will need a new design once billing has its own database. The output of this phase is a written map and a list of these cross-module transactions, which drives the rest of the plan.
2An Internal Billing API and Events Inside the Monolith
Before building anything new, we make billing a proper module inside the monolith. Other modules stop querying billing tables and calling billing internals; instead they use a small BillingApi interface, and billing publishes events such as InvoiceIssued and PaymentReceived for anyone who needs to react. Reports that joined billing tables are rewritten to use the API or a reporting copy. We enforce the new boundary with an ArchUnit rule so it cannot erode during the long migration.
This step is valuable on its own: even if the extraction stopped here, the monolith would be easier to change. And it makes the later steps much smaller, because only billing itself touches billing tables.
3The New Service, Its Schema and Keeping Data in Sync
The new billing service is a Spring Boot application with its own schema, which may be in a new PostgreSQL database or a separate Oracle schema, depending on the target platform. Its data model can be cleaner than the old one, since we are not bound by ten years of columns.
During the migration, both the old and the new data must stay consistent. Change data capture, CDC, reads the database's change log and streams every insert, update and delete to the new service, for example with Debezium, which supports Oracle through LogMiner; check the connector's requirements for your Oracle version. CDC needs no change to the monolith's code. The alternative is a controlled dual-write: the billing module writes to both the old tables and the new service, guarded by a feature flag, with a reconciliation job that compares the two daily. Dual-writes are simpler to start but risk inconsistency when one write fails, which is why the reconciliation job is essential.
- Other monolith modulesuse
BillingApiand billing events only - Billing module in the monolithstill writes the Oracle billing tables
- Change data capturestreams changes from the Oracle log
- New billing serviceown schema, consumes the changes
- Reconciliation jobcompares totals and invoices daily
5 layers, from the top down. Step through them one at a time.
4Shadow Mode: Comparing Old and New
Before the new service makes any real decision, it runs in shadow mode. Requests continue to be handled by the old billing code, but each one is also sent to the new service, whose result is recorded and compared, not used. For billing, we compare invoice totals, tax amounts, line items and payment allocations. Any difference is logged with the inputs so the team can investigate.
We run shadow mode until the difference rate is effectively zero for a full billing cycle, typically at least a month, because monthly invoicing, end-of-month adjustments and year-end rules only appear at those times. Differences are often bugs in the old system, which leads to an important decision: replicate the old behaviour exactly first, fix it later, so that the migration is not mixed with behaviour changes.
5Gradual Cutover With Rollback
We switch real traffic gradually, by a dimension that limits risk: perhaps internal test customers first, then a small country, then small business customers, then everyone else. A routing flag in the BillingApi implementation decides, per customer segment, whether the old module or the new service is in charge. At each stage we watch error rates, reconciliation results and support tickets.
Rollback must stay possible until confidence is high. That means data must flow both ways for migrated segments: if the new service becomes the source of truth for a segment, its changes are synced back to the old tables, so switching the flag back gives the old code current data. This reverse sync is extra work, but it is what makes the cutover a series of reversible steps instead of one big bet.
- Map tables, code and cross-module transactions
- Internal BillingApi and events in the monolithenforce with ArchUnit
- New service with own schema, data syncedCDC or flagged dual-write
- Shadow mode for a full billing cyclecompare totals, taxes, lines
- Cut over one customer segmentreverse sync keeps rollback possible
- Segment healthy?YesMove the next segmentNoSwitch the flag back and fix
- All segments movedremove old code and tables
7 steps in order. Play them, or step through them one at a time.
6Removing the Old Code and Tables
The last step is the one most often skipped: deleting the old billing code, the routing flags, the sync jobs and the Oracle billing tables, after archiving whatever history must be kept for legal reasons. If we skip it, the monolith does not shrink, the old tables keep confusing people, and someone eventually reads from them again. We plan this step with a date and an owner from the start, and we do not declare the extraction finished until it is done.
7Follow-up questions
How do you handle transactions that used to span billing and order tables?
Once billing has its own database, one local transaction can no longer cover both. The usual design is the transactional outbox with a saga: the order is saved together with an OrderPlaced event in the monolith's transaction, the billing service consumes the event and creates the invoice, and if invoicing fails, it publishes a failure event that the order side handles, for example by marking the order as needing attention or cancelling it. Consumers must be idempotent, since events can arrive more than once. This changes the business guarantee from 'both at once' to 'both eventually, with a defined compensation', and that change must be agreed with the business owners.
CDC or dual-write: which would you choose?
For a busy shared Oracle schema, I prefer CDC, because it captures every change, including ones from batch jobs or scripts we do not know about, without modifying the monolith's code. Dual-write is acceptable for a smaller scope if it is behind a flag and checked by a reconciliation job.
What do you do when shadow mode finds the old system was wrong?
Record it, reproduce the old behaviour in the new service for the migration, and fix the bug as a separate, visible change after cutover, with the business informed. Mixing fixes into the migration makes differences impossible to interpret.
8Conclusion
In this answer, we planned the extraction of billing from a ten-year-old monolith: map tables, code and cross-module transactions, build an internal billing API and events with enforced boundaries, create the new service with its own schema and sync data with CDC or a flagged dual-write, run shadow mode for a full billing cycle, cut over by customer segment with reverse sync for rollback, and finally delete the old code and tables. Cross-module transactions become outbox-driven sagas.
Open with
I would start with boundary analysis: list billing's tables, every query from other modules against them, the code dependencies, and especially the transactions that span billing and other modules, like an order and its invoice committed together, because each of those needs a new design.
Then, if they want more
Then, inside the monolith, I would create a proper billing module: a small BillingApi and events like InvoiceIssued, move all other modules and reports onto those, and enforce it with an ArchUnit rule so only billing touches billing tables. Next comes the new service with its own schema.
To keep data in sync during the migration I prefer change data capture from Oracle, for example Debezium, because it catches every change without touching monolith code; a dual-write behind a flag with a daily reconciliation job is the alternative.
Then shadow mode: the old code stays in charge, the new service computes the same results and we compare totals, taxes and lines for at least a full billing cycle. Cutover is gradual, by customer segment, with a routing flag and reverse sync so we can switch back.
For transactions that spanned orders and billing, I would use an outbox and a saga with idempotent consumers and agreed compensations. And finally I would delete the old code and tables, otherwise the monolith never shrinks.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Lead the extraction of the billing module from a 10-year-old Spring monolith with a...": https://scrivio-interview-library.netlify.app/architecture/modernization/a5fa3c3f69/