How to replace a renderer while invoices keep shipping
On this page
A migration seam makes two renderers interchangeable. A comparison contract tells you when switching is safe.
Your invoicing library is being retired. Replacing every call in one release couples the new dependency to date formatting, page breaks, archived invoices and the email queue. Start with the caller that already knows what a finished invoice means.
Choose a boundary you can observe
Move one caller behind a function that accepts an invoice and returns document bytes. Keep the old engine behind it first. PDF metadata, font embedding and object order can change while the printed invoice stays identical. A byte-for-byte golden file would turn those implementation details into promises.
Instead, prepare a small comparison ledger. For a refund case, require the same signed total, currency, tax breakdown and customer identifier. For a long-address case, inspect a rendered page for clipped digits. For a two-page case, inspect repeated headers and ensure totals appear once. These checks answer different questions. Searching extracted text will happily find a total printed outside the page.
Control effects during the comparison
Give both renderers the same input snapshot, locale and issue date. Store both outputs in a test directory. Put email delivery outside the comparison boundary so that one invoice generates one customer message. Once a cohort passes, route its real render requests to the new implementation while keeping a switch back for inputs that still work with the old engine.
Fowler describes this gradual replacement as branch by abstraction. Its less celebrated final step matters here. Once archived invoices and live jobs can all use the new renderer, remove the temporary routing code. Keep the comparison ledger as a regression suite for the properties customers actually depend on. Martin Fowler on branch by abstraction.