High-concurrency payment order duplicate prevention method, device, system, equipment, medium and program product
Patent Information
- Application Number
- CN202211029146.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-25
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2042-08-25
AI Technical Summary
[0005]但现有技术中,订单支付请求的方法识别效率偏低,难以应对高并发和/或恶意重复订单的情况
Smart Images

Figure CN115374098B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of network technology, and more specifically to a method, apparatus, system, device, medium, and program product for preventing duplicate payment orders during high concurrency. Background Technology
[0002] With the rapid development of internet technology, more and more companies are building their own e-commerce platforms and connecting to payment services provided by bank open platform systems (including general payment, aggregated payment, SDK payment, etc.). This requires generating payment orders before actual payment is made. During major promotional events like Singles' Day and 618, e-commerce platforms are running large-scale promotions, and a large number of orders are generated through these open platform payment orders, posing a significant challenge to the open platforms' high-concurrency order processing capabilities.
[0003] When a customer places an order and makes a payment, it must be ensured that only one payment order can be created for each order on the bank's open platform. At the same time, it is also necessary to avoid duplicate payments that may result from concurrent order payment requests from customers.
[0004] In existing technologies, when dealing with high concurrency and / or malicious duplicate orders, a unified cache queue is typically used before an order is placed to identify order payment requests based on user information, product information, client IP, and other information, thereby filtering the order payment requests and preventing the same order payment requests from being submitted repeatedly.
[0005] However, in existing technologies, the method of identifying order payment requests is inefficient and difficult to handle situations involving high concurrency and / or malicious duplicate orders. Summary of the Invention
[0006] In view of the above problems, this disclosure provides methods, apparatus, systems, devices, media, and program products for preventing duplicate payment orders in high-concurrency transactions to improve identification efficiency.
[0007] According to a first aspect of this disclosure, a method for preventing duplicate payments in high-concurrency transactions is provided, comprising: sequentially performing a first anti-duplicate verification operation and a cache anti-concurrency verification operation on a received first order payment request to ensure that a preset distributed cache database can only write a preset number of the first order payment requests; performing a second anti-duplicate verification operation on the first order payment request from the distributed cache database to determine whether the first order payment request exists in the order database; and writing the first order payment request into the order database when the first order payment request does not exist in the order database.
[0008] According to an embodiment of this disclosure, the first order payment request is sent to the application server cluster by a reverse proxy server in a polling manner.
[0009] According to an embodiment of this disclosure, the preset distributed cache database stores data in key-value pairs. The step of sequentially performing a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request includes: generating a unique key-value pair based on the merchant information and order number in the first order payment request; determining whether the unique key-value pair exists in the distributed cache database; when the unique key-value pair does not exist in the distributed cache database, determining whether the data value corresponding to the unique key-value pair can be created based on a distributed lock; and when the data value corresponding to the unique key-value pair can be created, writing the first order payment request into the distributed cache database based on the key-value pair format.
[0010] According to an embodiment of this disclosure, the step of creating the data value corresponding to the unique key value based on the distributed lock includes: obtaining the data value corresponding to the unique key value through a single thread based on the unique key value; and creating the data value if obtaining the data value corresponding to the unique key value fails.
[0011] According to an embodiment of this disclosure, the step of performing a second anti-duplicate verification operation on the first order payment request from the distributed cache database includes: querying whether a corresponding order payment request exists in the order database based on the merchant information and the order number as a query index.
[0012] According to an embodiment of this disclosure, after writing the first order payment request into the distributed cache database, the method further includes: setting an expiration time for the first order payment request in the distributed cache database.
[0013] According to a second aspect of this disclosure, a high-concurrency payment order anti-duplicate device is provided. The device is applied to an application server cluster and includes: a distributed cache database verification module, configured to sequentially perform a first anti-duplicate verification operation and a cache anti-concurrency verification operation on a received first order payment request, to ensure that a preset distributed cache database can only write a preset number of the first order payment requests; an order database verification module, configured to perform a second anti-duplicate verification operation on the first order payment request from the distributed cache database, to determine whether the first order payment request exists in the order database; and a payment processing module, configured to write the first order payment request into the order database when the first order payment request does not exist in the order database.
[0014] According to an embodiment of this disclosure, the first order payment request is sent to the application server cluster by a reverse proxy server in a polling manner.
[0015] According to an embodiment of this disclosure, the preset distributed cache database stores data in key-value pairs. The distributed cache database verification module is further configured to: generate a unique key-value pair based on the merchant information and order number in the first order payment request; determine whether the unique key-value pair exists in the distributed cache database; when the unique key-value pair does not exist in the distributed cache database, determine whether the data value corresponding to the unique key-value pair can be created based on a distributed lock; and when the data value corresponding to the unique key-value pair can be created, write the first order payment request into the distributed cache database based on the key-value pair format.
[0016] According to an embodiment of this disclosure, the distributed cache database verification module is further configured to obtain the data value corresponding to the unique key value through a single thread based on the unique key value; and to create the data value if obtaining the data value corresponding to the unique key value fails.
[0017] According to an embodiment of this disclosure, the order database verification module is further configured to query whether a corresponding order payment request exists in the order database based on the merchant information and the order number as a query index.
[0018] According to an embodiment of this disclosure, the apparatus further includes an expiration time setting module, which is further configured to set the expiration time of the first order payment request in the distributed cache database.
[0019] According to a third aspect of this disclosure, a high-concurrency payment order anti-duplicate system is provided. The system includes a reverse proxy server, an application server cluster, a distributed cache cluster, and a database server cluster. The reverse proxy server is configured to perform load balancing on first order payment requests, distributing them to the application server cluster. The application server cluster is configured to sequentially perform a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment requests, ensuring that a preset distributed cache database can only write a preset number of first order payment requests. A second anti-duplicate verification operation is performed on the first order payment requests from the distributed cache database to determine whether the first order payment request exists in the order database. If the first order payment request does not exist in the order database, the first order payment request is written into the order database. The distributed cache cluster is configured to cache the first order payment requests. The database server cluster is configured to store the first order payment requests.
[0020] According to embodiments of this disclosure, the reverse proxy server is further configured to perform load balancing via round-robin.
[0021] According to embodiments of this disclosure, the distributed cache cluster includes multiple distributed storage shards, each of which includes a master distributed storage shard and a slave distributed storage shard; and the database server cluster includes multiple database servers, each of which includes a master database server and a slave database server.
[0022] According to a fourth aspect of this disclosure, an electronic device is provided, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the above-described high-concurrency payment order anti-duplicate method.
[0023] According to a fifth aspect of this disclosure, a computer-readable storage medium is also provided, having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the aforementioned method for preventing duplicate high-concurrency payment orders.
[0024] According to a sixth aspect of this disclosure, a computer program product is also provided, including a computer program that, when executed by a processor, implements the above-described method for preventing duplicate high-concurrency payment orders. Attached Figure Description
[0025] The foregoing contents, as well as other objects, features, and advantages of this disclosure, will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0026] Figure 1A The illustration depicts an application scenario for preventing duplicate payment orders during high concurrency according to an embodiment of this disclosure.
[0027] Figure 1B A schematic diagram of a high-concurrency payment order anti-duplicate system architecture according to an embodiment of the present disclosure is shown.
[0028] Figure 2 A flowchart illustrating a high-concurrency payment order anti-duplicate method according to an embodiment of the present disclosure is shown.
[0029] Figure 3 A flowchart illustrating a distributed cache according to an embodiment of the present disclosure is shown schematically.
[0030] Figure 4 The diagram illustrates the entire process of a high-concurrency payment order anti-duplicate method according to an embodiment of the present disclosure.
[0031] Figure 5A schematic block diagram of a high-concurrency payment order anti-duplicate device according to an embodiment of the present disclosure is shown.
[0032] Figure 6 A block diagram schematically illustrates an electronic device suitable for implementing a high-concurrency payment order anti-duplicate method according to an embodiment of the present disclosure. Detailed Implementation
[0033] The embodiments of the present disclosure will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the disclosure. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of the present disclosure for ease of explanation. However, it will be apparent that one or more embodiments may be practiced without these specific details. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concepts of the present disclosure.
[0034] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this disclosure. The terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0035] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0036] When using expressions such as "at least one of A, B, and C", they should generally be interpreted in accordance with the meaning that is commonly understood by a person skilled in the art (e.g., "a system having at least one of A, B, and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B, and C, etc.).
[0037] Before providing a detailed description of the embodiments of this disclosure, the key technical terms used in the embodiments of this disclosure will be explained one by one:
[0038] Nginx: A high-performance HTTP and reverse proxy server used in this disclosure for load balancing.
[0039] Redis: A high-performance key-value distributed caching database, which is used in this disclosure for preventing duplicate requests and concurrency issues.
[0040] Rdb: A persistence mechanism supported by Redis, which generates a snapshot of the current data and saves it to disk.
[0041] Zookeeper Cluster: An open-source, distributed Apache project that provides coordination services for distributed frameworks.
[0042] The SetNx method is a write method in Redis. It takes a key and a value as input parameters. The setNx method sets the value of the key to the value and returns 1 if and only if the key does not exist. If the given key already exists, setNx does nothing and returns 0.
[0043] Round-robin: A load balancing method to solve the problem of excessive server pressure.
[0044] In existing technologies, when dealing with high concurrency and / or malicious duplicate orders, a unified cache queue is typically used before an order is placed to identify order payment requests based on user information, product information, client IP, and other information, thereby filtering the order payment requests and preventing the same order payment requests from being submitted repeatedly.
[0045] However, in existing technologies, the method of identifying order payment requests is inefficient and difficult to handle situations involving high concurrency and / or malicious duplicate orders.
[0046] The embodiments of this disclosure provide a method for preventing duplicate payments in high-concurrency transactions. The method is applied to an application server cluster and includes: sequentially performing a first anti-duplicate verification operation and a cache anti-concurrency verification operation on a received first order payment request to ensure that a preset distributed cache database can only write a preset number of the first order payment requests; performing a second anti-duplicate verification operation on the first order payment requests from the distributed cache database to determine whether the first order payment request exists in the order database; and writing the first order payment request into the order database when the first order payment request does not exist in the order database.
[0047] In the embodiments of this disclosure, by combining the first anti-duplicate verification operation and the cache anti-concurrency verification operation, the distributed cache database can achieve the effects of order deduplication and order concurrency prevention. Furthermore, by performing a second anti-duplicate verification operation in the order database, redundant requests in the order database can be filtered out when the first anti-duplicate verification operation and the cache anti-concurrency verification operation partially fail. This improves fault tolerance in detecting duplicate orders, avoids data performance degradation, and prevents the risk of related servers crashing when concurrency reaches a certain level.
[0048] Figure 1AThe illustration depicts an application scenario for preventing duplicate payment orders during high concurrency according to an embodiment of this disclosure.
[0049] like Figure 1A As shown, application scenario 100 according to this embodiment may include terminal devices 101, 102, and 103, network 104, and server 105. Network 104 is used as a medium to provide a communication link between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.
[0050] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0051] Terminal devices 101, 102, and 103 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0052] Server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using terminal devices 101, 102, and 103 (for example only). The backend management server can analyze and process data such as received user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal devices.
[0053] It should be noted that the high-concurrency payment order anti-duplicate method provided in this embodiment can generally be executed by server 105. Correspondingly, the high-concurrency payment order anti-duplicate device provided in this embodiment can generally be installed in server 105. The high-concurrency payment order anti-duplicate method provided in this embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with terminal devices 101, 102, 103 and / or server 105. Correspondingly, the high-concurrency payment order anti-duplicate device provided in this embodiment can also be installed in a server or server cluster that is different from server 105 and capable of communicating with terminal devices 101, 102, 103 and / or server 105.
[0054] It should be understood that Figure 1A The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0055] The following will be based on Figure 1A The described scene, through Figures 1B to 4 The high-concurrency payment order anti-duplicate method of the disclosed embodiments is described in detail.
[0056] Figure 1B A schematic diagram of a high-concurrency payment order anti-duplicate system architecture according to an embodiment of the present disclosure is shown.
[0057] like Figure 1B As shown, the high-concurrency payment order anti-duplicate system includes a reverse proxy server 110, an application server cluster 120, a distributed cache cluster 130, and a database server cluster 140, wherein...
[0058] The reverse proxy server 110 is configured to perform load balancing on the first order payment request to distribute it to the application server cluster.
[0059] For example, within a certain period of time, a large number of order payment requests are received from different clients. These order payment requests are handled by the reverse proxy server 110 and evenly distributed to the various application servers in the application server cluster 120 for processing, so as to avoid excessive pressure on a single point.
[0060] According to embodiments of this disclosure, the reverse proxy server 110 is further configured to perform load balancing via round-robin.
[0061] The application server cluster 120 is configured to sequentially perform a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request, so as to ensure that the preset distributed cache database can only write a preset number of the first order payment requests; perform a second anti-duplicate verification operation on the first order payment request from the distributed cache database to determine whether the first order payment request exists in the order database; and write the first order payment request into the order database when the first order payment request does not exist in the order database.
[0062] The application server cluster 120 includes multiple application servers, and each application server contains multiple application instances.
[0063] The distributed cache cluster 130 is configured to cache the first order payment request.
[0064] The database server cluster 140 is configured to store the first order payment request.
[0065] According to embodiments of this disclosure, the distributed cache cluster 130 includes multiple distributed storage shards, the distributed storage shards including master distributed storage shards and slave distributed storage shards; and the database server cluster 140 includes multiple database servers, the database servers including master database servers and slave database servers.
[0066] like Figure 1B As shown, the distributed cache cluster 140 can use a highly available distributed Redis cluster, leveraging Redis's persistence mechanism and master-slave replication mechanism to ensure data reliability. Redis is a persistent in-memory database, requiring data in memory to be synchronized to disk for persistence. This can be achieved through snapshotting. This method writes the data in memory to a binary file as a snapshot, with the default filename being dump.rdb. Redis can be configured to automatically persist data if more than m keys are modified within n seconds. These m keys include not only the keys used for anti-duplicate purposes but also keys storing other information in Redis. Redis's master-slave replication strategy is implemented through its persistent RDB file. The process involves first dumping (exporting) the RDB file, transferring the entire RDB file to the slave, and then synchronizing the dumped (exported) operations to the slave in real time. To use the master-slave functionality, simple configuration is required on the slave side: configuring it as a slave to the master database and ensuring it is not readable.
[0067] Meanwhile, Redis can use a ZooKeeper cluster to coordinate failover, automatically switching between master and slave nodes to ensure high availability. ZooKeeper records the status of each node, and when ZooKeeper detects a master node failure, it automatically sets a slave node as the new master.
[0068] like Figure 1B As shown, the data servers in the database server cluster 140 also have a master-slave structure to ensure high availability.
[0069] Figure 2 A flowchart illustrating a high-concurrency payment order anti-duplicate method according to an embodiment of the present disclosure is shown.
[0070] like Figure 2 As shown, the high-concurrency payment order anti-duplicate method of this embodiment includes operations S210 to S230, which can be executed by server 105 and / or application server cluster 120.
[0071] According to an embodiment of this disclosure, the first order payment request is sent to the application server cluster by a reverse proxy server in a polling manner.
[0072] For example, the aforementioned reverse proxy server can use Nginx. By configuring the access weights of application instances on each application server in a balanced manner, order payment requests can be evenly distributed across the application instances on each application server, effectively preventing efficiency and performance issues caused by uneven task processing across nodes in the application server cluster. Nginx's load balancing is implemented through round-robin, which is used to address the problem of excessive server pressure. User access requests are distributed to web service nodes in a cyclical order, starting from the first server node and ending at the last, before starting a new round of looping. Order payment requests can be distributed to different backend application servers one by one in chronological order.
[0073] It should be noted that the term "first" in the above-mentioned first order payment request is used to distinguish it from other similar order payment requests. For example, different order payment requests can be referred to as the first order payment request, the second order payment request, and the third order payment request, etc. Further details will not be elaborated upon here.
[0074] In operation S210, the first anti-duplicate verification operation and the cache anti-concurrency verification operation are executed sequentially on the received first order payment request to ensure that the preset distributed cache database can only write a preset number of the first order payment requests.
[0075] The preset quantity is typically one, ensuring that only one specific order exists in the distributed cache database during order duplication and high concurrency. The first order payment request includes at least merchant information and an order number.
[0076] Specifically, the first anti-duplicate verification operation is used to prevent multiple identical order payment requests from occurring in the distributed cache database, and the cache anti-concurrency verification operation is used to prevent high-concurrency events from occurring in the distributed cache database.
[0077] Figure 3 A flowchart illustrating a distributed cache according to an embodiment of the present disclosure is shown schematically.
[0078] like Figure 3 As shown, the high-concurrency payment order anti-duplicate measure in this embodiment includes operations S310 to S340. Operation S210 can be executed by operations S310 to S340.
[0079] In operation S310, a unique key value is generated based on the merchant information and order number in the first order payment request.
[0080] According to embodiments of this disclosure, the preset distributed cache database stores data in the form of key-value pairs.
[0081] Specifically, in the distributed caching database Redis, data is stored in key-value format, and the unique key mentioned above is the key value. For example, the merchant information and order number in the first order payment request can be concatenated to obtain the key value. Of course, the value can be the order details information from the first order payment request.
[0082] In operation S320, it is determined whether the unique key value exists in the distributed cache database.
[0083] It is understood that the above operation S320 is the first anti-duplicate verification operation.
[0084] In operation S330, when the unique key value does not exist in the distributed cache database, it is determined whether the data value corresponding to the unique key value can be created based on the distributed lock.
[0085] According to an embodiment of this disclosure, the step of creating the data value corresponding to the unique key value based on the distributed lock includes: obtaining the data value corresponding to the unique key value through a single thread based on the unique key value; and creating the data value if obtaining the data value corresponding to the unique key value fails.
[0086] It is understandable that the above operation S330 is the cache anti-concurrency verification operation.
[0087] In operation S340, when the data value corresponding to the unique key value can be created, the first order payment request is written to the distributed cache database based on the form of the key-value pair.
[0088] It should be noted that in the embodiments of this disclosure, in the event of high order concurrency, multiple identical first order payment requests may be received simultaneously. These multiple identical first order payment requests will be converted into multiple identical keys before being entered into the database. At the same time, the first anti-duplicate verification operation performed on these identical key values is concurrent and simultaneous. Once such a high concurrency event occurs, simply performing the first anti-duplicate verification operation can only ensure that there is no key value in the distributed cache database Redis that is the same as the one just received, but it cannot prevent multiple identical key values from entering the distributed cache database Redis at the same time. Therefore, in addition to this, the above-mentioned cache concurrency verification operation should also be performed.
[0089] Specifically, the `setNx` method of the Redis distributed cache database is used to write data to Redis. Because Redis operates in a single-process, single-threaded mode, and the `setNx` method only sets the key's value to `value` and returns 1 if the key does not exist (i.e., the `setNx` operation succeeds); if the given key already exists, `setNx` does nothing and returns 0 (i.e., the `setNx` operation fails). Utilizing these two characteristics, when entering the Redis distributed cache database, only one of all identical requests will return a successful `setNx` operation. A request that returns a failed `setNx` is definitely the first concurrent order payment request, and the customer is directly notified of a duplicate request. For example, when 10 concurrent first order payment requests arrive at step 2 simultaneously, it is determined that the corresponding key does not exist in the Redis distributed cache database. All 10 requests can pass step 2. Because Redis commands are executed in a single thread, when the `setNx` method is executed in step 3, only one request will return a successful `setNx`, while the rest will return failures.
[0090] In the embodiments of this disclosure, in the anti-duplicate verification of the distributed cache database, in addition to the conventional first anti-duplicate verification operation, the characteristics of single thread and distributed lock are cleverly used in the anti-concurrency processing, effectively reducing repeated concurrency to a minimum.
[0091] According to an embodiment of this disclosure, after writing the first order payment request into the distributed cache database, the method further includes: setting an expiration time for the first order payment request in the distributed cache database.
[0092] Specifically, set a timeout period to prevent data in the distributed cache database from not being cleared in time, thus ensuring the performance of the distributed cache database.
[0093] In operation S220, a second anti-duplicate verification operation is performed on the first order payment request from the distributed cache database to determine whether the first order payment request exists in the order database.
[0094] According to an embodiment of this disclosure, the step of performing a second anti-duplicate verification operation on the first order payment request from the distributed cache database includes: querying whether a corresponding order payment request exists in the order database based on the merchant information and the order number as a query index.
[0095] For example, the merchant information and order number can be concatenated to obtain a unique query index, and the order database entry operation for the first order payment request can be completed so that when a new order payment request is received, the order database can be checked for duplicates.
[0096] Ideally, after passing the initial anti-duplicate verification and cache concurrency prevention verification operations, the first and only first order payment request should be entered into the order database. However, considering that the distributed cache database may experience partial failure of its filtering mechanism when dealing with high concurrency, a unique index is established using merchant information and order number before the request is finally entered into the order database to prevent multiple identical first order payment requests from appearing in the order database.
[0097] In operation S230, if the first order payment request does not exist in the order database, the first order payment request is written into the order database.
[0098] In the embodiments of this disclosure, by combining the first anti-duplicate verification operation and the cache anti-concurrency verification operation, the distributed cache database can achieve the effects of order deduplication and order concurrency prevention. Furthermore, by performing a second anti-duplicate verification operation in the order database, redundant requests in the order database can be filtered out when the first anti-duplicate verification operation and the cache anti-concurrency verification operation partially fail. This improves fault tolerance in detecting duplicate orders, avoids data performance degradation, and prevents the risk of related servers crashing when concurrency reaches a certain level.
[0099] Figure 4 The diagram illustrates the entire process of a high-concurrency payment order anti-duplicate method according to an embodiment of the present disclosure.
[0100] like Figure 4 As shown, the high-concurrency payment order anti-duplicate method of this embodiment includes operations S401 to S413.
[0101] In operation S401, submit a payment order.
[0102] Specifically, the merchant's client submits the payment order, and the payment order is distributed by the reverse proxy server to the corresponding application server for processing.
[0103] In operation S402, a unique key value is generated using merchant information and merchant order number.
[0104] In operation S403, determine whether the key exists in the Redis cluster. If it does, execute operation S406; otherwise, execute operation S404.
[0105] In operation S404, the Redis setNx method is used to set the value of the key.
[0106] In operation S405, determine whether the setNx setting was successful. If it was, execute operation S407; otherwise, execute operation S406.
[0107] In operation S406, a message appears indicating a duplicate submission.
[0108] In operation S407, set the expiration time of the key.
[0109] In operation S408, the database is queried based on merchant information and merchant order number.
[0110] For example, the merchant information could be a merchant ID.
[0111] In operation S409, determine whether the order exists in the database. If it does, execute operation S410; otherwise, execute operation S411.
[0112] During the operation of S410, a message appeared indicating that a duplicate order had been placed.
[0113] In operation S411, insert data into the database (the database uses merchant information and merchant order number as unique indexes).
[0114] In operation S412, order follow-up processing is performed.
[0115] In operation S413, the order is successfully completed and the order number information is returned.
[0116] For example, the post-order processing could involve proceeding to the payment stage, where the payment is processed, and upon successful completion of the payment, the corresponding order number information would be provided.
[0117] In the embodiments disclosed herein, the high-concurrency processing performance requirements of the bank's open platform order-taking service after connecting to a large number of merchants are effectively addressed, while also effectively intercepting malicious order fraud. This disclosure uses a front-end Nginx reverse proxy server to load balance front-end requests, evenly distributing concurrent requests to various application instances in the back-end server cluster. Simultaneously, a unified Redis cache queue is used to effectively filter duplicate requests. Then, leveraging the characteristics of the `setNx` method in Redis, identical requests that have passed Redis's anti-duplicate verification are filtered a second time, effectively eliminating duplicate concurrent requests. Finally, through reverse lookups in the database and the database's uniqueness feature, database-level anti-duplicate and anti-concurrency processing is performed. At this point, only one of all identical concurrent requests is ultimately written to the database, effectively reducing the pressure on the database server.
[0118] Based on the above-mentioned methods for preventing duplicate payments during high concurrency, this disclosure also provides a device for preventing duplicate payments during high concurrency. The following will be combined with... Figure 5 The device is described in detail.
[0119] Figure 5A schematic block diagram of a high-concurrency payment order anti-duplicate device according to an embodiment of the present disclosure is shown.
[0120] like Figure 5 As shown, the high-concurrency payment order anti-duplicate device 500 of this embodiment includes a distributed cache database verification module 510, an order database verification module 520, and a payment processing module 530.
[0121] The distributed cache database verification module 510 is used to sequentially perform a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request, so as to ensure that the preset distributed cache database can only write a preset number of the first order payment requests. In one embodiment, the distributed cache database verification module 510 can be used to perform the operation S210 described above, which will not be repeated here.
[0122] The order database verification module 520 is used to perform a second anti-duplicate verification operation on the first order payment request from the distributed cache database to determine whether the first order payment request exists in the order database. In one embodiment, the order database verification module 520 can be used to perform the operation S220 described above, which will not be repeated here.
[0123] The payment processing module 530 is configured to write the first order payment request into the order database when the first order payment request does not exist in the order database. In one embodiment, the payment processing module 530 may be used to perform the operation S230 described above, which will not be repeated here.
[0124] According to an embodiment of this disclosure, the preset distributed cache database stores data in key-value pairs. The distributed cache database verification module is further configured to: generate a unique key-value pair based on the merchant information and order number in the first order payment request; determine whether the unique key-value pair exists in the distributed cache database; when the unique key-value pair does not exist in the distributed cache database, determine whether the data value corresponding to the unique key-value pair can be created based on a distributed lock; and when the data value corresponding to the unique key-value pair can be created, write the first order payment request into the distributed cache database based on the key-value pair format.
[0125] According to an embodiment of this disclosure, the distributed cache database verification module is further configured to obtain the data value corresponding to the unique key value through a single thread based on the unique key value; and to create the data value if obtaining the data value corresponding to the unique key value fails.
[0126] According to an embodiment of this disclosure, the order database verification module is further configured to query whether a corresponding order payment request exists in the order database based on the merchant information and the order number as a query index.
[0127] According to an embodiment of this disclosure, the apparatus further includes an expiration time setting module, which is further configured to set the expiration time of the first order payment request in the distributed cache database.
[0128] According to embodiments of this disclosure, any plurality of modules among the distributed cache database verification module 510, the order database verification module 520, and the payment processing module 530 can be combined into one module, or any one of these modules can be split into multiple modules. Alternatively, at least some of the functions of one or more of these modules can be combined with at least some of the functions of other modules and implemented in one module. According to embodiments of this disclosure, at least one of the distributed cache database verification module 510, the order database verification module 520, and the payment processing module 530 can be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or implemented by any other reasonable means of integrating or packaging the circuitry, or implemented by any one of software, hardware, and firmware implementations, or by a suitable combination of any of these. Alternatively, at least one of the distributed cache database verification module 510, the order database verification module 520, and the payment processing module 530 may be implemented at least partially as a computer program module, which can perform corresponding functions when the computer program module is run.
[0129] Figure 6 A block diagram schematically illustrates an electronic device suitable for implementing a high-concurrency payment order anti-duplicate method according to an embodiment of the present disclosure.
[0130] like Figure 6As shown, an electronic device 600 according to an embodiment of this disclosure includes a processor 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage portion 608 into a random access memory (RAM) 603. The processor 601 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 601 may also include onboard memory for caching purposes. The processor 601 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of this disclosure.
[0131] RAM 603 stores various programs and data required for the operation of electronic device 600. Processor 601, ROM 602, and RAM 603 are interconnected via bus 604. Processor 601 performs various operations of the method flow according to embodiments of the present disclosure by executing programs in ROM 602 and / or RAM 603. It should be noted that the programs may also be stored in one or more memories other than ROM 602 and RAM 603. Processor 601 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in said one or more memories.
[0132] According to embodiments of this disclosure, the electronic device 600 may further include an input / output (I / O) interface 605, which is also connected to a bus 604. The electronic device 600 may also include one or more of the following components connected to the I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 610 as needed so that computer programs read from it can be installed into the storage section 608 as needed.
[0133] This disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs that, when executed, implement the method according to the embodiments of this disclosure.
[0134] According to embodiments of this disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, such as including, but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this disclosure, the computer-readable storage medium may include ROM 602 and / or RAM 603 and / or one or more memories other than ROM 602 and RAM 603 described above.
[0135] Embodiments of this disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to cause the computer system to implement the methods provided in the embodiments of this disclosure.
[0136] When the computer program is executed by the processor 601, it performs the functions defined in the system / apparatus of this disclosure embodiments. According to embodiments of this disclosure, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0137] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and downloaded and installed via the communication section 609, and / or installed from the removable medium 611. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0138] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable medium 611. When the computer program is executed by the processor 601, it performs the functions defined in the system of this disclosure embodiment. According to embodiments of this disclosure, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0139] According to embodiments of this disclosure, program code for executing the computer programs provided in embodiments of this disclosure can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0140] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0141] Those skilled in the art will understand that the features described in the various embodiments and / or claims of this disclosure can be combined or combined in various ways, even if such combinations or combinations are not explicitly described in this disclosure. In particular, the features described in the various embodiments and / or claims of this disclosure can be combined or combined in various ways without departing from the spirit and teachings of this disclosure. All such combinations and / or combinations fall within the scope of this disclosure.
[0142] The embodiments of this disclosure have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of this disclosure. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. The scope of this disclosure is defined by the appended claims and their equivalents. Various substitutions and modifications can be made by those skilled in the art without departing from the scope of this disclosure, and all such substitutions and modifications should fall within the scope of this disclosure.
Claims
1. A method for preventing duplicate payment orders during high concurrency, the method being applied to an application server cluster, the method comprising: The first order payment request is processed sequentially with the first anti-duplicate verification operation and the cache anti-concurrency verification operation to ensure that the preset distributed cache database can only write a preset number of the first order payment requests. A second anti-duplicate verification operation is performed on the first order payment request from the distributed cache database to determine whether the first order payment request exists in the order database; as well as If the first order payment request does not exist in the order database, the first order payment request will be written into the order database. The first anti-duplicate verification operation and the second anti-duplicate verification operation are performed before the payment process. The preset distributed cache database stores data in key-value pairs. The step of sequentially performing a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request includes: generating a unique key-value pair based on the merchant information and order number in the first order payment request; determining whether the unique key-value pair exists in the distributed cache database; if the unique key-value pair does not exist in the distributed cache database, determining whether the data value corresponding to the unique key-value pair can be created based on a distributed lock; and if the data value corresponding to the unique key-value pair can be created, writing the first order payment request into the distributed cache database based on the key-value pair format. The step of performing a second anti-duplicate verification operation on the first order payment request from the distributed cache database includes: querying the order database to see if a corresponding order payment request exists, based on the merchant information and the order number as a query index.
2. The method according to claim 1, wherein, The first order payment request is sent to the application server cluster by the reverse proxy server through a polling method.
3. The method according to claim 1, wherein, The process of creating the data value corresponding to the unique key based on the distributed lock includes: Based on the unique key value, the data value corresponding to the unique key value is obtained through a single thread; and If it fails to retrieve the data value corresponding to the unique key, the data value is created.
4. The method according to any one of claims 1 to 3, wherein, After writing the first order payment request to the distributed cache database, the method further includes: Set the expiration time for the first order payment request in the distributed cache database.
5. A high-concurrency payment order anti-duplicate device, the device being applied to an application server cluster, the device comprising: The distributed cache database verification module is used to sequentially perform the first anti-duplicate verification operation and the cache anti-concurrency verification operation on the received first order payment request, so as to ensure that the preset distributed cache database can only write a preset number of the first order payment requests; The order database verification module is used to perform a second anti-duplicate verification operation on the first order payment request from the distributed cache database to determine whether the first order payment request exists in the order database. as well as The payment processing module is used to write the first order payment request into the order database when the first order payment request does not exist in the order database; The first anti-duplicate verification operation and the second anti-duplicate verification operation are performed before the payment process. The preset distributed cache database stores data in key-value pairs. The step of sequentially performing a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request includes: generating a unique key-value pair based on the merchant information and order number in the first order payment request; determining whether the unique key-value pair exists in the distributed cache database; if the unique key-value pair does not exist in the distributed cache database, determining whether the data value corresponding to the unique key-value pair can be created based on a distributed lock; and if the data value corresponding to the unique key-value pair can be created, writing the first order payment request into the distributed cache database based on the key-value pair format. The step of performing a second anti-duplicate verification operation on the first order payment request from the distributed cache database includes: querying the order database to see if a corresponding order payment request exists, based on the merchant information and the order number as a query index.
6. A high-concurrency payment order anti-duplicate system, the system comprising a reverse proxy server, an application server cluster, a distributed cache cluster, and a database server cluster. in, The reverse proxy server is configured to perform load balancing on the first order payment request, so as to distribute it to the application server cluster; The application server cluster is configured to sequentially perform a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request, so as to ensure that the preset distributed cache database can only write a preset number of the first order payment requests; and to perform a second anti-duplicate verification operation on the first order payment request from the distributed cache database, so as to determine whether the first order payment request exists in the order database. And when the first order payment request does not exist in the order database, the first order payment request is written into the order database; The distributed cache cluster is configured to cache the first order payment request; as well as The database server cluster is configured to store the first order payment request; The first anti-duplicate verification operation and the second anti-duplicate verification operation are performed before the payment process. The preset distributed cache database stores data in key-value pairs. The step of sequentially performing a first anti-duplicate verification operation and a cache anti-concurrency verification operation on the received first order payment request includes: generating a unique key-value pair based on the merchant information and order number in the first order payment request; determining whether the unique key-value pair exists in the distributed cache database; if the unique key-value pair does not exist in the distributed cache database, determining whether the data value corresponding to the unique key-value pair can be created based on a distributed lock; and if the data value corresponding to the unique key-value pair can be created, writing the first order payment request into the distributed cache database based on the key-value pair format. The step of performing a second anti-duplicate verification operation on the first order payment request from the distributed cache database includes: querying the order database to see if a corresponding order payment request exists, based on the merchant information and the order number as a query index.
7. The system according to claim 6, wherein, The reverse proxy server is also configured to perform load balancing via round-robin.
8. The system according to claim 6, wherein, The distributed cache cluster includes multiple distributed storage shards, each including a master distributed storage shard and slave distributed storage shards; and The database server cluster includes multiple database servers, including a master database server and slave database servers.
9. An electronic device, comprising: One or more processors; Storage device for storing one or more programs. Wherein, when the one or more programs are executed by the one or more processors, the one or more processors perform the method according to any one of claims 1 to 4.
10. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, cause the processor to perform the method according to any one of claims 1 to 4.
11. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Concurrent payment method, system and device
CN112101955A
Apparatus for payment system and operation method of payment system
US20200126091A1