More than a year has passed since the development of What To Wear Today; many libraries have been updated, and unsettling reports have started coming into Android Vitals. Analytics from Google Analytics and reports from Firebase only confirmed the fears: some users encountered application crashes, and some users encountered problems when paying for a subscription.
Obfuscated logs did not provide much information about what exactly the problem was; however, the use of mapping allowed us to find out that the problem was a conflict between Google Play Billing and one of our own libraries. Since downgrading Google Billing was unacceptable, there was only one way out — a modification in our library.
After a detailed study of the internal structure of the library, let's call it AppBillingWrapper, it was decided to add extended logs in the next application update to confirm the error theory. Such logs would give a detailed understanding of the systemic nature of the error; it was necessary to understand this, since the problems arose only on Android versions 13 and higher.
Refactoring the internal mechanisms of the library did not change its public interfaces, and this allowed us to implement a Feature Toggle system. Why did we need this? The answer is simple: we created an alternative implementation of the public interface of AppBillingWrapper, a complete copy of the current functionality. The introduced Feature Toggle, depending on its value, selected one implementation or the other.
Well, the base for refactoring was ready, and with the next update, we released it into production. The value of the new toggle essentially changed nothing, since the two implementations were completely identical. In this way, we provided users with a mechanism for iterative, releaseless introduction of changes. Yes, it is difficult to call this releaselessness in the full sense of the word, but it was the first step on the path of introducing safe changes.
The next step was the introduction of a system that would allow safely making changes to the code. In other words — so as not to break anything. Here we decided to apply the TDD approach, since we were working with an important payment module, and it would be a shame if something went wrong with subscriptions. It was necessary to fulfill at least the following conditions:
1. Maintain the connected premium if it was previously purchased, that is, make an adequate DB migration system;
2. The number of failures is the same as now or lower;
3. System performance could drop by no more than 10%;
4. Complexity and maintainability (by the way, back then we did not yet have a clear idea of these metrics) should become better;
5. In 95% of cases, the Happy Path for purchasing a subscription should pass successfully. We understood that there is always some probability of discovering platform-dependent bugs, so we left 5% precisely for such cases.
We started by dividing the copy of AppBillingWrapper into blocks. In total, we got 3 blocks where business logic, platform code (DB), and code for working with the billing library were concentrated. Next, we developed a set of Test Cases, which, according to our calculations, covered at least 85-88% of all cases of direct use and unexpected errors. In total, we got 260 test cases. The volume is impressive, but we had to go through this path!
We did the implementation in blocks, meaning the entire process was to consist of 4 stages: 3 blocks and one release to remove the feature toggle. We acted as follows: we removed the code from the implementation sites one by one, leaving only high-level interfaces so as not to break the general logic of the entire feature, wrote falling tests, wrote the implementation, and ran the tests again. The marker is simple — a passed pipeline on the MR gave the right to merge into the feature-refactor branch. Only this way; we did not provide for deviations.
We started with the platform module, did a complete refactoring, brought the changes into the nearest version of the application, and turned on the toggle rollout to 5%. It was scary! But the analytics were silent; everything indicated that the scheme worked and we could continue. We did the rest of the modules according to this principle and rolled out the toggle to 100% of users gradually, over the course of 2 weeks.
After 88% of users updated to the current version, we simply made a small release removing the introduced toggle and deleting the old implementation of AppBillingWrapper.
In total, all the work took us 1 month. As a result, one bug was opened on AppBillingWrapper, the fix of which took us 1 hour of time, since the entire system as a whole became more predictable, transparent, and maintainable.