The fitness function is a concept borrowed from genetics, It represents a metric used in evolutionary algorithms to evaluate how well a solution performs at solving a given task.
The idea was introduced into software development through the book Building Evolutionary Architectures. It describes how fitness functions help continuously evolve architecture in the right direction through automated checks. Simply put, they are a way to ensure that our system gets better (or at least stays the same) rather than worse.
Fitness functions are automated checks that evaluate the non-functional characteristics of a system. They help assess whether we are maintaining the desired quality level or need to make changes.
Large systems developed by teams of many engineers typically face various constraints. For instance, storing personal data in a specific format or ensuring access control to prevent data leaks. There are also non-functional requirements, such as the ability to quickly modify code for testing business hypotheses or to scale under peak loads during promotional campaigns.
Some of these constraints and requirements can be automatically verified using fitness functions. For example:
The complexity of adding fitness functions to a project depends on the stack being used. For instance, if a project uses a modular architecture with separate deployments, you can use a tool like Deptrac, in PHP to automatically check dependencies between modules. However, I’m unsure if similar tools are available for your language. In some cases, ready-made tools may not exist for specific programming languages or frameworks. This might require manual checks or developing custom solutions for creating fitness functions.
Fitness functions are a powerful tool for maintaining the quality of large systems, especially those that evolve quickly and face high demands for stability and flexibility. They allow teams to focus on development rather than manual compliance checks.