Using Fitness Functions in architecture: Improving the quality and performance of systems

Have you ever wondered how to improve the quality and performance of IT systems systematically and efficiently? Have you ever heard of the mysterious 'Fitness Functions' tool and its impact on software architecture? If not, this article is just for you! Learn how Fitness Functions can change how you create and improve IT systems, ensuring exceptional performance and reliability.

Generally speaking, a function takes some input (parameters) and generates a result based on those parameters. There can also be functions without parameters, but the key is that functions produce something.

In principle, any code can be wrapped in a function and given a meaningful name. Today, I am showing you fitness functions, which check whether architectural assumptions are met in reality in the written code.

Fitness functions

What sets fitness functions apart from “regular” functions is the fact that fitness functions can also be something that cannot be written in code. Simply put, manual work could be done to check a given architectural characteristic.

Architectures have requirements regarding performance, security, reliability, coding standards, and so on. All these -ilities are called architectural characteristics.

Designing a system and its architecture is not the end of the architect’s work. During development, you need to “go to the construction site” and see if everything is going according to plan. Fitness functions can do this for us; implementing them immediately and observing the results is important.

One of the architecture characteristics is performance, and the assumption is that requests should return in 100ms. You can write a test that checks this and it will be a fitness function.

If I had a requirement that the frontend application has a performance greater than 80 points in Google Pagespeed, I could set up a tool to check this on CI after each deployment of a new version.

Fitness functions can also measure coding standards, for example, whether the cyclomatic complexity is low or whether the unit test coverage is what we want.

Fitness functions can also measure coding standards, for example, whether the cyclomatic complexity is low or whether the unit test coverage is what we want.


Atomic fitness functions

Atomic functions check a selected characteristic of architecture in isolation. Such an atomic function only checks one aspect of architecture and does not worry about anything else.

Holistic fitness functions

Holistic functions can measure several aspects at the same time (e.g. performance and scaling). You can check how architecture performs in a real environment thanks to holistic fitness functions.

Static

Static fitness functions have a constant result, like a unit test that can be green or red. E.g., a fitness function that measures performance.

Dynamic

Dynamic fitness functions are those in which the result can vary depending on the circumstances. In such cases, a range of values may be acceptable for which we assume the fitness function has succeeded. For example, when measuring scalability and performance, we accept that performance may be slightly worse at a larger scale (but still within the range defined by us).


Practical Examples of Fitness Function Application

Example 1: Checking Application Security

Security is one of the most important characteristics of architecture, especially in today’s world where hackers and cybercriminals are becoming increasingly advanced.

Fitness functions help to check whether an application meets security requirements. An example of a fitness function checks whether the application always uses the HTTPS protocol to ensure a secure connection.

Example 2: Checking Application Performance

Performance is another important characteristic of architecture. Fitness functions can help check whether an application works fast and efficiently. For example, a fitness function can be created that monitors the server response time to HTTP requests and reacts when this time exceeds a certain level.

Another example may be a fitness function that checks whether the application is stable under load, for example, by testing the application using different load scenarios.

Example 3: Checking Compliance with Business Requirements

Fitness functions help to check whether the application architecture meets business requirements. For example, a fitness function can be created that monitors the use of system resources (such as memory and CPU) and reacts when it exceeds a certain level, which may mean that the application does not meet business requirements.

Another example may be a fitness function that checks whether the application returns expected results for different business scenarios, for example, by testing the application using different test data sets.

Example 4: Code quality checking

Fitness functions can help maintain high code quality in applications. For example, a fitness function can be created to check whether the code meets certain coding standards, such as by analyzing the code for cyclomatic complexity and other metrics. Another example could be a fitness function that checks whether the code complies with the SOLID and DRY principles, which are basic software design principles.

Example 5: Data integrity checking

Data integrity is another important characteristic of architecture, especially in the case of business applications that handle large amounts of data. Fitness functions can help ensure that data is correct and not damaged or lost.

For example, a fitness function can monitor data consistency between different data sources and respond when a discrepancy is detected.

How to evaluate the effectiveness of your architecture?

Evaluating the effectiveness of architecture is critical to ensuring the high quality and performance of systems. Fitness functions allow for automatic evaluation of architecture effectiveness, but what criteria and indicators should be monitored?

Here are a few practical tips:

  1. Define your business goals - before starting to monitor the effectiveness of your architecture, you need to know what business goals you want to achieve. For example, your goal is to increase the number of users. In that case, you need to monitor whether your architecture provides sufficient performance and scalability to handle more users.

  2. Identify critical architecture points - identify the most important parts of your architecture and determine which ones are most important for achieving your business goals. Focus on these critical points to ensure that they are effective and efficient.

  3. Monitor performance indicators - select several important performance indicators, such as response time, throughput, server load, resource consumption, etc. and monitor them regularly. If these indicators exceed the thresholds set for you, it means that your architecture may require further improvements.

  4. Monitor code quality - code quality directly impacts the effectiveness and efficiency of architecture, so monitoring code quality is crucial. Use code analysis tools to assess the quality of your code and monitor metrics such as cyclomatic complexity, number of errors, test coverage, etc.

  5. Test systems in a production environment - testing systems in a production environment is crucial for evaluating the effectiveness and efficiency of architecture. However, remember that testing in a production environment involves risks, so you must apply appropriate procedures and tools to minimize the risk of failure.

  6. Define fitness functions - fitness functions allow for automatic evaluation of architecture effectiveness. Define fitness functions appropriate for your architecture and monitor results regularly. Fitness functions should be defined in such a way as to reflect your business goals and critical points of architecture.

Evaluating architectural effectiveness is a continuous process. Monitor your architecture regularly to ensure that it meets your business goals and provides high-quality and performance systems.


Summary

Fitness functions are a mechanism for checking whether architectural assumptions are met in the written code. Fitness functions can be something that cannot be written in code, such as manual work to verify a given architectural characteristic. They can also be tests, monitoring, and other tools.

Thanks to them, we can measure performance, security, reliability, coding standards, etc. Fitness functions can be divided into atomic and holistic, static and dynamic.

Examples of fitness function applications include checking the security of applications, application performance, compliance with business requirements, code quality, and data integrity.

Evaluating the effectiveness of architecture is a continuous process. Monitoring selected performance indicators, code quality, and testing systems in a production environment allows for evaluating the effectiveness of architecture and adapting it to changing business requirements.

Fitness functions are a tool that enables the automatic verification of architectural characteristics and facilitates the maintenance of system quality and performance.

Sources

Subscribe my blog