liveBook · Manning

Build-time coupling

As explained in Microservices Patterns, Second Edition

Loose build-time coupling is a build dependency property in which changing a build module requires relatively few other subprojects to be recompiled and retested.

Build-time coupling occurs when a change to one build subproject requires another, unchanged subproject to be recompiled and retested. Loose build-time coupling limits that ripple, shortening the wait for feedback and accelerating the deployment pipeline, especially in large codebases. section 4.3 section 4.6

This is distinct from design-time coupling, which concerns whether a change requires changes elsewhere. Build-time coupling can still force unrelated code to be retested even when no source change is needed there. section 4.1.1 section 6.3.4

A Gradle dependency graph

In a food-ordering application, changing the money subproject causes its tests and those of accounting and customer-management to run. Order-management is also retested because it has a transitive dependency on money. Changing customer-management instead affects customer-management and order-management, but not accounting or money. section 4.3.1

Figure 4.9 The dependencies between Gradle projects create build-time coupling. Changing money causes the other projects to be recompiled and retested but changing customer-management only requires customer-management and order-management to be recompiled and retested.
gradle build time coupling

The dependency graph shows why changes to different subprojects have different rebuild and retest scopes. section 4.3.1

Reduce the affected build scope with two physical design choices:

  • Have clients depend on a stable API build project rather than a frequently changing implementation project. Implementation changes then need not trigger client retesting. section 5.4.4
  • Separate implementation code that does not need to be tested together. For example, put web and persistence in separate projects that both depend on domain; a web change then need not run the persistence tests. section 4.3.3 section 6.3.4

Incremental builds are necessary to benefit from a narrower dependency graph: the build tool must skip unaffected work. Splitting projects does not prevent changes to shared dependencies from propagating, and some coupling is inevitable. Parallel or clustered testing can also reduce elapsed time, but can be expensive and complex. section 5.4.4 section 6.3.1 section 4.6

Pay particular attention to build-time coupling in a large monolith, where a single codebase can make the deployment pipeline a bottleneck. It is generally less important within a relatively small microservice, though its build can still benefit from careful organization. section 4.3.3 section 3.2.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines change propagation and explains dependency and project-splitting strategies, including a worked Gradle dependency graph.
Examples
Traces changes through money, accounting, customer-management, and order-management projects and separates web, domain, and persistence projects.
What you can do after
Evaluate build dependencies and reorganize projects to reduce unnecessary recompilation and retesting.
How it connects
Connects build-time coupling to design-time coupling, incremental builds, physical design, and modular monoliths.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.