


Hardcore stuff: a journey of reconstruction of more than 30,000 lines of code in a core system
01 Let’s first talk about the historical baggage of this system
Our advertising engine went through about a year and a half before this reconstruction. The initial iteration is focused on search scenarios, with single business and clear processes.
#1. The business scenario began to become complex. In addition to search advertising, there were also It is necessary to support information flow recommendation and similar recommendation scenarios.
2. Advertising traffic begins to increase rapidly. In addition to meeting functional requirements, it is also necessary to take into account performance.
After sorting out, most of the logic of the entire engine can be shared, so we defined a main framework and made it extensible Partially abstracted. In this way, each scenario can implement certain public interfaces according to the particularity of its own business. In addition, from a performance perspective, we sacrificed some code readability and parallelized some logic.
With the development of business, search scenarios began to enter a rapid iteration period, with more and more new strategies added, and our main framework gradually became inflexible at this time.
1. In order to be compatible with the special logic of search , we need to add various if judgments in other scenarios to bypass these logics.
2. There are more and more advertising strategies, dozens in total. When the framework loses its clear structure, the implementation of some strategies begins to become customized and lacks hierarchical divisions. and pluggable abstract design.

##The turning point came at the end of 2019. Due to the particularity of the advertising business, traffic began to naturally decline. In addition, the product operation team The focus is on the work planning for the second year, thus giving us a very good window period to start this reconstruction.
We set the construction period to 1 month, and in the end was only online one day later than expected. Although there were two online problems, but in Grayscale They were discovered and repaired in time, and no online accidents were caused.
02 What preparations have we done before refactoring?
The amount of code refactored this time is very large, more than 30,000 lines, and it is the core engine part of the advertising system. Before starting, we can anticipate the following difficulties:
#1, Resistance on the business side : Advertising is extremely business-oriented. Although this reconstruction can improve long-term R&D efficiency, it cannot directly improve business income, and the development cycle will not be too short. How can we get support from business classmates? ?
▍Let everyone see the pain points
As mentioned earlier: With the business iteration, the main framework of our advertising engine has become blurred, and dozens of advertising strategies are scattered in different business scenarios, with messy configurations.
In view of these two pain points, we started sorting out the existing business one month in advance, reading the old code and looking through the previous requirements documents. Finally, we combined the core processes of different scenarios. and advertising strategies categorized into a clear table.
It is this table that allows technology and products to clearly see the whole picture of our engine part for the first time, and understand the complexity of the business and the current technical bottlenecks.
▍Clear the goals and values of refactoring
Let everyone feel the pain points Finally, we planned two core goals for this reconstruction:
1. Reconstruction of the main framework: modularize the main process, Redefine the upper and lower layer protocols to ensure clear interfaces; each layer also needs to be abstracted and have good scalability.
2. Flexible and configurable strategies: Advertising strategies are classified and abstracted according to business intentions, the execution conditions of the strategies are dynamically configurable, and the strategies can be plugged in and out at will.
In addition, we have refined the expected benefits that can be brought about after completing these two core goals:
#1. Technical benefits: The code structure is clearer, easier to understand and maintain; the scalability is enhanced, and the engine development efficiency will be further improved.
2. Business benefits: Strategies can achieve more fine-grained configuration and expansion, and are more friendly to business support; improved R&D efficiency can further speed up business iteration.
##▍Control of the overall rhythm
The control of the overall rhythm is also a very important part, allowing everyone to have a time expectation for this matter.
First of all, we set the construction period to 1 month. On the one hand, we considered the maximum cycle acceptable to the business side, and we also hoped for a quick solution technically; on the other hand, the Spring Festival is about to Come, we must rush to go online before the company shuts down the network, and reserve a buffer of 1-2 weeks to prevent unexpected situations.
03 What experiences can you share during the implementation process?
1. High-quality technical design plan
This is due to daily requirements. We will design technical solutions for projects with a development cycle of more than 3 days, and this reconstruction is of course no exception.
The overall architecture of the framework, the protocol design between modules, and the scalability design of the strategy are the focus of this technical solution. The team discussed it no less than three times. .
After the big plan was finalized, the team further refined the public parts such as database, interface fields, cache structure, log buried points, etc. Because it involves multi-person collaborative development, the team agreed Using documents as the communication interface, documents are always synchronized with code.
2. Pre-reconstruct the framework code
This PR is very critical, it is our technical solution The most important step to landing on the code. We have sorted out the reconstructed package structure, module division, API definition between each layer, and abstraction of different advertising strategies, ignoring the implementation details first.
In this way, the main body of the code is basically formed, which can clearly depict our ideal framework. We then organized multiple centralized code reviews and finally formed a unified opinion.
This step can well avoid getting caught up in implementation details too early, resulting in insufficient attention to the main framework and unstable code. Rework later will drag down efficiency.
3. Frequent communication and paired code review mechanism
After entering the detailed implementation stage, a very important point is: review the existing Logical understanding. The engine code has been iterated for a year and a half. It has been developed by many people in history, but this time only three students participated in the reconstruction.
#During the whole process, whenever we encountered any unclear code logic, we communicated and verified repeatedly and did not make subjective guesses. This caution is actually very important.
In addition, in terms of code review, we assigned students who are familiar with this business to be responsible for each module. They are paired in pairs and the mechanism is flexible.
4. Effective test plan
Refactoring has not been done, testing first. This principle is emphasized in the book "Refactoring" and is also the focus of our discussion of this technical solution. I will single it out here to expand on it in detail.
First of all, we made an agreement in the early stage: not to leave any old code, and completely build a new package for reconstruction. This makes it easy to compare the results before and after reconstruction and conduct online grayscale experiments at the same time.
Regarding the test plan, the following 4 points are worth learning from:
1 . End-to-end testing: This reconstruction does not involve functional adjustments, so the behavior of the outer API will not change. This end-to-end testing method is the most effective. This is the most important means of R&D and QA testing. .
2. Smoke test: QA students provide smoke cases, and R&D students conduct smoke. Before R&D tests, all smoke cases must be passed. . This is not common in most Internet companies, but it is absolutely effective for large projects.
3. Sandbox environment dual-process verification: As mentioned earlier, the code before and after our reconstruction is retained, so the input parameters of the online environment can be captured through scripts as a case, and then Use an automated method to compare the returned fields of the API one by one.
4. Online environment grayscale experiment: Grayscale is very important for reconstruction. We use the existing ABTest platform to gradually liberalize grayscale traffic, starting from 5% , to 10%, to 30%, and finally to 100%, a very cautious pace of volume increase was established, and then verified through logs and business indicator monitoring.
Write at the end
Review the entire reconstruction process and summarize it into the following 7 Key points:
7. Verify carefully and be responsible for every line of code
Of course, the most critical factor is people. Large-scale project refactoring extremely tests the team's collaboration ability. If everyone is reliable, the refactoring is already half successful.
The above is the detailed content of Hardcore stuff: a journey of reconstruction of more than 30,000 lines of code in a core system. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

The best version of the Apple 16 system is iOS16.1.4. The best version of the iOS16 system may vary from person to person. The additions and improvements in daily use experience have also been praised by many users. Which version of the Apple 16 system is the best? Answer: iOS16.1.4 The best version of the iOS 16 system may vary from person to person. According to public information, iOS16, launched in 2022, is considered a very stable and performant version, and users are quite satisfied with its overall experience. In addition, the addition of new features and improvements in daily use experience in iOS16 have also been well received by many users. Especially in terms of updated battery life, signal performance and heating control, user feedback has been relatively positive. However, considering iPhone14

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

A computer operating system is a system used to manage computer hardware and software programs. It is also an operating system program developed based on all software systems. Different operating systems have different users. So what are the computer systems? Below, the editor will share with you what computer operating systems are. The so-called operating system is to manage computer hardware and software programs. All software is developed based on operating system programs. In fact, there are many types of operating systems, including those for industrial use, commercial use, and personal use, covering a wide range of applications. Below, the editor will explain to you what computer operating systems are. What computer operating systems are Windows systems? The Windows system is an operating system developed by Microsoft Corporation of the United States. than the most

Detailed explanation of the method of modifying the system date in the Oracle database. In the Oracle database, the method of modifying the system date mainly involves modifying the NLS_DATE_FORMAT parameter and using the SYSDATE function. This article will introduce these two methods and their specific code examples in detail to help readers better understand and master the operation of modifying the system date in the Oracle database. 1. Modify NLS_DATE_FORMAT parameter method NLS_DATE_FORMAT is Oracle data

Linux and Windows are two common operating systems, representing the open source Linux system and the commercial Windows system respectively. In both operating systems, there is a command line interface for users to interact with the operating system. In Linux systems, users use the Shell command line, while in Windows systems, users use the cmd command line. The Shell command line in Linux system is a very powerful tool that can complete almost all system management tasks.

After installing the win10 operating system on our computers, some friends may experience a system blue screen and prompt error code 0xc0000428 when using the computer. Don't worry about this kind of problem. The editor thinks that we can troubleshoot the problem on the system first to see if it is caused by hardware or software, and then solve the problem in a targeted manner. Let’s take a look at what the editor did for the specific details~ How to solve the problem of 0xc0000428 in win10 system 1. Restart continuously and then force shutdown three times to let the win10 system automatically enter the advanced startup options. 2. In the win10 system advanced startup options interface, open in sequence: Troubleshooting-Advanced Options-Startup Settings, in Startup Settings
