Parallel Method and System for Cloud Migration Based on Nginx Image Splitting Technology
By using Nginx mirroring technology to asynchronously copy mirror requests and perform difference comparisons at the Nginx reverse proxy layer, the problem of insufficient test coverage and switching risks in existing cloud migration methods is solved. This enables security verification and smooth transition driven by real traffic, reducing costs and risks.
Patent Information
- Application Number
- CN202611298410.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-11-17
AI Technical Summary
The existing method of full regression testing plus one-time flow switching to cloud migration has shortcomings such as insufficient test coverage, uncontrollable switching risks, inability to conduct verification and production in parallel, and high manpower and time costs. It cannot fully verify the new system using real production traffic without affecting the online production environment.
The Nginx mirroring technology is adopted. Through the ngx_http_mirror_module module of the Nginx reverse proxy layer, the mirror request is asynchronously copied to the target system to be migrated in the isolated mirror environment within the same call cycle of the client request, and the mirror response is discarded without affecting the production environment. The system is verified by traffic recording and difference comparison modules, and a set observation period indicator system is set to ensure smooth switching and rollback.
It enables comprehensive verification of the new system using real production traffic without the user's awareness, eliminates the difference between test data and production environment, automatically detects response differences, reduces manpower and time costs, ensures the security and controllability of the migration process, and provides a smooth online transition mechanism.
Smart Images

Figure CN123123365A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of cloud migration technology, and in particular to a parallel method and system for cloud migration based on Nginx image splitting technology. Background Technology
[0002] With the continuous advancement of information technology application innovation, various industries are accelerating the localization migration and adaptation of their IT systems. In this process, the complete migration of business systems running on the old architecture to a new technology platform (i.e., cloud migration) is one of the core aspects of the migration work.
[0003] Currently, the industry's commonly used cloud migration method is a full regression test + one-time traffic switching model. The basic process is as follows: First, the target system to be migrated is built on the new platform; second, testers manually construct test datasets and write test cases based on their understanding of the old system's business logic; then, full functional regression testing is performed on the target system to be migrated in an independent test environment; finally, after the test passes, a low-peak business period is selected, and all production traffic is switched from the old system to the new system in one go by modifying the domain name resolution configuration or network routing policy.
[0004] However, the aforementioned existing technical solutions have revealed the following problems in actual engineering:
[0005] First, there is a fundamental difference between test data and the production environment. The above approach relies on manually constructed test datasets to verify the business logic and processing capabilities of the new system. However, manually constructed test data, in terms of scale, distribution, and complexity, cannot truly reflect the actual traffic characteristics of the online production environment. Many edge scenarios, abnormal inputs, and complex business combinations are difficult to cover in manual testing, resulting in the exposure of numerous defects in the new system that were not discovered during the testing phase after the switchover and deployment.
[0006] Second, the one-time traffic switching mode carries an irreversible high risk. The above-mentioned solution redirects all production traffic to the new system at once during the switchover, while the old system simultaneously ceases service. If the new system experiences functional abnormalities, performance bottlenecks, or data processing errors under real production traffic, it will directly lead to business interruption. Even if an emergency rollback is initiated, it requires reconfiguring domain name resolution or routing, and the effective propagation of DNS resolution has a delay of several minutes to several hours, during which business continues to suffer. This all-or-nothing switchover method in this embodiment leaves the migration process without a buffer or observation window.
[0007] Third, migration verification and production operation cannot be carried out in parallel. In the above scheme, the test environment and the production environment are two completely isolated independent facilities. After the new system completes verification in the test environment, it faces a binary decision of whether to go live or not. Once it is decided to go live, the new system will directly bear all production traffic, and it will be impossible to observe the performance of the new system under real production traffic before the actual traffic is switched; if it is decided not to go live, the migration work will be suspended, and the invested engineering resources will not generate any phased benefits.
[0008] Fourth, the costs in terms of manpower and time are high. The above solutions require testers to invest a significant amount of time in constructing test data and writing test cases. For an old business system that has been running for many years, its business logic is often scattered throughout the code, database stored procedures, and operation and maintenance scripts, lacking complete technical documentation. Testers find it difficult to construct comprehensive test scenarios within a limited time. This results in regression testing cycles that can easily last for several months, severely slowing down the migration progress.
[0009] In summary, the existing full regression testing + one-time flow switching to cloud migration method has shortcomings such as insufficient test coverage, uncontrollable switching risks, inability to conduct verification and production in parallel, and high manpower and time costs. There is an urgent need for a migration solution that can fully verify the new system using real production traffic without affecting the online production environment. Summary of the Invention
[0010] To address the aforementioned technical challenges, this invention provides a parallel cloud migration method and system based on Nginx mirroring technology. The aim is to asynchronously and non-blockingly copy an equivalent mirror request to the target system in an isolated mirror environment within the same call cycle where client business requests are normally forwarded to the backend production service and a response is returned. The mirror response is then discarded and not returned to the client. This allows for real-time driving and verification of the new system using real production traffic, without any intrusion into the production environment or user awareness. Furthermore, through traffic recording and difference comparison, as well as a controllable switching and rollback mechanism based on observation period indicators, a smooth transition and controllable risks are achieved throughout the entire cloud migration process.
[0011] To achieve the above objectives, this application proposes a parallel cloud migration method based on Nginx image splitting technology, comprising the following steps:
[0012] Receive business requests sent by clients at the Nginx reverse proxy;
[0013] The Nginx reverse proxy forwards the business request to the backend production service for processing, records the call chain identifier of the business request, and returns the production response returned by the backend production service as the final response to the client.
[0014] Within the same call cycle when the business request is forwarded to the backend production service, the business request is copied asynchronously and non-blockingly using the ngx_http_mirror_module built into the Nginx reverse proxy to generate a mirror request, and the mirror request is sent to at least one target system to be migrated in an isolated mirror environment.
[0015] The image response generated by the target system to be migrated after processing the image request is discarded by the Nginx reverse proxy and is not included in the synthesis of the final response.
[0016] As a further solution, the mirror request is completely consistent with the business request in terms of HTTP method, request URI, request header, request body, cookie, and calling context, so that the mirror request constitutes a lossless equivalent copy of the business request.
[0017] As a further solution, during the Nginx configuration phase, request body replication is explicitly enabled using the mirror_request_body on directive, and the original domain name, original request URI, original cookie, token, and the call chain identifier are passed through to the target system to be migrated using the proxy_set_header directive.
[0018] Wherein, the original request URI is the original request URI when the client initiates the business request; the load balancing strategy and domain name resolution strategy of the target system to be migrated are isomorphic to the backend production service side, so that the mirror request enters the target system to be migrated as an equivalent production call.
[0019] As a further solution, the target systems to be migrated are multiple, including cloud migration target systems, as well as at least one of the gray release version system and the A / B experimental version system;
[0020] By configuring multiple mirror target addresses in array form using the mirror directive, the Nginx reverse proxy can send mirror requests to all mirror target addresses concurrently in an asynchronous and non-blocking manner within the same request cycle, enabling a single client access to drive multiple sets of environments to be verified in parallel.
[0021] As a further solution, the mirroring request is forwarded through an internal endpoint declared as internal in the Nginx configuration, and the access logs of the internal endpoint are turned off;
[0022] The read timeout and connection timeout for the mirror request are both configured to be less than the corresponding timeout for forwarding the business request to the backend production service. This ensures that any anomalies on the target system side to be migrated are detected by the Nginx reverse proxy before they affect the normal return of the production response, and the corresponding mirror response is discarded without affecting the normal return of the production response.
[0023] As a further solution, it also includes:
[0024] Deploy a traffic recording and difference comparison module at the gateway or access layer on the mirror environment side. The traffic recording and difference comparison module uses the call chain identifier as the association key to record the mirror response status code, mirror response body and mirror response time generated by the mirror request in the target system to be migrated, and compares the difference with the production response returned by the backend production service under the same call chain identifier, generates a difference report and outputs alarm events.
[0025] As a further solution, the difference comparison includes field-level comparison, structure-level comparison, and semantic-level comparison; the difference report and the alarm event are output to the operation and maintenance and R&D personnel through a bypass message channel, and do not participate in the synthesis of the response returned to the client, nor do they affect the production paths of the backend production service and the target system to be migrated.
[0026] As a further solution, it also includes:
[0027] Based on the difference report, a quantifiable observation period indicator system is set. After parallel verification and continuous operation meet the preset observation period conditions, the resolution weight or reverse proxy entry of the production domain name is gradually switched from the backend production service to the target system to be migrated according to the predetermined switching strategy to achieve smooth online. If any observation indicator exceeds the limit, a rollback strategy is triggered to keep the production path of the request processed by the backend production service unchanged.
[0028] As a further solution, the observation period indicator system includes at least one of the following:
[0029] The difference rate is the ratio of the number of difference requests to the total number of image requests.
[0030] P99 response delay deviation, which is the difference between the mirror response P99 delay and the production response P99 delay;
[0031] Business key field consistency refers to the consistency rate of values of specified business fields in the mirror response and the production response.
[0032] On the other hand, the present invention also provides a parallel cloud migration system based on Nginx image splitting technology, used to implement a parallel cloud migration method based on Nginx image splitting technology as described in any of the preceding claims, including:
[0033] The Nginx reverse proxy module includes a built-in ngx_http_mirror_module, which receives business requests from clients, forwards them to backend production services for processing, records the call chain identifier of the business requests, and returns the production response from the backend production service as the final response to the client. Furthermore, within the same call cycle of forwarding the business request to the backend production service, the ngx_http_mirror_module asynchronously and non-blockingly replicates the business request to generate a mirror request, and sends the mirror request to at least one target system to be migrated in an isolated mirror environment. The mirror response generated by the target system after processing the mirror request is discarded by the Nginx reverse proxy module and does not participate in the synthesis of the final response.
[0034] The traffic recording and difference comparison module is deployed on the gateway or access layer of the mirror environment side. It is used to record the mirror response status code, mirror response body and mirror response time generated by the mirror request in the target system to be migrated, using the call chain identifier as the association key, and to compare the difference with the production response returned by the backend production service under the same call chain identifier, generate a difference report and output alarm events.
[0035] The switchback control module is used to set a quantifiable observation period indicator system based on the difference report. After the system has been running continuously and meets the preset observation period conditions, the resolution weight of the production domain name or the reverse proxy entry point is gradually switched from the backend production service to the target system to be migrated according to the predetermined switch strategy to achieve smooth online. In addition, when any observation indicator exceeds the limit, the rollback strategy is triggered to keep the production path of the request processed by the backend production service unchanged.
[0036] Compared with related technologies, the parallel cloud migration method and system based on Nginx image splitting technology provided by this invention has the following advantages:
[0037] 1. This invention utilizes the ngx_http_mirror_module, an Nginx reverse proxy, to seamlessly replicate each piece of real production traffic into a mirror request and drive the target system to be migrated. The mirror request maintains complete consistency with the business request in terms of HTTP method, request URI, request header, request body, cookies, and call context, enabling the target system to be migrated to be validated under identical input conditions to the backend production service. This fundamentally eliminates the difference between test data and the production environment, covering all business scenarios that are difficult to reach through manual testing. Simultaneously, based on a call chain identifier-based difference comparison mechanism, it can automatically detect any differences between the mirror response and the production response at the field, structural, and semantic levels, avoiding omissions that may occur during manual comparison.
[0038] 2. This invention ensures absolute security of the production environment through the following triple isolation mechanism: First, image calls are executed asynchronously and non-blockingly, and do not participate in the waiting sequence for the final client response. The processing result of the image response is directly discarded by the Nginx reverse proxy, and the client is completely unaware of the existence of image traffic splitting. Second, image requests are forwarded through internal endpoints declared internally, and access logs are turned off, so image traffic will not pollute the main access log of the production environment. Third, the read timeout and connection timeout on the image side are configured to be strictly less than the corresponding timeout on the backend production service side, ensuring that any anomalies on the target system side to be migrated are detected by the Nginx reverse proxy before affecting the normal return of the production response and the corresponding image response is discarded.
[0039] Under the protection of the above three mechanisms, even if the target system to be migrated experiences a crash, deadlock, or timeout, the response latency and service level agreement of the production environment will not be affected.
[0040] 3. This invention deploys a traffic recording and difference comparison module independently on the mirror environment side. Using the call chain identifier as the association key, it performs three-level difference comparisons—field-level, structure-level, and semantic-level—on each mirror response and its corresponding production response, generating difference reports and outputting alarm events. This provides continuous and quantifiable verification data for operations and development personnel. The team assesses the maturity of the target system to be migrated based on the verification results of real production traffic, rather than relying on limited test case pass rates, thus enabling them to make more confident deployment decisions.
[0041] 4. This invention eliminates the need for constructing test data and building a separate test script system. A single production traffic stream can simultaneously drive the backend production service and the target system to be migrated. The entire process of traffic replication, image sending, and response discarding is automatically completed by the Nginx reverse proxy. The entire parallel verification channel can be set up with only a few lines of Nginx configuration, significantly saving manpower, machine, and time costs. Furthermore, by configuring multiple mirror target addresses in array form using the mirror directive, multiple verification environments, such as the target system for cloud migration, the canary release version system, and the A / B experimental version system, can be driven in parallel within a single client access, further improving verification efficiency.
[0042] 5. This invention establishes a quantifiable observation period indicator system, including difference rate, P99 response latency deviation, and consistency of key business fields. After parallel verification confirms that continuous operation meets the preset observation period conditions, a gradient weight adjustment or a canary switching strategy based on business lines or user groups is adopted to gradually switch production traffic from the backend production service to the target system to be migrated. The performance of the new system can be continuously observed at each gradient stage, and the switching can be paused once a problem is detected. If any observed indicator exceeds the limit during the observation period, a rollback strategy is triggered to maintain the production path for requests processed by the backend production service unchanged. The rollback operation can be completed by restoring the domain name resolution weight or resetting the reverse proxy routing configuration. The entire process is completed within minutes, with zero impact on online business. Attached Figure Description
[0043] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0044] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 A schematic diagram illustrating the steps of a parallel cloud migration method based on Nginx image splitting technology provided by this invention;
[0046] Figure 2 A schematic diagram of a parallel system architecture for cloud migration based on Nginx image splitting technology is provided for this invention.
[0047] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0049] During the process of migrating and adapting IT systems to domestic standards in enterprises, a large number of outdated systems with unclear requirements and scattered documentation pose a major challenge to the migration work. The currently prevalent industry approach of full regression testing + one-time migration has the following problems:
[0050] First, manually constructed test data cannot accurately reflect the actual traffic characteristics of the online production environment in terms of scale, distribution, and complexity, and it is difficult to cover a large number of edge scenarios and complex business combinations. Second, the one-time traffic switching mode instantly redirects all production traffic to the new system. Once a functional abnormality or performance bottleneck occurs, business interruption is inevitable, and rollback cannot be completed in time due to the delay in DNS cache propagation. Third, the test environment is completely isolated from the production environment, and verification and production operation cannot be carried out in parallel. The new system cannot be tested by real production traffic before the traffic switching. Fourth, regression testing requires a lot of manpower to construct test data and write test cases, which takes several months and seriously slows down the migration progress.
[0051] Please see Figure 1 To address the aforementioned issues, this embodiment provides a parallel cloud migration method based on Nginx image splitting technology, including:
[0052] Receive business requests sent by clients at the Nginx reverse proxy;
[0053] The Nginx reverse proxy forwards the business request to the backend production service for processing, records the call chain identifier of the business request, and returns the production response returned by the backend production service as the final response to the client.
[0054] Within the same call cycle when the business request is forwarded to the backend production service, the business request is copied asynchronously and non-blockingly through the ngx_http_mirror_module (mirror distribution module) built into the Nginx reverse proxy to generate a mirror request, and the mirror request is sent to at least one target system to be migrated in an isolated mirror environment;
[0055] The image response generated by the target system to be migrated after processing the image request is discarded by the Nginx reverse proxy and is not included in the synthesis of the final response.
[0056] It should be noted that this method relies on the ngx_http_mirror_module built into the Nginx reverse proxy layer to establish a parallel traffic channel between the online production environment (the old system that is still running) and the target system to be migrated to the cloud (the new system to be switched). Its core idea is: when any business request initiated by the client reaches the Nginx reverse proxy, the Nginx reverse proxy, within the same call cycle as a normal call to the backend production service, asynchronously and non-blockingly replicates a mirror request that is completely equivalent to the original request in terms of HTTP method, request URI, request header, request body, cookie, and call context, and initiates a call to the target system to be migrated in the isolated mirror environment. The production response returned by the backend production service is returned to the client along the original path, while the mirror response generated by the mirror request is directly discarded by the Nginx reverse proxy and does not participate in the synthesis of the client's final response. This achieves real-time driving and verification of the target system to be migrated, using real online traffic as a verification payload without any intrusion or awareness on the client or the backend production service.
[0057] The steps of this solution will be described in detail below with reference to the embodiments.
[0058] Example 1
[0059] S101, The client requests to enter the Nginx reverse proxy.
[0060] In traditional migration verification models, testing of the new system relies on independent test datasets detached from the production environment, which cannot cover all request types in real business scenarios. This step places the Nginx reverse proxy at the production traffic entry point, enabling every business request from a real client to be captured and utilized, thereby providing a real and comprehensive traffic source for subsequent image verification.
[0061] The client sends a business request to the Nginx reverse proxy, carrying all business information such as business parameters, cookies, headers, and call context in the request message. Upon receiving the request, the Nginx reverse proxy, following the workflow of the loaded ngx_http_mirror_module, first forwards the request to the backend production service (i.e., the legacy system that is still running) via the normal path. Simultaneously, the Nginx reverse proxy records the call chain identifier of the request, which is used for subsequent comparisons of the same request number on the mirror side. By establishing a unique call chain identifier for each request, subsequent mirror-side difference comparisons can accurately associate the mirror response with the production response one-to-one, avoiding comparison misalignments caused by concurrent request interleaving.
[0062] Specifically, the call chain identifier can be a globally unique identifier (such as a UUID or an identifier based on a combination of timestamp and random number) generated for each incoming business request at the Nginx reverse proxy layer, or it can reuse the Trace ID already generated by the upstream system. This call chain identifier is injected into the request header and passed to the backend production service along with the business request, and is also passed through to the image request.
[0063] S102, Nginx reverse proxy asynchronously copies image requests to the target system to be migrated.
[0064] In traditional solutions, due to the lack of asynchronous traffic splitting mechanisms, verification of the new system can only be conducted in an independent offline environment, completely separating test traffic from production traffic. This step leverages the asynchronous non-blocking characteristics of the ngx_http_mirror_module to complete mirror replication and transmission in parallel within the same call cycle of production request processing, achieving the effect of driving two systems simultaneously with a single production access. The asynchronous non-blocking design is crucial to ensuring that the production path remains unaffected: mirror replication and transmission operations do not block the forwarding and response of the main request, and even if the target system to be migrated is slow or unreachable, the client's normal business response will not be delayed in any way.
[0065] While forwarding the business request to the backend production service, the Nginx reverse proxy, based on the mirror target address list pre-declared during the configuration phase using the mirror directive, copies a mirror request that is completely identical to the business request in terms of HTTP method, request URI, request header, request body, cookies, and call context. This mirror request is then sent concurrently to the mirror target address—the target system to be migrated—in an isolated mirror environment, in an asynchronous, non-blocking manner. This mirror call does not participate in the waiting sequence for the final client response; the response processing flow of the business request continues to execute, and the mirror call and the original request's response processing do not block each other in terms of timing.
[0066] In this embodiment, the copying and sending of the mirror request is completed within the internal event loop of the Nginx reverse proxy: the Nginx reverse proxy copies the complete message data of the business request (including the request line, request header, and request body) to a separate memory buffer, and then sends the session data to the mirror target address through a new non-blocking connection. Due to the use of a non-blocking I / O model, this sending operation does not block the forwarding and response processing flow of the business request.
[0067] S103, The production response is returned to the client, and the mirror response is discarded.
[0068] The mirroring mechanism adopted in this embodiment, which only allows viewing and not responding, differs from traditional canary releases and traffic replication schemes, reflecting the core design principle of non-intrusive production in this invention. In traditional one-time traffic switching schemes, the new system directly replaces the old system to carry production traffic, and the switching risk cannot be released in advance. However, this embodiment directly discards the mirrored response at the Nginx reverse proxy level, ensuring that regardless of whether the processing result of the target system to be migrated is correct or not, the response speed is slow, or even if it crashes, the client's business result is always solely determined by the backend production service, thereby completing the verification of the new system under zero production risk.
[0069] The backend production service processes the business request according to the normal process and returns the processing result (i.e., the production response) to the Nginx reverse proxy. The Nginx reverse proxy then returns this production response as the final response to the business request to the client. Meanwhile, the image request asynchronously sent to the target system to be migrated is processed independently in the isolated image environment, generating an image response. Since the image call does not affect the response sequence and content of the business request, the Nginx reverse proxy discards the image response upon receipt, without forwarding it to the client or writing it to the production session. The client is completely unaware of the image traffic splitting throughout the entire interaction process.
[0070] It should be noted that the Nginx reverse proxy's discarding of mirror responses here means that the mirror responses do not enter the final response synthesis path of the client, and do not affect the client's business results. The recording of traffic on the mirror environment side is independently completed by the traffic recording and difference comparison module deployed on the gateway or access layer of the mirror environment side (see S106 for details). This module can independently collect data when the mirror request enters the target system to be migrated and when the mirror response is returned, and it is independent of the Nginx reverse proxy's behavior of discarding mirror responses.
[0071] S104, Lossless and consistent mirror request replication.
[0072] The above steps establish a parallel traffic architecture with dual production and mirror channels. However, for the difference comparison results to be valuable, the mirror request and the business request must be completely equivalent in the business dimension. If the mirror request is missing or deformed in any dimension such as Header, Body, or Cookie, the difference between the mirror response and the production response may stem from inconsistencies in the request itself, rather than differences in processing logic between the target system to be migrated and the backend production service, thus distorting the difference comparison results. Therefore, this step specifically addresses the issue of lossless consistency of mirror requests.
[0073] To ensure lossless consistency of the mirror request: that is, each mirror request is completely equivalent to the business request in the business dimension: in this embodiment, the mirror request is completely consistent with the business request in the dimensions of HTTP method, request URI, request header, request body, cookie, and calling context, so that the mirror request constitutes a lossless equivalent copy of the business request.
[0074] To achieve lossless and consistent mirror request replication, this embodiment explicitly enables request body replication during the Nginx configuration phase using the `mirror_request_body on` directive, and transmits key business identifiers such as the original domain name, original request URI, original cookie, token, and call chain identifier to the target system to be migrated via the `proxy_set_header` directive. The original request URI is the original request URI used when the client initiates the business request. The load balancing strategy and domain name resolution strategy on the target system side are isomorphic to those on the backend production service side, enabling mirror requests to enter the target system as equivalent production calls.
[0075] The following is a core configuration example of Nginx reverse proxy in this embodiment:
[0076] http {
[0077] # Backend production services (preserving and running legacy systems)
[0078] upstream prod_legacy {
[0079] server 10.0.0.11:8080 weight=10; # Backend production service master node
[0080] keepalive 64;
[0081] }
[0082] # Mirror target (target system to be migrated in an isolated environment)
[0083] upstream mirror_new_system {
[0084] server 10.2.0.21:8080;
[0085] }
[0086] server {
[0087] listen 80;
[0088] server_name service.example.com;
[0089] location / {
[0090] # Normal production path: Call the backend production service and return a production response
[0091] proxy_pass http: / / prod_legacy;
[0092] proxy_set_header Host $host;
[0093] proxy_set_header X-Real-IP $remote_addr;
[0094] proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
[0095] proxy_set_header X-Original-URI $request_uri;
[0096] proxy_http_version 1.1;
[0097] proxy_set_header Connection "";
[0098] # Asynchronously copy requests to the mirror target using ngx_http_mirror_module
[0099] mirror / mirror_dispatch;
[0100] mirror_request_body on;
[0101] }
[0102] # Mirror distribution internal endpoint
[0103] location = / mirror_dispatch {
[0104] internal;
[0105] access_log off;
[0106] proxy_pass http: / / mirror_new_system;
[0107] proxy_set_header Host $host;
[0108] proxy_set_header X-Original-URI $request_uri;
[0109] proxy_set_header X-Mirror-Source "nginx-mirror";
[0110] proxy_read_timeout 5s;
[0111] proxy_connect_timeout 2s;
[0112] }
[0113] }
[0114] }
[0115] The above configuration follows three principles during implementation to achieve complete isolation and protection of the production environment:
[0116] First, the upstream response corresponding to the backend production service is the only source for the final response synthesis in the client; responses from all image calls do not participate in the synthesis of the final response.
[0117] Second, all mirror calls are forwarded through the internal endpoint / mirror_dispatch declared in internal, and the access log of this internal endpoint is turned off (access_log off) to prevent mirror traffic from polluting the main access log of the Nginx reverse proxy.
[0118] Third, the read timeout (proxy_read_timeout 5s) and connection timeout (proxy_connect_timeout 2s) on the mirror side are strictly less than the corresponding timeouts on the backend production service side. This ensures that any anomalies on the target system to be migrated are detected by the Nginx reverse proxy before affecting the normal return of the production response, and the corresponding mirror response is discarded without affecting the normal return of the production response. Through the above three configuration principles, failures on the mirror side are strictly isolated within the mirror environment. Even if the target system to be migrated experiences a crash, deadlock, or response timeout, the response latency and service level agreement (SLA) of the production environment will not be affected in any way.
[0119] S105, Parallel Mounting of Multiple Image Targets: A single access drives multiple verification environments.
[0120] In migration practice, multiple environments often need to be tested with production traffic. For example, in addition to the target system being migrated to the cloud, there may be multiple variants such as canary release versions (e.g., v1.5) and A / B testing versions that need to be verified in parallel. Building separate traffic replication channels for each environment is not only complex to configure but also introduces additional performance overhead to the Nginx reverse proxy. This step leverages the mirror directive's ability to configure multiple mirror targets in an array format, achieving the effect of multiple verifications in a single access, significantly improving verification efficiency.
[0121] This embodiment further supports scenarios involving parallel verification of multiple versions. Specifically, the `mirror` directive supports configuring multiple mirror targets as an array, allowing at least one of the cloud migration target system, the canary release version system, and the A / B test version system to be mounted concurrently on the same traffic channel. The Nginx reverse proxy sends the mirror requests to all mirror target addresses concurrently in an asynchronous, non-blocking manner within the same request cycle, thereby driving multiple environments to be verified in parallel within a single client access.
[0122] For example, in actual deployment, multiple upstream images can be added (such as mirror_v15 corresponding to the gray release version and mirror_ab_test corresponding to the A / B test version), and the image requests of different business paths can be routed to different image targets through URI matching rules in the internal endpoint of / mirror_dispatch, so as to achieve parallel mounting of the target system for cloud migration, the gray release version system and the A / B test version system.
[0123] S106. Mirror-side traffic recording and difference comparison.
[0124] After the above steps, the target system to be migrated is running under the continuous drive of real production traffic. However, traffic-driven operation alone is insufficient to form a closed-loop verification process: operations and development personnel cannot manually compare massive amounts of mirror responses with production responses one by one. Therefore, an automated difference detection mechanism is needed to systematically compare the results in the mirror environment with those in the production environment, thereby identifying potential functional defects and performance deviations. This step automates the verification process by independently deploying traffic recording and difference comparison modules on the mirror environment side, ensuring that each production request generates a comparison record that can be used to assess the risk of going live.
[0125] To support traffic comparison and difference detection to determine whether the target system to be migrated is ready for deployment, this embodiment deploys a traffic recording and difference comparison module at the gateway or access layer on the mirror environment side. This module uses the call chain identifier as the association key (i.e., mirror requests and business requests associated with the same call chain identifier form a set of comparison samples), records the mirror response status code, mirror response body, and mirror response time generated by each mirror request in the target system to be migrated, and compares these with the production response returned by the backend production service under the same call chain identifier. It then generates a difference report and outputs alarm events.
[0126] Specifically, the difference comparison includes three levels:
[0127] (1) Field-level comparison: Compare the values of the same fields in the mirror response and the production response to see if they are consistent, including HTTP status codes, fields specified in the response header, and leaf node values in the response body such as JSON / XML. Field-level comparison can detect deviations in the values of individual fields in the target system to be migrated, such as incorrect order amount calculations or abnormal user status returns.
[0128] (2) Structure-level comparison: Compare the data structure of the mirror response and the production response to see if they are consistent, including the hierarchical structure of JSON / XML, array length, and the existence of fields. Structure-level comparison can detect missing or redundant information in the response format of the target system to be migrated, such as missing a nested object or inconsistent array element count.
[0129] (3) Semantic-level comparison: For numeric fields, a certain range of deviation is allowed (e.g., a rounding error of ±0.01 yuan is allowed for monetary fields); for text fields, semantic equivalence is judged after removing irrelevant characters such as spaces and newlines. Semantic-level comparison can filter out false differences introduced by non-business factors such as serialization method and floating-point precision, and avoid false alarms.
[0130] The results of the difference comparison are output to operations and development personnel via a bypass message channel (such as message queues Kafka, RabbitMQ, or log collection systems like ELK). These results are not involved in the synthesis of responses returned to the client and do not affect the production paths of backend production services or the target system to be migrated. Because the difference comparison results are output asynchronously via the bypass message channel, even a surge in alarms or congestion in the message channel will not put any reverse pressure on the production environment.
[0131] S107. Controllable switching and rollback based on observation period indicators.
[0132] Through continuous parallel operation and discrepancy comparison, the operations team has accumulated a large amount of data regarding the differences between the target system to be migrated and the backend production services. However, the original massive discrepancy reports do not directly equate to a clear deployment decision: occasional sporadic discrepancies may be due to occasional factors such as network jitter or third-party service timeouts, and do not indicate a systemic problem in the target system to be migrated. Therefore, it is necessary to transform the discrepancy data into a quantifiable and observable indicator system to continuously evaluate the stability of the target system to be migrated over a sufficiently long observation period, thereby avoiding premature or delayed switchover decisions due to occasional discrepancies.
[0133] To ensure the continuity and rollbackability of deployment decisions, this embodiment establishes a quantifiable observation period indicator system based on the difference report. This observation period indicator system includes at least one of the following:
[0134] (1) Difference rate: the ratio of the number of difference requests to the total number of mirror requests. The lower the difference rate, the more consistent the processing results of the production traffic of the target system to be migrated are with the backend production service.
[0135] (2) P99 response delay bias: the difference between the mirror response P99 delay and the production response P99 delay. This indicator reflects whether the target system to be migrated can reach the level of backend production services in terms of processing performance. P99 is chosen instead of the average value as the metric because P99 can better reflect the system's performance under the worst conditions, avoiding the average value from masking long-tail latency issues.
[0136] (3) Consistency of key business fields: This refers to the consistency rate of values of specified business fields in the mirror response and the production response. This metric focuses on the accuracy of core business fields (such as order amount, user status, approval results, etc.) to avoid differences in non-key fields interfering with the go-live decision.
[0137] In actual operation, the operations and maintenance team continuously monitors the above indicators. After parallel verification confirms that continuous operation meets the preset observation period conditions (e.g., the difference rate is lower than the first threshold for N consecutive days, the P99 response latency deviation is lower than the second threshold, and the consistency of key business fields is higher than the third threshold), the resolution weight of the production domain name or the reverse proxy entry is gradually switched from the backend production service to the target system to be migrated according to the predetermined switching strategy, achieving a smooth online launch. The switching strategy can adopt a gradient weight adjustment (e.g., first switch 10% of the traffic and observe for 1 day, then switch 30% and observe for 1 day, and finally switch 100%), or it can adopt a gray-scale switching strategy based on business lines or user groups. Compared with the traditional one-time traffic switching solution, the gradient gradual switching strategy in this embodiment can continuously observe the performance of the new system at each gradient stage. Once a problem is found, the switching can be paused or rolled back, thereby distributing the switching risk over multiple controllable time windows.
[0138] If any observed metric exceeds its limit during the observation period, a rollback strategy is triggered, maintaining the production path for requests handled by the backend production service. The rollback operation can be achieved by restoring the domain name resolution weight or resetting the reverse proxy routing configuration. The entire rollback process is completed within minutes, with zero impact on online business.
[0139] In summary, this embodiment, through S101 to S107, forms a complete cloud migration closed loop driven by real traffic, carried by mirrored traffic distribution, verified by difference comparison, switched by observation period indicators, and triggered rollback by indicators exceeding limits. Compared to the traditional migration model of full regression testing + one-time traffic switching, this embodiment has the following advantages: First, comprehensive test coverage: By replicating real production traffic, it avoids verification blind spots caused by differences between test data and the production environment, covering edge scenarios and complex business combinations that are difficult to reach by manual testing; Second, risk control: The mirrored traffic is isolated from the production environment, so even if the target system to be migrated experiences anomalies, it will not affect the normal use of online users, providing a safe and reliable verification solution for system migration; Third, increased confidence in going live: Based on the continuous verification results of real traffic, the team can execute the go-live decision with more confidence, significantly reducing the risk of going live; Fourth, improved resources and efficiency: There is no need to construct test data or build independent test scripts. A single production traffic can drive the entire link verification, saving manpower, machine, and time costs; Fifth, smooth switching and rollback: The gradient switching and over-limit rollback mechanism based on observation period indicators avoids the high-risk mode of one-time traffic switching, ensuring that the go-live process has zero impact on online business.
[0140] Example 2
[0141] This embodiment provides a parallel cloud migration system based on Nginx image splitting technology. This system is based on the same inventive concept as the method described in Embodiment 1 and is used to execute the method described in Embodiment 1. This embodiment provides a system architecture that can be directly deployed in engineering.
[0142] Please see Figure 2 The system provided in this embodiment includes the following three core modules:
[0143] The Nginx reverse proxy module, which includes the built-in `ngx_http_mirror_module`, receives business requests from clients, forwards them to backend production services for processing, records the call chain identifier of the business requests, and returns the production response from the backend production service as the final response to the client. Within the same call cycle, this module also uses `ngx_http_mirror_module` to asynchronously and non-blockingly replicate the business requests to generate mirror requests, and sends these mirror requests to at least one target system to be migrated, located in an isolated mirror environment. The mirror responses generated by the target system after processing the mirror requests are discarded by the Nginx reverse proxy module and do not participate in the final response synthesis. The specific configuration and operation of the Nginx reverse proxy module have been described in detail in S101 to S104 of Example 1, and will not be repeated here.
[0144] The traffic recording and difference comparison module receives the runtime data generated in the target system by the mirror request output by the Nginx reverse proxy module, and undertakes the core function of S106 in Example 1. This module is deployed on the gateway or access layer of the mirror environment side. It records the mirror response status code, mirror response body, and mirror response time generated in the target system by the mirror request, using the call chain identifier as the association key. It then compares these data with the production response returned by the backend production service under the same call chain identifier, generates a difference report, and outputs alarm events.
[0145] In practical implementation, the traffic recording and difference comparison module can be deployed in any of the following ways: First, as an independent bypass service, it obtains mirror response data by listening to the traffic mirror port of the gateway on the mirror environment side; second, it is integrated into the API gateway on the mirror environment side as a plugin; third, by embedding an AOP (Aspect-Oriented Programming) interceptor in the application layer of the target system to be migrated, the response data is asynchronously sent to the difference comparison engine after request processing is completed. The difference comparison engine supports configurable comparison rules, including a list of ignored fields, numerical tolerance ranges, and semantic equivalence patterns. The difference comparison results are output as a difference report in JSON format and pushed asynchronously through the bypass message channel.
[0146] The switchback control module, taking the difference report output by the traffic recording and difference comparison module as input, undertakes the core function of S107 in Embodiment 1 and serves as the decision-making hub for the system's transition from the verification phase to the deployment phase. This module is used to set a quantifiable observation period indicator system based on the difference report. After the system has been running continuously and meets the preset observation period conditions, it gradually switches the resolution weight of the production domain name or the reverse proxy entry point from the backend production service to the target system to be migrated according to a predetermined switchover strategy, achieving a smooth deployment. It also triggers a rollback strategy when any observation indicator exceeds its limit, maintaining the production path for requests processed by the backend production service unchanged.
[0147] In its implementation, the switchover and rollback control module can include a metric calculation engine and a switchover executor. The metric calculation engine periodically retrieves difference reports from the traffic recording and difference comparison module, calculates the current values of each metric based on a preset observation period metric system (difference rate, P99 response latency deviation, consistency of key business fields), and compares them with thresholds. The switchover executor, based on the metric comparison results and the preset switchover / rollback strategy, performs traffic weight adjustment operations by calling the Domain Name System (DNS) API or reverse proxy configuration management interface. The three modules form a data flow link through call chain identifiers and difference reports: the Nginx reverse proxy module generates call chain identifiers and injects image requests; the traffic recording and difference comparison module generates difference reports using the call chain identifiers as the association key; and the switchover and rollback control module drives deployment decisions based on the difference reports. These three modules work together to form a complete cloud migration closed loop from traffic diversion to verification decisions.
[0148] The above are only some embodiments of this application and do not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A parallel cloud migration method based on Nginx image splitting technology, characterized in that, Includes the following steps: Receive business requests sent by clients at the Nginx reverse proxy; The Nginx reverse proxy forwards the business request to the backend production service for processing, records the call chain identifier of the business request, and returns the production response returned by the backend production service as the final response to the client. Within the same call cycle when the business request is forwarded to the backend production service, the business request is copied asynchronously and non-blockingly using the ngx_http_mirror_module built into the Nginx reverse proxy to generate a mirror request, and the mirror request is sent to at least one target system to be migrated in an isolated mirror environment. The image response generated by the target system to be migrated after processing the image request is discarded by the Nginx reverse proxy and does not participate in the synthesis of the final response.
2. The parallel cloud migration method based on Nginx image splitting technology according to claim 1, characterized in that, The mirror request is completely identical to the business request in terms of HTTP method, request URI, request header, request body, cookie, and calling context, so that the mirror request constitutes a lossless equivalent copy of the business request.
3. The parallel cloud migration method based on Nginx image splitting technology according to claim 1, characterized in that, During the Nginx configuration phase, request body replication is explicitly enabled using the mirror_request_body on directive, and the original domain name, original request URI, original cookie, token, and the call chain identifier are passed through to the target system to be migrated using the proxy_set_header directive. Wherein, the original request URI is the original request URI when the client initiates the business request; the load balancing strategy and domain name resolution strategy of the target system to be migrated are isomorphic to the backend production service side, so that the mirror request enters the target system to be migrated as an equivalent production call.
4. The parallel cloud migration method based on Nginx image splitting technology according to claim 1, characterized in that, The target systems to be migrated are multiple, including cloud migration target systems, as well as at least one of the gray release version system and the A / B experimental version system; By configuring multiple mirror target addresses in array form using the mirror directive, the Nginx reverse proxy can send mirror requests to all mirror target addresses concurrently in an asynchronous and non-blocking manner within the same request cycle, enabling a single client access to drive multiple sets of environments to be verified in parallel.
5. The parallel cloud migration method based on Nginx image splitting technology according to claim 1, characterized in that, The mirroring request is forwarded through an internal endpoint declared as internal in the Nginx configuration, and the access logs for the internal endpoint are turned off. The read timeout and connection timeout for the mirror request are both configured to be less than the corresponding timeout for forwarding the business request to the backend production service. This ensures that any anomalies on the target system side to be migrated are detected by the Nginx reverse proxy before they affect the normal return of the production response, and the corresponding mirror response is discarded without affecting the normal return of the production response.
6. The parallel cloud migration method based on Nginx image splitting technology according to claim 1, characterized in that, Also includes: Deploy a traffic recording and difference comparison module at the gateway or access layer on the mirror environment side. The traffic recording and difference comparison module uses the call chain identifier as the association key to record the mirror response status code, mirror response body and mirror response time generated by the mirror request in the target system to be migrated, and compares the difference with the production response returned by the backend production service under the same call chain identifier, generates a difference report and outputs alarm events.
7. The parallel cloud migration method based on Nginx image splitting technology according to claim 6, characterized in that, The difference comparison includes field-level comparison, structure-level comparison, and semantic-level comparison; the difference report and the alarm event are output to the operation and maintenance and R&D personnel through a bypass message channel, and do not participate in the synthesis of the response returned to the client, nor do they affect the production paths of the backend production service and the target system to be migrated.
8. A parallel cloud migration method based on Nginx image splitting technology according to claim 6, characterized in that, Also includes: Based on the difference report, a quantifiable observation period indicator system is set. After parallel verification and continuous operation meet the preset observation period conditions, the resolution weight or reverse proxy entry of the production domain name is gradually switched from the backend production service to the target system to be migrated according to the predetermined switching strategy to achieve smooth online. If any observation indicator exceeds the limit, a rollback strategy is triggered to keep the production path of the request processed by the backend production service unchanged.
9. A parallel cloud migration method based on Nginx image splitting technology according to claim 8, characterized in that, The observation period indicator system includes at least one of the following: The difference rate is the ratio of the number of difference requests to the total number of image requests. P99 response delay deviation, which is the difference between the mirror response P99 delay and the production response P99 delay; Business key field consistency refers to the consistency rate of values of specified business fields in the mirror response and the production response.
10. A parallel cloud migration system based on Nginx image splitting technology, used to implement the parallel cloud migration method based on Nginx image splitting technology as described in any one of claims 1 to 9, characterized in that, include: The Nginx reverse proxy module includes a built-in ngx_http_mirror_module, which receives business requests from clients, forwards them to backend production services for processing, records the call chain identifier of the business requests, and returns the production response from the backend production service as the final response to the client. Furthermore, within the same call cycle of forwarding the business request to the backend production service, the ngx_http_mirror_module asynchronously and non-blockingly replicates the business request to generate a mirror request, and sends the mirror request to at least one target system to be migrated in an isolated mirror environment. The mirror response generated by the target system after processing the mirror request is discarded by the Nginx reverse proxy module and does not participate in the synthesis of the final response. The traffic recording and difference comparison module is deployed on the gateway or access layer of the mirror environment side. It is used to record the mirror response status code, mirror response body and mirror response time generated by the mirror request in the target system to be migrated, using the call chain identifier as the association key, and to compare the difference with the production response returned by the backend production service under the same call chain identifier, generate a difference report and output alarm events. The switchback control module is used to set a quantifiable observation period indicator system based on the difference report. After the system has been running continuously and meets the preset observation period conditions, the resolution weight of the production domain name or the reverse proxy entry point is gradually switched from the backend production service to the target system to be migrated according to the predetermined switch strategy to achieve smooth online. In addition, when any observation indicator exceeds the limit, the rollback strategy is triggered to keep the production path of the request processed by the backend production service unchanged.
