Fitness Function
Also known as: architectural fitness function
An architectural fitness function is an automated, objective test of a non-functional requirement — coupling, latency, security posture, cost — run continuously in CI. It turns an architectural intention into something that can fail a build, which is the only mechanism that reliably prevents slow erosion.
Last reviewed · Part of the Architecture Glossary
In practice
Every fitness function needs three things, and a rule missing any of them is a wish:
- A metric — cyclomatic complexity, p99 latency, count of forbidden imports, bundle size in KB.
- A threshold — the value at which the build fails, chosen from today's number so it ratchets rather than blocks.
- A place it runs — pre-merge CI, nightly, or continuously in production.
Concrete examples:
| Attribute | Function | Threshold |
|---|---|---|
| Modularity | ArchUnit: no domain to infrastructure imports | 0 violations |
| Performance | k6 smoke test p95 on the checkout path | < 400 ms |
| Security | npm audit / Trivy on the built image | 0 critical |
| Cost | Infracost delta on the Terraform plan | < $50/month |
| Resilience | Chaos experiment: kill one AZ | SLO holds |
When it matters
Any architectural characteristic you have written down and expect to still be true in a year. Coupling rules in particular decay within two sprints of being agreed verbally.
Common mistake
Setting the threshold at the aspirational value, so the build is red on day one and someone adds continue-on-error. Set it at the current measurement, fail on regression, and tighten it deliberately.
See also
- Blast RadiusBlast radius is the extent of damage a single failure or change can cause — how many users, tenants, regions or services are affected when one component fails.
- SLO (Service Level Objective)An SLO is a target value for an SLI over a window — for example, 99.9% of requests succeed over 28 days.
- Contract TestingContract testing verifies that a provider's API satisfies the expectations its consumers actually rely on, by running each consumer's recorded expectations against the provider in isolation.