The Crucial Role of Unit and Performance Testing in Iterative Optimization Algorithm Design

Betul Ahat
Trendyol Tech
Published in
6 min readFeb 12, 2024

Introduction

Mathematical models (see an example in Figure 1) and heuristic algorithms need to be flexible and adaptable so that they can meet the ever-changing demands of the business environment. They require agile modifications due to the dynamic changes in industries like e-commerce, where customer preferences, market trends, and operational needs change very frequently. In this evolving environment, the iterative algorithm development process is essential to retain efficiency.

Figure 1: Order allocation problem - mathematical model

While mathematical models and heuristic algorithms adapt to shifts in the business environment, testing serves as a beneficial tool to maintain efficiency and reliability. It helps the optimization algorithms to remain resilient under fluctuating conditions, thus prevents potential issues to go unnoticed. This can be achieved by developing a large set of test suites that can cover various scenarios and especially edge cases. In this article, we explore the essential role of unit and performance testing in the dynamic iterations of optimization algorithms. Additionally, we share insights into how we, as Trendyol Data Science — Optimization team, leverage this strategy to maintain the robustness and adaptability of our optimization algorithms within the dynamic business landscape.

Unit Testing

Unit testing is a central step of the algorithm development process. It requires to verify that each part of the code operates as intended in isolation. It plays a crucial role in the iterative optimization algorithm development process in many ways:

1. Avoid unintended consequences

While conducting unit tests, a set of scenarios is executed to ensure that the algorithm performs as expected. These tests are helpful to address any inconsistencies in the early stages of algorithm development process. Hence, problematic issues can be identified before they have an impact in the operational flow. This is particularly crucial in large-scale projects, where a change in one part of the code can also impact other components in a production environment.

2. Continuous validation

Unit tests also act as a safeguard in dynamic business environments having fluctuations in customer behavior and changing business requirements. They offer continuous validation and ensure the robustness of the algorithms. As unit tests cover a diverse range of scenarios, they assure that any unforeseen outcomes will be quickly identified during algorithm iterations. By executing unit tests after making changes in some parts of the algorithm, it becomes easy to check whether the code continues to function as expected.

3. Collaborative code maintenance & documentation

When multiple researchers contribute to the iterative algorithm design process, unit tests provide collaborative code maintenance. Each team member can confidently build upon others’ work. In addition, they are a also a good way of documentation in collaborative development process. Team members can use unit tests as a reference to understand the expected outcome of the parts of the code. Using this information, it gets simpler to modify the code for improved performance.

Performance Testing

Performance testing is also a critical phase in the algorithm development process. It involves the simulation of real-world scenarios to evaluate the overall efficiency and stability of the algorithm under various conditions. Two main types of performance testing are load testing and stress testing. The former replicates both normal operational conditions and particularly peak loads. This ensures that the algorithm is able to operate under anticipated user activity. On the other hand, stress testing loads the system above its normal operating limits and assesses its capacity to function under higher loads than usual usage levels. Let us now shift out focus to the benefits of performance testing in iterative algorithm optimization:

1. Testing algorithm efficiency

Performance tests offer valuable insights into the efficiency of algorithms under regular input sizes by replicating real-world settings. They help to identify bottlenecks that may arise due to diverse and dynamic challenges during peak periods. Hence, they serve as a guideline to fine-tune and optimize the overall system performance.

2. Assessing performance under pressure

Since stress testing goes beyond typical operational levels, mathematical models and heuristic algorithms are exposed to excessive load. This is essential to observe the resilience of the system under pressure and gain insights for refining overall system robustness. This proactive approach ensures that the system remains stable even in challenging scenarios, such as unexpected usage spikes.

Ensuring Success in E-commerce: The Power of Testing

The e-commerce industry is known for its dynamic nature and seasonal fluctuations. Thus, robust algorithm designs are essential to ensure sustained success. At Trendyol, our algorithms usually operate in real-time and have an impact on critical processes like order fulfillment and inventory management. Any failure or unexpected outcome in these algorithms can lead to revenue loss, particularly during high-demand periods or special events.

In addition, an important value of Trendyol is to “strive to better everyday”, aiming for continuous progress. To achieve this, instead of waiting for projects to conclude as a whole, we adopt an iterative approach for all tasks. We begin with a minimum viable product, then work on enhancing it along the way as we progress. We are dedicated to find innovative ways to enhance performance every day.

In this journey, we utilize unit tests as a safeguard to ensure flawless operations. By testing particularly on edge cases, we can get critical insights about the performance of the algorithm. These insights help us to address any potential issues before the algorithm reaches the production stage.

Figure 2: An example output of unit testing

As an example, let’s consider the order allocation problem. The objective is to allocate items in an order to specific locations within the warehouse such that picking time and operational costs are minimized. To deal with this challenge, we developed an algorithm based on the mathematical model given in Figure 1. Then, we needed to iterate it several times to handle changes in the business requirements. However, it is essential to satisfy that the total allocated quantity meets customer demand in all cases. In order to guarantee that customer demand is always satisfied, we devised a comprehensive set of scenarios, involving edge cases. By running tests on this set, as seen in the figure below, we ensure that the algorithm behaves as expected. This process of iterative testing enabled us to validate the robustness of our algorithm throughout these iterations.

Figure 3: An example unit test for order allocation problem

Meanwhile, at Trendyol, we encounter varying demands influenced by seasons, holidays, and special events. Also, we usually have limited time solve a problem. To address these challenges, we conduct a performance analysis of our algorithms, as illustrated in the figure below, under heavy loads to observe their ability to react within the given time limit. We can then identify potential improvement areas within the algorithm before they impact real-time operations.

Figure 4: Comparison of algorithm performances

Conclusion

In conclusion, the iterative nature of the algorithm development process requires to adopt a robust testing strategy to maintain efficiency and reliability. This approach lowers the risk of potential issues and undetected errors in the stages. Within each iteration, unit tests assess the validity of our solutions. They enable us to refine our algorithms without compromising the reliability. Simultaneously, performance testing ensures the robustness under diversified operational challenges. By following a comprehensive testing strategy, we can tackle the uncertainties in the dynamic business landscape.

Join Us

We’re building a team of the brightest minds in our industry. Interested in joining us? Visit the pages below to learn more about our open positions.

--

--