Order duplicate prevention method and device, electronic equipment, storage medium and program product

By employing a multi-layered anti-duplicate verification mechanism, combined with local caching, distributed caching, and relational databases, the problem of easy penetration in order anti-duplicate verification in existing technologies has been solved, achieving stable order processing under high security and high concurrency.

CN120852022BActive Publication Date: 2026-01-09云账户技术(天津)有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202511354052.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-22
Publication Date
2026-01-09
Estimated Expiration
2045-09-22

AI Technical Summary

Technical Problem

In existing technologies, relying on composite key unique indexes in relational databases to prevent order duplication is easily penetrated, lacks fallback measures, and poses a high security risk.

Method used

A multi-layered anti-duplicate verification mechanism is adopted, including local caching, distributed caching, and relational database. The first, second, and third anti-duplicate verifications complement each other to ensure the uniqueness of order requests.

Benefits of technology

It effectively reduces the risk of duplicate payments, improves system security and throughput in high-concurrency scenarios, and reduces the risk of duplicate payment failure caused by single point of failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120852022B_ABST
    Figure CN120852022B_ABST
Patent Text Reader

Abstract

The application provides an order duplicate prevention method and device, electronic equipment, a storage medium and a program product, relates to the technical field of computers, and a method applied to a client includes: performing a first duplicate prevention check operation on N first order requests to determine whether the N first order requests have duplicate order requests in a local cache, N being an integer greater than 1; in the case that the N first order requests do not have duplicate orders in the local cache, writing the N first order requests into a distributed cache layer, and performing a second duplicate prevention check operation on the N first order requests to perform corresponding business operations on the order requests that do not have duplicates. The embodiments of the application are used for solving the problem of security caused by the penetration of the existing single-layer order duplicate prevention.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of computer, in particular, to an order anti-duplication method and device, electronic equipment, storage medium and program product. BACKGROUND

[0002] At present, order anti-duplication is mainly implemented by relying on the composite key unique index of a relational database. Specifically, a settlement system combines user ID, settlement amount, time window and other dimensions as a unique key by newly creating an order anti-duplication table, generates a unique identifier by Hash calculation and inserts it into the table, and relies on database unique constraint conflict interception to intercept repeated requests. However, if there is a logic error (for example, Hash algorithm defects or index configuration errors) in this scheme, there is a lack of bottom-up measures, which will directly cause repeated payments, and the security risk is high. SUMMARY

[0003] The present disclosure provides an order anti-duplication method, device, electronic equipment, storage medium and program product, which is used to solve the problem of security caused by the penetration of the existing single-layer order anti-duplication.

[0004] In a first aspect, the present disclosure provides an order anti-duplication method, comprising:

[0005] performing a first anti-duplication verification operation on N first order requests to determine whether there are duplicate order requests in a local cache, N being an integer greater than 1;

[0006] in the case where there are no duplicate orders in the local cache, writing the N first order requests to a distributed cache layer and performing a second anti-duplication verification operation on the N first order requests to perform corresponding business operations on the order requests without duplicates.

[0007] Optionally, the performing of the first anti-duplication verification operation on the plurality of first order requests to determine whether there are duplicate order requests in the local cache comprises:

[0008] querying, based on a first identifier corresponding to each of the first order requests, whether there is an order request duplicated with the first order request in the local cache to determine whether there are duplicate order requests in the local cache.

[0009] wherein each of the first order requests corresponds to a first identifier.

[0010] Optionally, the performing of the second anti-duplication verification operation on the N first order requests to perform corresponding business operations on the order requests without duplicates comprises:

[0011] M second order requests are obtained from the N first order requests, a creation time of the M second order requests is within a preset time window, M is an integer greater than 1;

[0012] In a case where the M is less than or equal to a first threshold, a corresponding business operation is performed on the order request without repetition; wherein the M second order requests include the order request without repetition.

[0013] Optionally, the case where the M is less than or equal to the first threshold, the corresponding business operation is performed on the order request without repetition, includes:

[0014] In a case where the number of the M second order requests is less than or equal to the first threshold, the M second order requests are written into a database;

[0015] A third anti-duplication verification operation is performed on the M second order requests to determine whether a second identifier of each of the second order requests is unique, and at least one target order request is determined; wherein the target order request is one of the M second order requests;

[0016] A corresponding business operation is performed on the target order request.

[0017] Optionally, the third anti-duplication verification operation is performed on the M second order requests to determine whether the second identifier of each of the second order requests is unique, and at least one target order request is determined, includes:

[0018] According to the second identifier corresponding to each of the second order requests, at least one third order request is determined from the M second order requests, the third order request is the second order request with only a unique second identifier;

[0019] Each of the third order requests is sorted according to a preset time rule, and a third order request arranged in a preset position is determined as the target order request.

[0020] Optionally, the method further includes:

[0021] In a case where the number of the N first order requests recorded in the local cache within the preset time window is greater than a second threshold, the N first order requests are intercepted.

[0022] In a second aspect, the application further provides an order anti-duplication method, including:

[0023] A first operation module is configured to perform a first anti-duplication verification operation on N first order requests to determine whether there is a repeated order request in a local cache, N is an integer greater than 1.

[0024] The second operation module is configured to write the N first order requests into the distributed cache layer and perform a second duplicate checking operation on the N first order requests to perform corresponding business operations on the order requests without duplication in the case that the N first order requests do not have duplicate orders in the local cache.

[0025] In a third aspect, the present application provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method according to the first aspect.

[0026] In a fourth aspect, the present application provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program, when executed by a processor, implements the steps of the method according to the first aspect.

[0027] In a fifth aspect, the present application provides a computer program product, comprising computer instructions, wherein the computer instructions, when executed by a processor, implement the steps of the method according to the first aspect.

[0028] In the embodiments of the present application, the first duplicate checking operation is performed on the N first order requests to determine whether there are duplicate order requests in the local cache, and in the case that the N first order requests do not have duplicate orders in the local cache, the N first order requests are written into the distributed cache layer, and the second duplicate checking operation is performed on the N first order requests to perform corresponding business operations on the order requests without duplication. In this way, the first duplicate checking operation and the second duplicate checking operation are used to mutually compensate for the respective defects of the multiple layers of protection, reduce the risk of repeated payments, avoid penetration of single-layer protection, and improve the security of the system. BRIEF DESCRIPTION OF DRAWINGS

[0029] Figure 1 is one of the flow diagrams of the order duplicate prevention method provided by the embodiments of the present application;

[0030] Figure 2 is the overall architecture diagram of the order duplicate prevention system provided by the embodiments of the present application;

[0031] Figure 3 is the second flow diagram of the order duplicate prevention method provided by the embodiments of the present application;

[0032] Figure 4 is the structure diagram of the order duplicate prevention device provided by the embodiments of the present application;

[0033] Figure 5FIG. 1 is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0034] The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are some but not all of the embodiments of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present disclosure.

[0035] The present application provides an order duplicate prevention method and device, electronic equipment, storage medium and program product. The following will be described in detail through specific embodiments and application scenarios.

[0036] Please refer to Figure 1 The present application provides an order duplicate prevention method, comprising:

[0037] Step 101, performing a first duplicate prevention checking operation on N first order requests to determine whether there are duplicate order requests in the local cache, N is an integer greater than 1.

[0038] It should be noted that the above first order request can be an original order request initiated by a user through a client, and can include user ID, settlement amount, creation time, payment channel and the like.

[0039] In the above step, the first order request can be queried in the local cache. The local cache can use a cache tool with LRU (Least Recently Used) characteristics, the key can be the order identifier, and the value can be the order information (order number, amount, creation time, etc.). Specifically, it is queried whether the order identifier exists in the local cache: if it exists, it is determined as a duplicate order request, and all requests are directly intercepted and returned as "frequent operation"; if it does not exist, the first identifier of the order request is written into the local cache, and is released to the distributed cache layer.

[0040] It is worth mentioning that if the number of first order requests recorded in the local cache within a preset time window exceeds a second threshold (for example, more than 5 requests initiated by the same user within 1 minute), all requests are directly intercepted. For example, user A initiates 3 settlement requests with an amount of 100.00 yuan within 10 seconds, the normalized amount is 100 yuan, and the order identifier is "userA:100". If the identifier exists in the local cache, the last 2 requests will be directly intercepted.

[0041] Step 102, in the case that the N first order requests do not exist repeated orders in the local cache, write the N first order requests into the distributed cache layer, and perform a second anti-duplicate checking operation on the N first order requests to perform corresponding business operations on the order requests that do not exist duplicates.

[0042] The above-mentioned distributed cache layer can be a cache layer implemented based on a distributed memory database such as Redis, used for anti-duplicate checking across service nodes.

[0043] The above-mentioned step is a second anti-duplicate checking based on the distributed cache layer, used to solve the problem of repeated requests across service nodes and ensure the effectiveness of anti-duplicate checking at the cluster level.

[0044] Specifically, the N first order requests that pass the local cache checking can be written into the distributed cache, synchronized to the distributed cache layer (Redis cluster), and Redis can store order information in a Sorted Set structure, with the key being the user ID and the value containing the order number, creation time, first identifier, etc., used for filtering requests by time window. Through the ZCOUNT command of Redis, the number of order requests with creation time within a preset time window is counted to obtain M second order requests (M can be the total number of requests within the time window).

[0045] If M≤the first value (for example, 3 times / minute, that is, the maximum allowed number of requests per unit time), it is determined that it is not a repeated request, and the subsequent business operation is allowed to be performed. If M>the first value, it is determined that it is a repeated request, and the request is intercepted and a "repeated request" is returned.

[0046] For example, after 3 requests of user A pass the local cache checking, they are written into Redis. The server can query the total number of requests M=3 of user A within 1 minute, and if the first value is 3, then M≤the first value, and the request is released to the database layer; if M=4, it is intercepted.

[0047] In this way, through the multi-layer checking of local cache and distributed cache in the embodiments of the present application, the defects of single-layer protection (such as database single-point failure, cache penetration, etc.) can be compensated for each other, and the risk of repeated payment can be reduced. In addition, the embodiments of the present application can also take advantage of the high performance characteristics of local cache and distributed cache to improve system throughput and be suitable for high-concurrency scenarios.

[0048] Optionally, the first anti-duplicate checking operation performed on the plurality of first order requests to determine whether the plurality of first order requests exist repeated order requests in the local cache comprises:

[0049] query, based on the first identifier corresponding to each of the first order requests, whether there is an order request that is repeated with the first order request in the local cache to determine whether the multiple first order requests have repeated order requests in the local cache;

[0050] Each of the first order requests corresponds to a first identifier.

[0051] In some embodiments, a unique "first identifier" can be generated for each order request, and the identifier can be queried based on the local cache to determine whether the order is repeated. Thus, by using the high performance characteristics of the local cache, most of the repeated orders can be intercepted before entering the downstream system, reducing the system pressure and improving the response speed.

[0052] The first identifier described above can be a composite identifier generated for local duplicate prevention, which is composed of key duplicate prevention dimensions (such as user ID, normalized settlement amount, etc.) in the first order request, and can be calculated by a Hash function.

[0053] Specifically, for each first order request, the core dimensions involved in duplicate prevention verification are extracted, including: user ID (unique identifier of the enterprise user initiating settlement) and settlement amount (which can be subjected to "amount normalization", such as removing invalid zero values after decimal points, unifying units, etc., to avoid false positives due to format differences, for example, "100.00 yuan" and "100 yuan" are unified to "100"). The extracted key information is combined according to a fixed rule (for example, "user ID: normalized amount"), and a unique hash value, i.e., the "first identifier" of the order request, is calculated by a hash function. Illustratively, the user ID is "user123" and the normalized amount is "500", which are combined as "user123:500", and the first identifier "a7b3c9..." is calculated by hashing.

[0054] Thus, the local cache can be queried to determine duplicates, and the local cache stores the first identifiers and corresponding information of recent orders (such as within a preset sliding time window, usually 1 minute). The server can perform the following operations on the first identifier generated at present: if the first identifier already exists in the local cache, it means that the same user has initiated an order request of the same amount within the time window, and it is determined as a "duplicate order", which is directly intercepted and returns a "frequent operation" prompt; if the first identifier does not exist in the local cache, it means that the current order has not been detected as a duplicate in the local cache layer, and the first identifier is written into the local cache (and the creation time is recorded), allowing the order request to enter the next layer of verification (distributed cache layer).

[0055] It is worth mentioning that the local cache can adopt the LRU feature, which can automatically discard order information that exceeds the preset sliding time window, ensuring that only valid time anti-duplicate data is retained in the cache, and avoiding memory overflow.

[0056] In this way, in the embodiments of the application, the local cache belongs to memory-level operation, and the response speed is much faster than database query, so that repeated requests can be quickly intercepted in a high-concurrency scenario, solving the problem of low throughput of traditional databases and inapplicability to high concurrency.

[0057] The generation of the first identifier is based on multi-dimensional combination and normalization processing, avoiding the misjudgment risk of single-dimensional anti-duplication and improving the anti-duplication accuracy. At the same time, the local cache as the first layer of protection reduces the pressure on the downstream distributed cache and database. In the above embodiments of the application, the local cache is independent of the distributed cache and the database, so even if the downstream system is abnormal, most of the repeated requests can still be intercepted through the local cache, reducing the risk of anti-duplication failure caused by single-point failure.

[0058] Optionally, the second anti-duplication checking operation is performed on the N first order requests to perform a corresponding business operation on the order request that does not exist.

[0059] M second order requests are obtained from the N first order requests, the creation time of the M second order requests being within a preset time window, and M being an integer greater than 1;

[0060] In the case where M is less than or equal to a first threshold, a corresponding business operation is performed on the order request that does not exist; wherein the M second order requests include the order request that does not exist.

[0061] In some embodiments, the second layer of checking (distributed memory database layer checking) can be an anti-duplication check on order requests across service nodes after the local cache layer check passes. The core is to compare the number of order requests within a preset time window with a threshold to determine whether to allow subsequent business operations, solving the problem that a single local cache cannot cope with repeated requests in a distributed scenario.

[0062] It should be noted that the above-mentioned second order request can be an order request (for example, a request initiated within 1 minute) filtered from the N first order requests and having a creation time within a "preset time window". The above-mentioned preset time window can be a pre-set anti-duplication time range (for example, 1 minute), which can be used to limit the number of orders within a unit time. The first value can be a maximum order quantity threshold (for example, a user is allowed to have at most 3 orders of the same amount within 1 minute) allowed by the distributed cache layer within a unit time.

[0063] In specific embodiments, N first order requests are obtained, which are orders that are not intercepted after being checked by the local cache layer, i.e., the first identifier is not found to be repeated in the local cache, and need to be further checked by the distributed cache layer. M second order requests are screened. The distributed cache layer can use a Sorted Set data structure to store order information, with the user ID as the key and the order creation time as the score, and the value containing the order number, amount, etc. The server can use the Redis command to screen out the orders created within the "preset time window" (for example, 1 minute ago) from the N first order requests, obtaining M second order requests. Exemplarily, N = 5 (5 requests that pass the local check) can screen out 3 requests created within the last 1 minute, i.e., M = 3.

[0064] Subsequently, a comparison with the first value can be made to compare M (the number of orders within the preset time window) with the first value (threshold value): if M ≤ first value, it means that the number of orders per unit time does not exceed the limit, and it is determined as "non-repeated request", allowing subsequent business operations (such as writing to the database and performing third layer check) to be performed; if M > first value, it means that the number of orders per unit time exceeds the limit, and it is determined as "repeated request", which is directly intercepted and a "repeated request" prompt is returned. Exemplarily, the first value can be set to 3, and if M = 3 (equal to the threshold value), it is allowed to pass; if M = 4 (exceeds the threshold value), it is intercepted.

[0065] In this way, compared with directly writing to the database, the query and counting operations of the distributed cache have higher performance, and can quickly intercept requests exceeding the threshold value in a high-concurrency scenario, reducing the pressure on the database. Moreover, a funnel-type protection is formed with the local cache layer, the local cache intercepts single-node repeated requests, and the distributed cache intercepts cross-node repeated requests, thereby jointly reducing the risk of repeated orders penetrating to the database.

[0066] Optionally, in the case where the M is less than or equal to the first threshold value, performing a corresponding business operation on the order request that does not exist repetition, comprising:

[0067] In the case where the number of the M second order requests is less than or equal to the first threshold value, writing the M second order requests into the database;

[0068] Performing a third anti-repetition check operation on the M second order requests to determine whether the second identifier of each of the second order requests is unique, and determining at least one target order request; wherein the target order request is one of the M second order requests;

[0069] Performing a corresponding business operation on the target order request.

[0070] In yet another embodiment, a third layer of duplicate prevention checking operation, i.e., relational database layer checking, can be provided, which can be the final bottom-up link for order duplicate prevention. After the distributed cache layer checking passes (M≤first threshold), the target order that can perform the business operation is finally determined through the unique constraint and sorting rules of the database, so as to reduce the risk of repeated payment.

[0071] The first threshold described above can be the maximum number of orders allowed to enter the database layer (for example, a maximum of 3 orders for the same user within 1 minute) in the distributed cache layer. The second identifier described above can be a composite unique identifier used for duplicate prevention in the database layer, which is composed of a user ID, a normalized amount, and a time slice, and serves as the basis for a database unique index. The target order request can be an order that is uniquely allowed to perform a payment operation and the like after being checked by the database layer (usually the earliest order created within a time window).

[0072] In the specific implementation process, when the distributed cache layer determines that M (the number of orders within a preset time window) ≤ the first threshold, the server can write the M order requests to the order duplicate prevention table of the relational database. The table can be pre-configured with a composite unique index (such as user_id+amount_fp+time_slot) with the second identifier as the core, which is used to trigger unique key conflict detection. Subsequently, a third duplicate prevention checking operation can be performed, and the database layer ensures order uniqueness through the following two steps: first, the unique identifier checking can use the unique index of the order duplicate prevention table to check whether the second identifier of each second order request already exists. If it exists, a database unique key conflict is triggered, and the order is determined to be duplicated and intercepted; if it does not exist, it is a third order request (i.e., an order with a unique corresponding second identifier). Second, the sorting determines the target order, which can sort all third order requests according to a preset rule of creation time+order number (such as the earliest creation time and the smallest order number priority), and select the order arranged in a preset position (usually the first position) as the target order request. Exemplarily, M=3 (3 orders within 1 minute), after unique index checking, all are third order requests, and after sorting by creation time, the earliest order initiated is determined as the target order.

[0073] Finally, the target order can perform a business operation, and only the target order is allowed to perform a payment operation and other core business operations, and the remaining orders, although passing the previous two layers of checking, are intercepted because they are not selected as the target order, so as to ensure that only one valid order is processed within the same time window.

[0074] It is worth mentioning that the write database and the unique index check are executed in the same transaction, avoiding the problem of asynchronous check and write in a concurrent scenario (for example, A order passes the check but is not written, and B order passes the check again). For time slicing, the time_slot in the second identifier can divide the preset time window into smaller time slices (for example, 10 seconds / slice), further improving the accuracy of the unique index and reducing conflict misjudgment.

[0075] In this way, in the above embodiments of the present application, even if the front two layers of cache check fail due to exceptions (such as cache penetration), the unique index of the database can still intercept repeated orders and avoid financial losses. In addition, the front two layers of cache intercept most repeated requests, and the database layer only processes a small number of compliant orders, which ensures safety and avoids the database from becoming a performance bottleneck.

[0076] Optionally, the third duplicate prevention check operation is performed on the M second order requests to determine whether the second identifier of each second order request is unique, and at least one target order request is determined, including:

[0077] According to the second identifier corresponding to each second order request, at least one third order request is determined from the M second order requests, and the third order request is the second order request with only a unique second identifier;

[0078] Each third order request is sorted according to a preset time rule, and a third order request arranged in a preset position is determined as the target order request.

[0079] In some embodiments, the target order that can be executed for payment can be finally determined from the M second order requests through the second identifier uniqueness check and the preset rule sorting two-step operation, which is the final safety guarantee for order duplicate prevention and solves the penetration risk that may exist in single-layer check.

[0080] It should be noted that the above-mentioned second identifier can be a composite unique identifier used by the database layer for duplicate prevention, which is a composite unique index key of the order duplicate prevention table of the relational database. The time slice is a subdivision of the preset time window, which ensures that orders in the same window can be accurately distinguished. The above-mentioned third order request can be determined after the second identifier uniqueness check, and there is no repeated second order request (i.e., its second identifier is not recorded in the database). The above-mentioned preset time rule can be a rule for sorting according to time-related dimensions such as order creation time and order serial number (for example, "earliest creation time first" and "smallest serial number first"). The above-mentioned preset position can be a unique valid position determined after sorting (usually the first position), and the order corresponding to this position is the target order.

[0081] In the implementation process, the database layer can perform verification through the composite unique index (based on the second identifier) of the order anti-duplication table: for each second order request, the system compares its second identifier (for example, "user123:500:20240520100000") with the existing records in the database. If the second identifier already exists (that is, the database triggers a unique key conflict), the order is determined to be duplicated and excluded from the valid order; if the second identifier does not exist (no conflict), the order is determined to be a third order request, that is, a candidate order that passes the uniqueness verification. For example, M=3 (3 second order requests), of which 2 orders have second identifiers that conflict with the database history records, and only 1 order passes the uniqueness verification and becomes a third order request.

[0082] For all third order requests, they can be sorted according to a preset time rule: they can be sorted in ascending order of "creation time" (the earliest created first), and if the creation time is the same, they can be sorted in ascending order of "order number" (the smallest order number first). Then, the target order is determined, and the third order request located at a preset position (usually the first position) after sorting is selected as the target order request, that is, the order that is uniquely allowed to execute the payment. For example, the creation times of the 3 third order requests are 10:00:01, 10:00:03, and 10:00:05, respectively, which can be sorted in ascending order of time, and the order of 10:00:01 is determined as the target order.

[0083] It is worth mentioning that the second identifier verification and the order writing are performed in the same database transaction, which ensures that the order information can be recorded atomically after the verification passes, avoiding the problem of asynchronous verification and writing in a concurrent scenario (for example, A order passes the verification but is not written, and B order repeatedly passes the verification). The composite unique index is guaranteed by the database native mechanism, which can more reliably intercept duplicate identifiers and avoid the failure of anti-duplication caused by code implementation errors compared with application layer logic verification.

[0084] In this way, through the above-mentioned embodiments of the present application as the last link of the three-layer verification, even if the previous two layers (local cache, distributed cache) fail due to exceptions (such as cache penetration, cluster failure), the unique index of the database can still intercept duplicate orders and completely avoid duplicate payments, solving the defect of the existing single-layer database anti-duplication without bottom-up. Through the composite dimensions of the second identifier and the time slice, combined with normalization processing, the false judgment caused by the difference in the amount format and the problem of time precision is avoided, and the anti-duplication accuracy is improved. In addition, the present application can sort according to a preset time rule, ensure that only the earliest valid order is processed within the same time window, meet the demand of processing the first request first in the business logic, and reduce the secondary confirmation cost with the user.

[0085] Optionally, the method further comprises:

[0086] When the number of the N first order requests recorded in the local cache within the preset time window is greater than a second threshold, the N first order requests are intercepted.

[0087] In some embodiments, as a supplementary protection mechanism of the local cache layer (first layer of duplicate request checking), a second threshold is set to limit the total number of order requests within a preset time window, and when the number of requests exceeds the threshold, the requests are directly intercepted, further reducing the impact of duplicate requests on the downstream system and improving the system's ability to resist high-frequency requests.

[0088] In specific embodiments, the server can monitor the value of N in real time, and when N exceeds the second threshold, the interception mechanism is triggered: all subsequent requests of the user within the current preset time window are directly rejected, and a prompt of "operation too frequent, please try later" is returned; these requests are not allowed to enter the distributed cache layer or the database layer, and high-frequency requests are blocked from the source. For example, the second threshold is set to 5 (a maximum of 5 requests in 1 minute), and if the user "user123" initiates 6 requests in 1 minute (N=6), the 6th and subsequent requests will be directly intercepted by the local cache.

[0089] The above-mentioned second threshold can be adjusted according to the business scenario (for example, temporarily increasing the threshold during high-concurrency periods, and reducing the threshold for low-frequency businesses), and the interception effect can be observed in real time through a monitoring system (such as Prometheus+Grafana), to ensure that normal business is not affected, and abnormal requests can be effectively intercepted.

[0090] In this way, in the embodiments of the present application, for high-frequency requests caused by malicious order brushing and misoperation, total quantity limitation is used to avoid the collapse of local cache, distributed cache and database due to overload. The requests exceeding the threshold are directly intercepted in the local cache layer, without consuming the resources of the distributed cache or the database, thereby improving the throughput of the overall system. In addition, as a supplementary rule of the local cache layer, the first layer of protection network is formed together with the first identifier duplicate checking, further reducing the risk of duplicate requests penetrating to the downstream, and realizing multi-layer protection to compensate for defects.

[0091] Please refer to Figure 2 , Figure 2 is a whole architecture diagram of an order duplicate prevention system provided by the embodiments of the present application. The order duplicate prevention system in the embodiments of the present application effectively balances performance and data consistency through layered checking, and the specific implementation process is as follows:

[0092] First, through the local cache layer, for the realization of fast interception. Some embodiments, can use CaffeineCache and other local memory cache storage anti-coincidence key (Key = user ID + order number + amount + creation time), combined with the sliding window counter to real-time statistics user order volume in recent time. Exemplarily, after the client request arrives, first in the local cache layer fast check. If the cache exists the same key and not expired, then directly intercept the rejection (no need to touch the remote service), most of the repeated requests are blocked in this layer, significantly reducing the downstream pressure.

[0093] Subsequently, after the request is preliminarily checked by the local cache, the order request will flow to the sliding window counter (belongs to the flow control link), based on the preset rule statistics, judges the number of requests, if the threshold is intercepted, avoid high frequency request impact system; The request that is not intercepted enters the API gateway, after load balancing, further to the Redis cluster (distributed cache), with the help of the ordered set (Sorted Set) structure of Redis, according to the time range to filter orders, combined with the preset value check, intercept the repeated or excessive orders again.

[0094] Finally, the database layer is the third layer of protection of the order anti-coincidence scheme (bottom layer), mainly to solve the repeated order leakage problem caused by the abnormal scene of "cache invalidation, network delay" and so on in the front two layers of cache (local cache, Redis distributed cache). By establishing an order anti-coincidence table in a relational database (such as MySQL, PostgreSQL), using the original unique index and transaction mechanism of the database, ensuring the rigidity constraint of order uniqueness verification, avoiding the risk of repeated payment and other funds.

[0095] See Figure 3 An order anti-coincidence method in an embodiment of the present application, the method specifically includes:

[0096] Step 201, the server receives N first order requests sent by the client, each first order request corresponds to a first identifier;

[0097] Step 202, based on the first identifier corresponding to each first order request, query whether there is a repeated order request in the local cache, to determine whether there is a repeated order request in the local cache;

[0098] Step 203, in the case that the N first order requests do not exist in the local cache, write the N first order requests to the distributed cache layer;

[0099] Step 204, obtaining M second order requests from the N first order requests, a creation time of the M second order requests being within a preset time window, M being an integer greater than 1;

[0100] Step 205, in a case where a quantity of the M second order requests is less than or equal to the first threshold, writing the M second order requests into a database;

[0101] Step 206, determining at least one third order request in the M second order requests according to the second identifier corresponding to each of the second order requests, the third order request being the second order request in which only a unique second identifier exists;

[0102] Step 207, sorting each of the third order requests according to a preset time rule, and determining a third order request arranged at a preset position as the target order request;

[0103] Step 208, performing a corresponding business operation on the target order request.

[0104] It can be understood that all implementation manners in the above embodiments can refer to the related descriptions in the order duplication prevention method shown in the foregoing Figure 1 For the sake of avoiding repeated descriptions, the present embodiment will not be described herein.

[0105] Referring to Figure 4 The present disclosure provides an order duplication prevention device, comprising:

[0106] A first operation module 301 is configured to perform a first duplication prevention checking operation on N first order requests to determine whether the N first order requests have duplicated order requests in a local cache, N being an integer greater than 1.

[0107] A second operation module 302 is configured to write the N first order requests into a distributed cache layer in a case where the N first order requests do not have duplicated orders in the local cache, and perform a second duplication prevention checking operation on the N first order requests to perform a corresponding business operation on the order requests that do not have duplication.

[0108] Optionally, the first operation module 301 is configured to:

[0109] query whether there is an order request duplicated with the first order request in the local cache based on a first identifier corresponding to each of the first order requests to determine whether the multiple first order requests have duplicated order requests in the local cache.

[0110] Each of the first order requests corresponds to a first identifier.

[0111] Optionally, the second operation module 302 comprises:

[0112] a first obtaining sub-module, configured to obtain M second order requests from the N first order requests, the M second order requests being created within a preset time window, M being an integer greater than 1;

[0113] a first execution sub-module, configured to, in a case where the M is less than or equal to a first threshold, perform a corresponding business operation on the order request without repetition; wherein the M second order requests comprise the order request without repetition.

[0114] Optionally, the first execution sub-module comprises:

[0115] an order writing unit, configured to, in a case where the number of the M second order requests is less than or equal to the first threshold, write the M second order requests into a database;

[0116] an order confirmation unit, configured to perform a third anti-duplication verification operation on the M second order requests to determine whether a second identifier of each of the second order requests is unique, and determine at least one target order request; wherein the target order request is one of the M second order requests.

[0117] an operation execution unit, configured to perform a corresponding business operation on the target order request.

[0118] Optionally, the order confirmation unit is configured to:

[0119] determine at least one third order request from the M second order requests according to the second identifier corresponding to each of the second order requests, the third order request being the second order request with only one unique second identifier;

[0120] sort each of the third order requests according to a preset time rule, and determine a third order request arranged at a preset position as the target order request.

[0121] Optionally, the order anti-duplication device further comprises:

[0122] an order interception module, configured to, in a case where the number of the N first order requests recorded in the local cache within the preset time window is greater than a second threshold, intercept the N first order requests.

[0123] The order anti-duplication device provided by the embodiments of the present disclosure can implement each process in the order anti-duplication method embodiments as shown in Figure 1 or Figure 3 Therefore, details are not repeated here.

[0124] According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium.

[0125] Figure 5 A schematic block diagram of an example electronic device 400 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular telephones, smartphones, wearable devices, and other similar computing devices. The components shown here, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present disclosure described and / or claimed in this document.

[0126] As shown in Figure 5 The device 400 includes a computing unit 401 that can perform various appropriate actions and processes according to a computer program stored in a Read-Only Memory (ROM) 402 or a computer program loaded into a Random Access Memory (RAM) 403 from a storage unit 408. Various programs and data required for the operation of the device 400 can also be stored in the RAM 403. The computing unit 401, the ROM 402, and the RAM 403 are connected to each other through a bus 404. An Input / Output (I / O) interface 405 is also connected to the bus 404.

[0127] Various components in the device 400 are connected to the I / O interface 405, including an input unit 406, such as a keyboard, a mouse, etc.; an output unit 407, such as various types of displays, speakers, etc.; the storage unit 408, such as a magnetic disk, an optical disk, etc.; and a communication unit 409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 409 allows the device 400 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.

[0128] The computing unit 401 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a Central Processing Unit (CPU), a Graphic Process Unit (GPU), various special-purpose Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processing (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 401 performs various methods and processes described above, such as the order anti-duplication method. For example, in some embodiments, the order anti-duplication method can be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as the storage unit 408. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device 400 via the ROM 402 and / or the communication unit 409. When the computer program is loaded onto the RAM 403 and executed by the computing unit 401, one or more steps of the order anti-duplication method described above can be performed. Alternatively, in other embodiments, the computing unit 401 can be configured to perform the order anti-duplication method by other any appropriate means, such as by means of firmware.

[0129] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a Field-Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a System on Chip (SOC), a Complex Programmable Logic Device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0130] Program code for carrying out operations of the methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces the functions / operations specified in the flowcharts and / or block diagrams. The program code can be executed entirely on a machine, partially on a machine, partially on a machine as part of a standalone software package, or entirely on a remote machine or server.

[0131] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable storage media can include, without limitation, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media can include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0132] As used herein, the term "machine-readable medium" means any computer program product, apparatus and / or device (e.g., magnetic discs, optical disks, memory, Programmable Logic Devices (PLDs)) used to provide machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" means any signal that can be used to provide machine instructions and / or data to a programmable processor.

[0133] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0134] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.

[0135] The computer system can include clients and servers. This relationship can be. The servers are typically remote from the clients with the interactions typically taking place over a communication network. The relationship between a client and a server is one of client-server relationship. The server can be a cloud server, a server of a distributed system, or a server incorporating blockchain.

[0136] The embodiments of the present application also provide a computer program product, comprising computer instructions, which, when executed by a processor, implement the various processes of the above-described method embodiments and can achieve the same technical effects. To avoid repetition, they will not be described here. Figure 1 Or Figure 3 The various processes of the method embodiments shown above can be reordered, added, or deleted. For example, the steps described in the present disclosure can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions of the present disclosure can be achieved. This is not limited herein.

[0137] It should be understood that various forms of the flow shown above can be reordered, added, or deleted. For example, the steps described in the present disclosure can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions of the present disclosure can be achieved. This is not limited herein.

[0138] The above detailed description does not constitute a limitation on the scope of protection of the present disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present disclosure should be included within the scope of protection of the present disclosure.

Claims

1. An order duplicate prevention method characterized by comprising: The method comprises the following steps: performing a first duplicate check operation on N first order requests to determine whether the N first order requests have duplicate order requests in a local cache, N being an integer greater than 1; in the case where the N first order requests do not have duplicate orders in the local cache, writing the N first order requests into a distributed cache layer and performing a second duplicate check operation on the N first order requests to perform corresponding business operations on the order requests that do not have duplicates; the second duplicate check operation on the N first order requests to perform corresponding business operations on the order requests that do not have duplicates comprises the following steps: obtaining M second order requests from the N first order requests, the creation time of the M second order requests being within a preset time window, M being an integer greater than 1; in the case where M is less than or equal to a first threshold, performing corresponding business operations on the order requests that do not have duplicates; wherein the M second order requests include the order requests that do not have duplicates; in the case where the number of the M second order requests is less than or equal to the first threshold, writing the M second order requests into a database; performing a third duplicate check operation on the M second order requests to determine whether the second identifier of each second order request is unique to determine at least one target order request; wherein the target order request is one of the M second order requests; performing corresponding business operations on the target order request. the first duplicate check operation on the N first order requests to determine whether the first order requests have duplicate order requests in the local cache comprises the following steps:

2. The method of claim 1, wherein, based on the first identifier corresponding to each first order request, querying whether there is a duplicate order request in the local cache to determine whether the first order requests have duplicate order requests in the local cache; wherein each first order request corresponds to a first identifier. the third duplicate check operation on the M second order requests to determine whether the second identifier of each second order request is unique to determine at least one target order request comprises the following steps:

3. The method of claim 2, wherein, determining at least one third order request from the M second order requests according to the second identifier corresponding to each second order request, the third order request being the second order request that has only a unique second identifier; sorting each third order request according to a preset time rule to determine that the third order request arranged in a preset position is the target order request. The method further comprises the following steps:

4. The method of claim 1, wherein, in the case where the number of the N first order requests recorded in the local cache within a preset time window is greater than a second threshold, intercepting the N first order requests. The method comprises the following steps:

5. An order duplication prevention apparatus, characterized by comprising: ​ The first operation module is configured to perform a first duplicate check operation on N first order requests to determine whether the N first order requests have duplicate order requests in a local cache, N being an integer greater than 1. The second operation module is configured to write the N first order requests to a distributed cache layer and perform a second duplicate check operation on the N first order requests to perform corresponding business operations on the order requests without duplicates in a case where the N first order requests do not have duplicate orders in the local cache. The second operation module is further configured to: obtain M second order requests from the N first order requests, the M second order requests being created within a preset time window, M being an integer greater than 1; perform corresponding business operations on the order requests without duplicates in a case where the M is less than or equal to a first threshold value, the M second order requests including the order requests without duplicates; The second operation module is further configured to: write the M second order requests to a database in a case where the number of the M second order requests is less than or equal to the first threshold value; perform a third duplicate check operation on the M second order requests to determine whether a second identifier of each of the second order requests is unique, and determine at least one target order request, the target order request being one of the M second order requests; perform corresponding business operations on the target order request.

6. An electronic device, comprising: A computer program is stored on the computer readable storage medium and is executed by the processor to implement the steps of the order duplicate prevention method according to any one of claims 1 to 4.

7. A computer readable storage medium characterized by A computer program is stored on the computer readable storage medium and is executed by the processor to implement the steps of the order duplicate prevention method according to any one of claims 1 to 4.

8. A computer program product, characterised in that, A computer program is stored on the computer readable storage medium and is executed by the processor to implement the steps of the order duplicate prevention method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • High-concurrency payment order anti-duplication method, device, system and equipment, medium and program product

    CN115374098A