Part 3 of 8 · 1 min read
Finding seams
Group the code by context, then look at the dependencies.
BM's method has four steps.
- List the contexts. MusicCorp's monolith is thought to cover four: catalog (data about items for sale), finance (accounts, payments, refunds), warehouse (dispatch, returns, inventory) and recommendation (a complex, specialist system).
- Make a package for each, and move the existing code into them. Modern editors can do the moves automatically, and tests catch breakage. Doing it little by little, alongside other work, is fine.
- Look at what is left over. Code that fits nowhere often points to a context that was missed.
- Analyse the dependencies between packages. The packages should depend on each other the way the real departments do. If the warehouse package depends on the finance package but warehouse staff never depend on finance staff, something is wrong and should be looked into. Tools can draw these links.
This can take an afternoon in a small codebase or months in one with millions of lines. It need not be finished before the first split. It may be better to put the effort in one area.
A worked example (made up). A shop's code has 400 classes. After sorting, 120 are Catalog, 90 Orders, 70 Stock, 60 Payments and 40 fit nowhere. Looking at the 40, 25 are all about customer addresses and 15 are helpers. The 25 reveal a Customer context that nobody had named. The dependency picture shows Stock calling Payments 30 times, which the business does not do, and so it is flagged for repair before any split.
Check yourself: 1. Why look at the code that is left over? 2. What does it mean if the package dependencies do not match the real organisation? 3. Must all code be sorted before the first service is split out?