Yan Cui
I help clients go faster for less using serverless technologies.
“High cohesion, low coupling” is one of the most misunderstood principles in software engineering.
So, let’s clear things up!
TL;DR
Cohesion is about the internal focus of a thing – how well its components work together to fulfil a single purpose.
Coupling is about the external relationships between things – how much they depend on one another.
Cohesion
When applied to a code module, cohesion measures how closely related its functions are.
An Authenticator module will likely have high cohesion because all its functions are related to handling authentication.
On the other hand, a Utils module is likely a dumping ground for unrelated helper functions and will, therefore, have low cohesion.
When applied to a system, cohesion measures how well its components (services, subsystems, etc.) work together to achieve a single goal.
A service with well-defined boundaries and responsibilities will have high cohesion.
Conversely, a system has low cohesion if its components are poorly aligned and have overlapping or unrelated responsibilities. For example, a User service that handles authentication, account management and sending notifications about account updates.
Coupling
A good way to think about coupling is in terms of change propagation. That is, how much does System B need to change if we change System A.
Coupling is everywhere and comes in many different forms.
Some coupling (e.g. data format dependency) requires coordinated changes between systems.
Other forms of couplings are less obvious but more problematic to deal with.
For example, temporal coupling links the availability of one service to another. This often leads to cascade failures and necessitates other practices (e.g. retries, exponential backoff, fallbacks, chaos engineering and so on) to mitigate.
So there you have it, the difference between “Cohesion” and “Coupling”.
They measure similar but, ultimately, different qualities in software.
Hope you learn something new!
Whenever you’re ready, here are 3 ways I can help you:
- Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
- I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
- Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.