Achieving modularity 00:00:00 Make a prediction You will define the contract between two modules and recognize work that needs an explicit consistency plan across the boundary. An order module reads pricing's private database tables. If pricing splits one table into two with the same business meaning, can order creation still break? Yes. A private representation has become a public dependency. Ask pricing for a quote with total and currency; the order module then depends on what it needs, rather than on how the answer is stored. 00:00:35 Wagons that hook on A train can replace its milk wagon without rebuilding its timber wagon because each joins with the same agreed coupling. Unbolting the milk wagon's wall to reach the timber wagon would defeat the separation. Export a small capability at a module boundary and hide implementation details. Contracts also define which failures and consistency guarantees can cross. A module is a group of code with one responsibility, a public interface and a hidden implementation. In Java it may be a package or a module, in Python a package, in TypeScript a folder with an index.ts, in C++ a header with a source file or a C++20 module. People can hold only so much in their head. With modules you read one inside and a few faces, not the whole program. 00:01:27 Change pricing behind one boundary The order module needs a price for a basket. If it queries pricing's private tables directly, a pricing migration breaks order creation. Expose a quote operation returning a small value with total and currency. The pricing module can change its internal rule representation. Test the order module with a fixed quote and test pricing with its own examples. The contract test checks that both agree on rounding and currency. Change catalogue storage from decimal units to minor units. The basket should still receive a money amount with its currency. If a basket caller suddenly multiplies by one hundred, the internal representation has escaped through the public pricing boundary. 00:02:10 Put cross-module work on the diagram Placing an order also deducts inventory. In one process and one database a transaction may cover both modules. If they move apart, the workflow needs explicit pending, failure and recovery states. A well-drawn module boundary reveals the decision instead of making it disappear. Pause after inventory deduction and force order creation to fail. The design must either roll back the deduction or record a recoverable intermediate state. Drawing a box around inventory alone hides this cross-module obligation; trace the failure all the way back to the customer. One process with several modules is still one deployment. Separate module names do not automatically give independent failure or release behaviour. Keep a single database transaction when that meets the present requirements. Introduce pending states and recovery only when the operation truly spans independently failing systems. The Java platform exposes modules with explicit dependencies. An application can select the modules it requires when it builds a runtime image. The important point for our design is visibility. An internal representation can change behind an exported interface; consumers should not have to import an unexported implementation detail just to perform an advertised operation. 00:03:34 Try an interview follow-up How do you change a public interface with 30 callers? I would add the new method first and keep the old entry point working through the new implementation. Then I would migrate callers and count real calls to the old method. I would remove it only after a full usage cycle with no traffic, including test doubles and adapters that depend on the contract. The catalogue starts storing prices in minor currency units. Which basket code should change? Keep the representation inside the catalogue module and expose a money value through its interface. Then trace the public call and its tests. A folder boundary alone cannot protect a caller that still reads the catalogue table directly. 00:04:21 What to take with you Modularity means parts with one job, a small public face and a hidden inside. Good borders hide decisions that may change, so a change stays in one module. Package by feature, keep dependencies acyclic, and pass only small values across. Languages help to different degrees, so let the build check imports, internals and cycles. Give each module its own data. A modular monolith is a fine place to stay; split into services when independent release, scale or failure is worth the network.