Understanding microservice boundaries
Definitions of Coupling and Cohesion
Section titled “Definitions of Coupling and Cohesion”- Coupling describes the interdependence between modules or microservices within a system.
- Loose coupling is preferred; systems should aim to minimize dependencies between components.
- Several types of coupling were discussed: runtime (dependency on location or timing, e.g., HTTP calls), temporal (dependency on order or timing of operations), content (direct modification of another’s data, e.g., shared databases), functional (relying on another module’s logic), and sequential (output of one becoming input of another).
- High coupling complicates maintenance, testing, and can lead to cascading failures.
- Cohesion refers to how strongly related the tasks within a module are; high cohesion means components that change together are grouped together.
Strategies for Achieving Loose Coupling and High Cohesion
Section titled “Strategies for Achieving Loose Coupling and High Cohesion”- Use the single responsibility principle: each microservice should focus on one job or functional requirement.
- Communicate in a loosely coupled manner to perform tasks, avoiding strong dependencies between services.
- Avoid shared databases to reduce content coupling when building microservices.
- Pattern-based approaches to reducing coupling will be explained further in later modules.
Historical Context and Constantine’s Law
Section titled “Historical Context and Constantine’s Law”- Concepts of coupling and cohesion were introduced in 1968 by Larry Constantine.
- Constantine’s Law states that high cohesion and low coupling yield stable, maintainable software structures.
- These principles are foundational for routing modern software, especially in microservices architectures.
Practical Considerations and Pitfalls
Section titled “Practical Considerations and Pitfalls”- Cohesion can often be achieved by aligning services around business domains and grouping related changes together.
- Achieving low coupling is more challenging; some coupling is inevitable for collaboration and communication between services.
- The impact of coupling depends on control: if you own all involved services, tight coupling may be manageable; minimal coupling is critical when integrating third-party or external services.
- Excessive coupling can turn microservices into a distributed monolith, diminishing many of the intended benefits.
- Gregor Hohpe’s quote: appropriate coupling depends on your control over service endpoints.
- Further guidance on integration patterns for reducing external coupling will be discussed in subsequent modules.