A method and device for processing distributed transactions with eventual consistency

By generating delay tasks when order payment is successful, and obtaining order payment results from user equipment and third-party payment platforms, the problems of poor performance and large latency of distributed transaction solutions in the prior art are solved, and the final consistency and low latency of data between third-party payment platforms and user equipment are achieved.

CN114037436BActive Publication Date: 2025-03-18SHANGHAI WANWUXINSHENG ENVIRONMENTAL PROTECTION TECH GRP CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111203927.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-15
Publication Date
2025-03-18
Estimated Expiration
2041-10-15

AI Technical Summary

Technical Problem

In the prior art, strongly consistent distributed transaction solutions have poor performance and the maximum notification solution is delayed too long. The distributed transaction solutions designed by major companies have performance disadvantages, making it difficult to ensure data consistency and low latency between the third-party payment platform and user equipment during the order processing process.

Method used

By generating a delay task about the current order in response to detecting that the order payment is successful, the order payment result and payment service result are obtained from the user equipment and the third-party payment platform respectively based on the task. If the results are inconsistent, the business logic of the user equipment is called to modify the payment operation after the preset retry threshold is reached, and after the third-party payment platform is called to modify the payment operation until the data between the user equipment and the third-party payment platform is consistent.

Benefits of technology

The data consistency compensation method through the third-party payment platform during the order processing process is realized, ensuring the ultimate consistency and low delay between the third-party payment platform and user equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114037436B_ABST
    Figure CN114037436B_ABST
Patent Text Reader

Abstract

The purpose of the present application is to provide an eventual consistency distributed transaction processing method and device. The present application generates a delay task for the current order in response to detecting that the order payment is successful; based on the delay task, obtains the order payment result for the current order from the user device and the payment service result for the current order from the third-party payment platform; if the order payment result is inconsistent with the payment service result, re-calls and modifies the business logic corresponding to the current order in the user device, and after the number of retries reaches a preset retry number threshold, if it is still inconsistent, calls the third-party payment platform to modify the payment operation corresponding to the current order until the data between the user device and the third-party payment platform are consistent, thereby realizing a data consistency compensation method through the third-party payment platform, ensuring the eventual consistency of the data between the third-party payment platform and the user device with low latency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and device for eventually consistent distributed transaction processing. Background Art

[0002] In the complex distributed system, distributed transactions have always been a headache. It is impossible to use local transactions to control data consistency between multiple services. Currently, there are two-phase commit, three-phase commit, local message table, best effort notification and distributed transaction solutions designed by major companies on the market. In the existing technology, the performance of strong consistency distributed transaction solutions is too poor, the maximum notification solution has too long a delay, and the distributed transaction solutions designed by major companies also have more or less performance shortcomings. Summary of the invention

[0003] One purpose of the present application is to provide a method and device for eventually consistent distributed transaction processing, so that during the order processing process, data consistency between the third-party payment platform and the user device is guaranteed with low latency.

[0004] According to one aspect of the present application, a method for processing distributed transactions with eventual consistency is provided, wherein the method comprises:

[0005] In response to detecting that the order payment is successful, generating a delayed task regarding the current order;

[0006] Based on the delayed task, respectively obtaining an order payment result of the current order from the user device and a payment service result of the current order from the third-party payment platform;

[0007] If the order payment result is inconsistent with the payment service result, the business logic corresponding to the current order in the user device is re-called and modified, and after the number of retries reaches a preset retry threshold, if there is still inconsistency, the third-party payment platform is called to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent.

[0008] Furthermore, in the above method, calling the third-party payment platform to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent includes:

[0009] Calling the third-party payment platform to modify the payment operation corresponding to the current order so that the order payment result is consistent with the modified payment service result;

[0010] If the number of changes to the payment operation reaches a preset change threshold and is still inconsistent, the payment service result is rolled back so that the user device adds one or more payment services to the order payment result for the current order.

[0011] Furthermore, in the above method, the payment service result includes at least one payment service and its corresponding healthy server and at least one payment service and its corresponding abnormal server;

[0012] The rolling back of the payment service result so that the user device adds one or more payment services in the order payment result of the current order includes:

[0013] The payment service corresponding to the operation of the health server is rolled back through each health server respectively, so that the user device adds the payment service corresponding to the operation of each health server in the order payment result.

[0014] Furthermore, in the above method, the method further comprises:

[0015] If the order payment result is consistent with the payment service result, a response message is generated to indicate that the current order has been completed.

[0016] According to another aspect of the present application, a non-volatile storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions can be executed by a processor, the processor implements the above-mentioned eventually consistent distributed transaction processing method.

[0017] According to another aspect of the present application, there is also provided an eventual consistency distributed transaction processing device, wherein the device includes:

[0018] one or more processors;

[0019] A computer readable medium for storing one or more computer readable instructions,

[0020] When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the above-mentioned eventually consistent distributed transaction processing method.

[0021] Compared with the prior art, the present application generates a delay task regarding the current order in response to detecting that the order payment is successful; based on the delay task, obtains the order payment result regarding the current order from the user device and the payment service result regarding the current order from the third-party payment platform respectively; if the order payment result is inconsistent with the payment service result, re-calls and modifies the business logic corresponding to the current order in the user device, and after the number of retries reaches a preset retry number threshold, if it is still inconsistent, calls the third-party payment platform to modify the payment operation corresponding to the current order until the data regarding the current order between the user device and the third-party payment platform are consistent, so that in the process of order processing, the data consistency compensation method of the third-party payment platform is used to ensure the final consistency of the data between the third-party payment platform and the user device and low latency. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0023] Figure 1 A schematic diagram showing an actual process flow of an eventual consistency distributed transaction processing method in the prior art;

[0024] Figure 2 A schematic diagram showing the principles of an eventual consistency distributed transaction processing method according to one aspect of the present application is shown.

[0025] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION

[0026] The present application is described in further detail below in conjunction with the accompanying drawings.

[0027] In a typical configuration of the present application, the terminal, the device of the service network and the trusted party all include one or more processors (CPU), input / output interfaces, network interfaces and memories.

[0028] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0029] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory media such as modulated data signals and carrier waves.

[0030] like Figure 1 As shown, one aspect of the present application proposes an interactive flow diagram of an eventual consistency distributed transaction processing method, which is applied to an order processing process, including a user device, a third-party payment platform, and one or more servers under a distributed cluster, wherein the method includes steps S11, S12, S13, S14, S21, S22, S23, and S24, specifically including the following steps:

[0031] Step S11, the server generates a delayed task for the current order in response to detecting that the order payment is successful;

[0032] Step S12, the server obtains the order payment result of the current order from the user device and the payment service result of the current order from the third-party payment platform based on the delayed task;

[0033] Step S13, the server determines whether the order payment result is consistent with the payment service result, if so, executes step S14, if not, executes steps S15 and S16.

[0034] Among them, if the order payment result is consistent with the payment service result, in the step S14, the server generates response information for indicating that the current order has been completed.

[0035] If the order payment result is inconsistent with the payment service result, in step S15, the server re-calls and modifies the business logic corresponding to the current order in the user device, and after the number of retries reaches a preset retry threshold, if it is still inconsistent, continues to execute step S16, and the server calls the third-party payment platform to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent.

[0036] Through the above steps S11 to S16, during the order processing, the data consistency compensation method of the third-party payment platform is used to ensure the final consistency of the data between the third-party payment platform and the user device with low latency.

[0037] In actual application scenarios, such as Figure 2 As shown, during the order processing, when the user device places an order and generates an order, the payment service in the third-party payment platform pays for the current order. If the payment fails, a response message for the payment failure is returned to the user device to end the current order. If the payment is successful, the server responds to detecting that the order payment is successful. For example, when the third-party API is called successfully, a delay task for the current order is generated and sent to the message queue MQ. The delay time of the delay task is equal to the data downgrade limit time for modifying the user device (including but not limited to 2 seconds), and based on the delay task, the order payment result of the current order is obtained from the user device and the payment service result of the current order is called and queried from the third-party payment platform. In order to ensure data consistency between the user device and the third-party payment platform during the order payment processing, the server determines whether the order payment result of the user device is consistent with the payment service result of the third-party payment platform. If the order payment result is consistent with the payment service result, it means that the data is correct and consistent. The server generates response information indicating that the current order has been completed and the payment processing of the current order has been completed. If the order payment result is inconsistent with the payment service result, it means that the data about the current order between the user device and the third-party payment platform is inconsistent. The server re-calls and modifies the business logic in the user device corresponding to the current order, wherein the business logic processing is as follows: Figure 2 As shown in , and after the number of retries reaches a preset retry number threshold, if the data between the user device and the third-party payment platform is still inconsistent, the server calls the third-party payment platform to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent, thereby ensuring the ultimate consistency of data between the third-party payment platform and the user device and low latency.

[0038] Following the above embodiment of the present application, the step S16 calls the third-party payment platform to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent, specifically including:

[0039] Calling the third-party payment platform to modify the payment operation corresponding to the current order so that the order payment result is consistent with the modified payment service result;

[0040] If the number of changes to the payment operation reaches a preset change threshold and is still inconsistent, the payment service result is rolled back so that the user device adds one or more payment services to the order payment result for the current order.

[0041] For example, after re-calling and modifying the payment service of the user device, if the order payment result is still inconsistent with the modified payment service result, the third-party payment platform is called to modify the payment operation corresponding to the current order to make the order payment result consistent with the modified payment service result; if the number of changes made to the payment operation corresponding to the current order through the third-party payment platform reaches a preset change number threshold and is still inconsistent, the payment service result needs to be rolled back so that the user device can correspond to one or more payment services newly added in the order payment result of the current order, thereby ensuring the consistency of data related to the current order between the user device and the server.

[0042] Following the above embodiment of the present application, the payment service result includes at least one payment service and its corresponding healthy server and at least one payment service and its corresponding abnormal server;

[0043] The rolling back of the payment service result so that the user device adds one or more payment services in the order payment result of the current order includes:

[0044] The payment service corresponding to the operation of the health server is rolled back through each health server respectively, so that the user device adds the payment service corresponding to the operation of each health server in the order payment result.

[0045] For example, in a distributed system, the payment function for an order may need to call multiple services to modify data. For example, in the process of calling these services, a service in the middle may crash, causing the entire order payment process to fail, and the operation of the previous service will not be rolled back. In the present application, when an exception occurs in the payment service process of an order, the payment service result may include services that have successfully paid or services that have failed to pay. Payment services may include but are not limited to red envelope services, coupon services, coin services, cash services, and services to find someone to pay on your behalf. When payment fails, each health server can be used to roll back the payment service corresponding to the operation of the health server, so that the user device can add the payment service corresponding to the operation of each health server in the order payment result. Figure 2 As shown, the payment services involved in the current order include red envelope service, coupon service and cash service. When the coupon service and cash service payment fail and the red envelope service payment is successful, the health server corresponding to the red envelope service that has paid successfully will roll back the corresponding paid red envelope. For example, in a preferred embodiment of the present application, if the red envelope payment is a 5 yuan red envelope, the 5 yuan red envelope will be rolled back by the health server corresponding to the red envelope service. In the actual operation process, the interface of the operation data can be added, and the reverse (rollback) operation function can be realized by passing in the same operation data parameters and different operation category parameters. For example, the function of deducting the user's red envelope, the forward operation data parameter is to pass a 5 yuan red envelope, and the operation category parameter is passed 1 to realize the deduction of the 5 yuan red envelope book operation, and the reverse operation data parameter is to pass a 5 yuan red envelope, and the operation category parameter is passed 2 to realize the addition of a 5 yuan red envelope data operation, so as to realize the service rollback operation in the payment process when the entire payment process fails but there is still a successful payment, so as to ensure the consistency of the data related to the current order between the user device and the server.

[0046] According to another aspect of the present application, a non-volatile storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions can be executed by a processor, the processor implements the above-mentioned eventually consistent distributed transaction processing method.

[0047] According to another aspect of the present application, there is also provided an eventual consistency distributed transaction processing device, wherein the device includes:

[0048] one or more processors;

[0049] A computer readable medium for storing one or more computer readable instructions,

[0050] When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the above-mentioned eventually consistent distributed transaction processing method.

[0051] Here, for the detailed contents of each embodiment of the eventually consistent distributed transaction processing device, please refer to the corresponding part of the embodiment of the eventually consistent distributed transaction processing method mentioned above, which will not be described in detail here.

[0052] In summary, in the traditional distributed transaction processing method, service calls often directly use message queues, and will retry if failed. Even if they can be retried, the retry operation will continue to fail and retry in the service cluster that has already had problems, and it requires manual processing and delay for a long time, which is not only inefficient but also has a long delay time. In order to solve the problems in the prior art, the present application generates a delay task about the current order in response to detecting that the order payment is successful; based on the delay task, the order payment result about the current order is obtained from the user device and the payment service result about the current order is obtained from the third-party payment platform; if the order payment result is inconsistent with the payment service result, the business logic corresponding to the current order in the user device is re-called and modified, and after the number of retries reaches the preset retry number threshold, if it is still inconsistent, the third-party payment platform is called to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform is consistent, so that in the process of order processing, the data consistency compensation method of the third-party payment platform is used to ensure the final consistency of the data between the third-party payment platform and the user device and the delay is low.

[0053] It should be noted that the present application can be implemented in software and / or a combination of software and hardware, for example, can be implemented using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including relevant data structures) can be stored in a computer-readable recording medium, for example, a RAM memory, a magnetic or optical drive or a floppy disk and similar devices. In addition, some steps or functions of the present application can be implemented using hardware, for example, as a circuit that cooperates with a processor to perform each step or function.

[0054] In addition, a part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present application through the operation of the computer. The program instruction for calling the method of the present application may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in a working memory of a computer device that runs according to the program instruction. Here, according to an embodiment of the present application, a device is included, the device including a memory for storing computer program instructions and a processor for executing program instructions, wherein, when the computer program instruction is executed by the processor, the device is triggered to run the method and / or technical solution based on the aforementioned multiple embodiments according to the present application.

[0055] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present application is limited by the attached claims rather than the above description, so it is intended to include all changes that fall within the meaning and scope of the equivalent elements of the claims in the present application. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.

Claims

1. An eventual consistency distributed transaction processing method, applied to a server, wherein: The method comprises: In response to detecting that the order payment is successful, generating a delayed task regarding the current order; Based on the delayed task, the order payment result of the current order is obtained from the user device and the payment service result of the current order is obtained from the third-party payment platform; wherein, in the order processing process, after the user device places an order and generates an order, the payment service in the third-party payment platform pays for the current order; If the order payment result is inconsistent with the payment service result, the business logic corresponding to the current order in the user device is re-called and modified, and after the number of retries reaches a preset retry threshold, if there is still inconsistency, the third-party payment platform is called to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent.

2. The method according to claim 1, wherein: Calling the third-party payment platform to modify the payment operation corresponding to the current order until the data about the current order between the user device and the third-party payment platform are consistent, including: Calling the third-party payment platform to modify the payment operation corresponding to the current order so that the order payment result is consistent with the modified payment service result; If the number of changes to the payment operation reaches a preset change threshold and is still inconsistent, the payment service result is rolled back so that the user device adds one or more payment services to the order payment result for the current order.

3. The method according to claim 2, wherein: The payment service result includes at least one payment service and its corresponding healthy server and at least one payment service and its corresponding abnormal server; The rolling back of the payment service result so that the user device adds one or more payment services in the order payment result of the current order includes: The payment service corresponding to the operation of the health server is rolled back through each health server respectively, so that the user device adds the payment service corresponding to the operation of each health server in the order payment result.

4. The method according to claim 1, wherein: The method further comprises: If the order payment result is consistent with the payment service result, a response message is generated to indicate that the current order has been completed.

5. A non-volatile storage medium having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executable by a processor, the processor is enabled to implement the method according to any one of claims 1 to 4.

6. An eventual consistency distributed transaction processing device, wherein: The equipment includes: one or more processors; A computer readable medium for storing one or more computer readable instructions, When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Payment state maintenance method and system based on order callback

    CN113256276A