Data stream execution method and device, electronic equipment and storage medium
By binding a policy identifier to each API data stream under the HTTP/2 protocol, and processing each API data stream independently, the problem of mutual interference between business requests within an HTTP connection is solved, thereby improving the stability and transmission efficiency of the distributed system.
Patent Information
- Application Number
- CN202611281099.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-21
- Publication Date
- 2026-11-24
AI Technical Summary
Existing API governance solutions cannot effectively distinguish between multiple concurrent API data streams under the HTTP/2 protocol, causing different business requests within the same HTTP connection to interfere with each other and reducing the operational stability of distributed systems.
By intercepting target API data streams, parsing interface paths and client identities, binding unique policy identifiers, and executing independent policy processing based on policy identifiers, traffic governance granularity is refined to the API data stream level, and each API data stream is processed independently.
It improves the operational stability of distributed systems, avoids mutual interference between business requests within a single HTTP connection, reduces system resource consumption, and improves transmission efficiency and stability.
Smart Images

Figure CN123164148A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data communication technology, and in particular to a data stream execution method, apparatus, electronic device and storage medium. Background Technology
[0002] With the widespread adoption of microservice architecture and cloud-native technologies, APIs (Application Programming Interfaces) have become the core carrier for communication between services. HTTP / 2, with its advantages such as multiplexing and header compression, is gradually replacing HTTP / 1.1 and becoming the mainstream communication protocol in microservice scenarios.
[0003] Current API governance solutions are all based on the HTTP / 1.1 communication model, offering relatively coarse-grained control, typically using client IP addresses or HTTP connections as the unified governance unit. However, the HTTP / 2 protocol allows multiple independent API data streams to be transmitted concurrently within a single HTTP connection. If the HTTP connection-based governance approach continues, any rate limiting or circuit breaker operation on an HTTP connection will restrict all API data streams within that connection. For example, if a payment interface malfunctions and triggers a circuit breaker, normal, unrelated interfaces such as user queries and product listings on the same connection will also be blocked, thus reducing the overall stability of the distributed system. Summary of the Invention
[0004] This application provides a data stream execution method, apparatus, electronic device, and storage medium to solve the problem of low operational stability in distributed systems.
[0005] In a first aspect, this application provides a data stream execution method, the method comprising: The target API data stream is intercepted. Each client and the gateway are configured with a single HTTP communication connection, and each single HTTP communication connection carries multiple independent API data streams. Parse the interface path and client identity corresponding to the target API data stream; Match a policy identifier based on the interface path and the client identity, and bind the policy identifier to the target API data stream, wherein the same policy identifier is bound to multiple API data streams; The target API data stream is processed according to the policy identifier.
[0006] Optionally, performing corresponding policy processing on the target API data stream based on the policy identifier includes: Determine the interface path that matches the policy identifier; Select the target upstream service instance that will receive the target API data flow from all upstream service instances deployed under the interface path; Based on the historical request failure rate of the target upstream service instance, determine the circuit breaker status corresponding to the target upstream service instance; If the fuse is in the open state, then the target API data stream will be blocked.
[0007] Optionally, after determining that the fuse is in the open state, the method further includes: After intercepting a new API data stream, determine the first upstream service instance to accept the new API data stream; If the first upstream service instance is the same as the target upstream service instance, then the new API data stream will be blocked.
[0008] Optionally, performing corresponding policy processing on the target API data stream based on the policy identifier includes: Determine the interface path that matches the policy identifier; Based on the historical request failure rate of the interface path, determine the circuit breaker status corresponding to the interface path; If the fuse is in the open state, then the target API data stream will be blocked.
[0009] Optionally, after determining that the fuse is in the open state, the method further includes: After intercepting a new API data stream, the interface path corresponding to the new API data stream is determined based on the policy identifier bound to the new API data stream. If the interface path corresponding to the new API data stream is the same as the interface path corresponding to the target API data stream, then the new API data stream will be blocked.
[0010] Optionally, performing corresponding policy processing on the target API data stream based on the policy identifier includes: Retrieve the token bucket associated with the policy identifier and determine the number of target tokens required for the target API data stream, wherein the token is used to indicate the access permission for the interface call; If the number of remaining tokens in the token bucket is greater than or equal to the target number of tokens, then the target number of tokens is deducted from the token bucket, and the target API data stream is forwarded to the upstream service instance. If the number of remaining tokens in the token bucket is less than the target number of tokens, then the target API data flow is blocked.
[0011] Optionally, performing corresponding policy processing on the target API data stream based on the policy identifier includes: Generate audit logs for the target API data stream; Based on the audit logs, billing operations are performed on the target API data stream according to the pre-designed fee model of the interface path.
[0012] Secondly, this application provides a data stream execution apparatus, the apparatus comprising: The interception module is used to intercept the transmitted target API data stream. Each client is configured with a single HTTP communication connection with the gateway, and the single HTTP communication connection carries multiple independent API data streams. The parsing module is used to parse the interface path and client identity corresponding to the target API data stream; A binding module is used to match a policy identifier based on the interface path and the client identity, and bind the policy identifier to the target API data stream, wherein the same policy identifier is bound to multiple API data streams; The processing module is used to perform corresponding policy processing on the target API data stream according to the policy identifier.
[0013] Thirdly, this application provides an electronic device, comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus.
[0014] Fourthly, this application also provides a computer storage medium storing computer-executable instructions for executing the data stream execution method described in any of the preceding claims of this application.
[0015] The technical solutions provided in this application have the following advantages compared with the prior art: This application intercepts the target API data stream transmitted by the client, parses the interface path and client identity corresponding to the target API data stream, and then binds a unique policy identifier to the target API data stream based on the parsed interface path and client identity. Each policy identifier matches a processing policy, and the policy processing is executed on the target API data stream according to the policy identifier. Within the same HTTP communication connection, the policy identifier generated by combining the interface path and client identity will bind to multiple API data streams and match independent processing policies. This application uses policy identifiers to refine the smallest control granularity of traffic governance from the HTTP connection to the API data stream granularity. When an API data stream becomes abnormal, API data streams bound to other policy identifiers within the same HTTP connection will not be interfered with, solving the defect of mutual interference between different business requests in a single HTTP connection multi-stream concurrent scenario, and improving the overall operational stability of the distributed system. Attached Figure Description
[0016] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0017] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0019] Figure 1 A schematic diagram of the hardware environment for data stream execution provided in the embodiments of this application; Figure 2 A flowchart of a data stream execution method provided in an embodiment of this application; Figure 3 This application provides a schematic diagram of the overall process of data stream execution in an embodiment of the present application. Figure 4 This is a schematic diagram of the structure of a data stream execution device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0021] The following disclosure provides numerous different embodiments or examples for implementing various structures of this application. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of this application. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.
[0022] The embodiments of this application are applicable to a microservice architecture consisting of multiple clients and gateways.
[0023] Optionally, in the embodiments of this application, the above-described data stream execution method can be applied to, for example... Figure 1 The hardware environment shown consists of client 101, gateway 103, and upstream service cluster 105. For example... Figure 1 As shown, gateway 103 establishes an HTTP communication connection with client 101. Gateway 103 is deployed in the traffic link between client 101 and upstream service cluster 105. It is used to intercept, verify, and process the target API data stream initiated by client 101, and forward the processed valid API data stream to the corresponding upstream service cluster 105. The upstream service cluster 105 includes multiple upstream service instances. Client 101 includes, but is not limited to, terminal devices, business servers, and other business entities capable of initiating API call requests.
[0024] The following will describe in detail a data stream execution method provided in this application embodiment, taking its application to a gateway as an example, with specific implementation details. Figure 2 As shown, the specific steps are as follows: Step 201: Intercept the transmitted target API data stream, wherein each client and the gateway are configured with a single HTTP communication connection, and the single HTTP communication connection carries multiple independent API data streams; Step 202: Parse the interface path and client identity corresponding to the target API data stream; Step 203: Match the policy identifier based on the interface path and client identity, and bind the policy identifier to the target API data stream. The same policy identifier can be bound to multiple API data streams. Step 204: Perform the corresponding policy processing on the target API data stream according to the policy identifier.
[0025] In step 201, the gateway establishes a dedicated HTTP communication connection with each client. The client completes the construction of the communication link with the gateway through the connection management process and the TLS (Transport Layer Security) handshake process. Each HTTP communication connection can carry multiple independent API data streams that do not interfere with each other.
[0026] The client is a business entity that can proactively initiate business interface call requests. Clients include, but are not limited to, mini-programs, terminal apps, or front-end web pages. Each time a user triggers a business operation within the client, an independent API data stream is generated. A single API data stream corresponds to only one interface path. The interface path identifies the business function interface that the current request needs to call, such as the access path for functions like creating an order, payment settlement, or product information query. Each business operation initiated within the client can generate an API data stream, and multiple API data streams generated by the client can reuse the same HTTP communication connection for concurrent transmission.
[0027] The upstream service cluster is a collection of backend nodes that deploy various business interface programs. It is an entity that receives and processes API data stream requests. The gateway is deployed in the traffic transmission link between the client and the upstream service cluster. The gateway has the basic ability to forward the API data stream that has completed governance and verification to the upstream service cluster.
[0028] In this embodiment of the application, the gateway continuously captures all uplink traffic in the transmission link and intercepts target API data streams waiting to be forwarded to the upstream service cluster in real time. The target API data stream is any of the above-mentioned API data streams.
[0029] In step 202, after the gateway completes the interception operation of the target API data stream, it fully reads the header data frame HEADERS that comes with the target API data stream. The header data frame carries all the basic identification information corresponding to this request, including the path pseudo-header field and the Authorization field. The path pseudo-header field is used to store the interface path corresponding to this request, and the Authorization field carries the identity credentials that can uniquely identify the request initiator.
[0030] The gateway identifies the interface path corresponding to the target API data stream and the identity of the client that initiated the request by reading the field values of the two types of fields.
[0031] In step 203, the gateway pre-stores mapping configuration information between interface paths, client identities, and policy identifiers (PolicyIDs). The gateway uses the parsed interface path and client identity as joint search conditions to query the locally stored mapping configuration information, obtains the unique corresponding policy identifier, and binds this policy identifier to the target API data stream, giving the target API data stream an independent and exclusive control identifier.
[0032] Furthermore, since the policy identifier is generated by combining the client identity and the interface path, as long as the API data flow comes from the same client and accesses the same interface path, no matter how many independent API data flows there are, they will be bound to the same policy identifier. In other words, the same policy identifier is bound to multiple API data flows.
[0033] For example, when a mini-program client calls the order creation interface, 100 users within the mini-program perform concurrent operations, generating 100 independent API data streams. These 100 data streams have the same client identity and interface path, and all match the same policy identifier, meaning that the policy identifier is simultaneously bound to 100 API data streams.
[0034] In step 204, the gateway retrieves the policy matched by the policy identifier bound to the target API data stream and performs policy processing on the target API data stream according to the policy. Policy processing includes, but is not limited to, circuit breaker status determination, token quantity verification, audit log generation, or billing statistics. The policy processing executed by the gateway only applies to this target API data stream and will not interfere with other API data streams corresponding to policy identifiers within the same HTTP communication connection.
[0035] Traditional traffic governance mechanisms use the entire HTTP connection as the smallest governance unit. Once any API data stream within the connection triggers a rate-limiting threshold or a circuit breaker condition, the gateway indiscriminately blocks all concurrent data streams transmitted under that HTTP connection, and normal business requests are forcibly blocked due to unrelated interface anomalies. This application, however, refines the governance unit from the HTTP connection level to the independent API stream level using policy identifiers. This enables independent and differentiated management of multiple business requests within a single HTTP connection. If an API data stream triggers a circuit breaker condition or a traffic over-limit condition, the gateway only blocks the API data stream with the anomaly. Within the same HTTP connection, API data streams bound to other policy identifiers can still complete their processing and be forwarded to the upstream service cluster. This avoids a single interface anomaly affecting all business requests within the HTTP connection, reduces mutual interference caused by multiple API data streams sharing a single HTTP connection, and improves the system's operational stability in microservice distributed communication scenarios.
[0036] This application intercepts the target API data stream transmitted by the client, parses the interface path and client identity corresponding to the target API data stream, and then binds a unique policy identifier to the target API data stream based on the parsed interface path and client identity. Each policy identifier matches a processing policy, and the policy processing is executed on the target API data stream according to the policy identifier. Within the same HTTP communication connection, the policy identifier generated by combining the interface path and client identity will bind to multiple API data streams and match independent processing policies. This application uses policy identifiers to refine the smallest control granularity of traffic governance from the HTTP connection to the API data stream granularity. When an API data stream becomes abnormal, API data streams bound to other policy identifiers within the same HTTP connection will not be interfered with, solving the defect of mutual interference between different business requests in a single HTTP connection multi-stream concurrent scenario, and improving the overall operational stability of the distributed system.
[0037] Furthermore, in this application, each client's API business communication request can be transmitted using a single HTTP / 2 communication connection. This method fully leverages the multiplexing capabilities inherent in the HTTP / 2 protocol, effectively avoiding the problems of excessive HTTP connections and high resource consumption in traditional multi-connection communication modes. It significantly reduces system resource consumption for both the client and the gateway, while also reducing the operational overhead associated with extensive connection maintenance and management. Simultaneously, by utilizing the transmission advantages of single-connection multiplexing, it eliminates the time-consuming overhead of frequently creating and destroying connections, effectively reducing data communication latency and improving the overall transmission efficiency of the API data stream.
[0038] As an optional implementation, the processing strategies corresponding to the policy identifiers include three categories: circuit breaker verification, rate limiting verification, and billing log processing. Circuit breaker verification and rate limiting verification are executed sequentially; circuit breaker verification must be completed first, and rate limiting verification can only be executed after the verification passes. This application sets the circuit breaker status judgment as a pre-sequential step of rate limiting verification. When the interface path fails, the API data stream can be directly intercepted, eliminating unnecessary rate limiting calculations and reducing gateway computing power consumption. Billing log processing is performed synchronously and in parallel with the serial verification link formed by circuit breaker verification and rate limiting verification. The start timing of billing log processing is not constrained by the execution results of circuit breaker verification and rate limiting verification; billing log processing is fully executed regardless of whether the target API data stream is ultimately blocked or allowed.
[0039] Circuit breaking verification uses a policy identifier as an independent control unit, and can be implemented at the interface path granularity or the upstream service instance granularity. There are two implementation methods for performing circuit breaking verification on the target API data stream based on the policy identifier, which are explained below.
[0040] In one embodiment, the interface path matching the policy identifier is determined; the circuit breaker state corresponding to the interface path is determined based on the historical request failure rate of the interface path; if the circuit breaker state is open, the target API data stream is blocked.
[0041] The gateway reads the policy identifier bound to the target API data stream and uses the interface path matching the policy identifier as the interface path of the target API data stream. In this embodiment, the entire interface path is used as the statistical unit for circuit breaker control. The gateway uses a sliding time window mechanism to count the sum of the request failure rates of all upstream service instances under the interface path, which is used as the historical request failure rate of the interface path. The duration of the sliding time window can be customized by the business, such as being configured for different statistical periods such as the past hour, the past two minutes, or the past twenty-four hours.
[0042] The gateway has two preset failure rate thresholds. By comparing the failure rate over a preset historical period with the two thresholds, the status of the circuit breaker is distinguished, thereby completing circuit breaker control at the interface level.
[0043] When the failure rate of this interface path is lower than the first failure rate threshold, it indicates that the number of abnormal interface requests is extremely small, the overall operation is stable, and there are no persistent failures. At this time, the circuit breaker is in the closed state. The gateway does not intercept any requests to this interface and performs subsequent rate limiting verification on the API data stream under this interface path normally.
[0044] When the historical request failure rate of this interface path is greater than or equal to the first failure rate threshold and less than or equal to the second failure rate threshold, it indicates that the interface has begun to experience some abnormal requests, and the service status is not stable enough. At this time, the circuit breaker switches to a half-open state. The gateway will allow a small amount of API data flow to this interface to test whether the interface service has returned to normal, while continuing to monitor changes in the historical request failure rate.
[0045] When the historical request failure rate of a given interface path exceeds the second failure rate threshold, it indicates frequent overall failures on that interface path, with a large number of requests failing to respond normally, and the service in an abnormal and unavailable state. At this point, the circuit breaker is switched to the active state. During the circuit breaker's active period, the gateway immediately blocks the currently processing target API data stream and simultaneously sends an exception message to the client, such as sending a reset command RST_STREAM or a 50XX error. Furthermore, the gateway directly rejects all subsequent new API data streams destined for that interface path. API data streams corresponding to other normal interface paths within the system remain unaffected and continue to be processed and forwarded according to normal procedures.
[0046] This application employs a circuit breaker approach for the entire interface path, only counting global historical requests for a single interface path. The overall judgment logic is simple, the gateway's computational load is low, and the fault response speed is fast. By classifying the circuit breaker's different states based on historical request failure rates, it is possible to clearly distinguish between scenarios of minor interface anomalies and severe failures. When a large-scale failure occurs on an interface path, the target API data flow can be quickly blocked, preventing continuous abnormal requests from impacting backend services and effectively preventing further spread of the fault. Furthermore, the circuit breaker only applies to API data flow under the failed interface path, avoiding the accidental blocking of business traffic from other normal interface paths, effectively ensuring the overall operational stability of the entire system.
[0047] After determining that the circuit breaker is in the open state, the method further includes: after intercepting the new API data stream, determining the interface path corresponding to the new API data stream based on the policy identifier bound to the new API data stream; if the interface path corresponding to the new API data stream is the same as the interface path corresponding to the target API data stream, then blocking the new API data stream.
[0048] After determining that the circuit breaker corresponding to the interface path is in the open state, the gateway will continuously capture all uplink traffic in the transmission link in real time and continuously intercept every new API data stream subsequently initiated by the client.
[0049] For each new API data stream intercepted, the gateway first parses the interface path and client identity of the new API data stream, and obtains the policy identifier bound to the new API data stream by matching. Then, it uses the policy identifier to perform a reverse lookup to determine the interface path corresponding to the new API data stream.
[0050] The gateway then performs a consistency comparison between the interface path corresponding to the new API data flow and the interface path corresponding to the target API data flow that previously triggered the circuit breaker. If the two interface paths are exactly the same, it means that the new API data flow also needs to be distributed to the faulty interface path, and the gateway directly blocks the new API data flow. If the two interface paths are different, it means that the new API data flow accesses other business interfaces and is not related to the faulty interface path. The gateway continues to determine the circuit breaker status of the interface path corresponding to the new API data flow, thereby deciding whether to block or allow the new API data flow.
[0051] This application, after the circuit breaker is activated, pre-verifies the interface path to which all subsequently newly connected API data streams belong, blocking only new API requests that match the faulty interface path. This proactively intercepts invalid traffic, reduces unnecessary gateway computations, and API data streams redirected to other interface paths are not subject to any interception restrictions. Based on a fine-grained control method using policy identifiers, this application precisely limits traffic to the faulty interface, preventing the fault from spreading further, while fully preserving access capabilities to other business interfaces, effectively improving the overall operational stability of the distributed system.
[0052] In another embodiment, the interface path matching the policy identifier is determined; from all upstream service instances deployed under the interface path, the target upstream service instance that will receive the target API data flow is selected; based on the historical request failure rate of the target upstream service instance, the circuit breaker status corresponding to the target upstream service instance is determined; if the circuit breaker status is open, the target API data flow is blocked.
[0053] This embodiment differs from the overall interface circuit breaker method described above. It adopts more refined control logic. Specifically, the gateway reads the policy identifier bound to the target API data stream, parses the interface path corresponding to the policy identifier, and then determines the target upstream service instance to undertake this target API data stream in combination with the load balancing rules.
[0054] The load balancing rule refers to evenly distributing a large amount of API data streams accessing the same interface path to different upstream service instances, avoiding excessive traffic load on a single upstream service instance. Multiple upstream service instances are typically deployed to handle requests along the same interface path. This embodiment of the application no longer calculates the overall failure rate of the interface, but instead uses a single upstream service instance as the statistical unit, separately calculating the request failure status of each upstream service instance and determining the circuit breaker status of each upstream service instance independently. The circuit breaker status of each upstream service instance is independent and does not affect each other.
[0055] This embodiment also sets two levels of failure rate thresholds to distinguish between the three circuit breaker states, and performs a state determination process for a single upstream service instance. When the historical request failure rate corresponding to a single upstream service instance is lower than the third failure rate threshold, it means that the upstream service instance is running normally, the number of abnormal requests generated is extremely small, there is no persistent failure, and the circuit breaker corresponding to the upstream service instance remains closed. The gateway can normally forward the target API data stream to the upstream service instance and perform subsequent rate limiting verification operations on the target API data stream.
[0056] When the historical request failure rate of a single upstream service instance is greater than or equal to the third failure rate threshold and less than or equal to the fourth failure rate threshold, it indicates that the upstream service instance has generated a certain number of abnormal requests and its operational status is fluctuating. The circuit breaker corresponding to the upstream service instance switches to a half-open state. The gateway will allow a small amount of target API data flow to be sent to the upstream service instance to detect whether the upstream service instance has restored its normal service capabilities.
[0057] When the historical request failure rate of a single upstream service instance exceeds the fourth failure rate threshold, it indicates a severe failure of that upstream service instance, rendering it unable to process business requests normally. Only the circuit breaker for the failed upstream service instance will be switched to the active state; other normally functioning upstream service instances will remain unaffected. Once the circuit breaker is active, the gateway will immediately block the target API data flow currently destined for the failed upstream service instance and report the failure to the requesting client. Simultaneously, it will directly reject all subsequent new API data flows destined for the failed upstream service instance. This embodiment only intercepts traffic flowing to the failed upstream service instance; other normally functioning upstream service instances under the same interface path are unaffected by this circuit breaker control, and API data flows destined for healthy upstream service instances will continue to execute according to the normal process.
[0058] This application employs an independent circuit breaker management approach for upstream service instances. Historical requests to each individual target upstream service instance are statistically analyzed separately, ensuring that the statistical data for each upstream service instance does not interfere with each other. By classifying the different states of the circuit breaker based on historical request failure rates, it is possible to clearly distinguish between scenarios involving minor anomalies and severe failures of upstream service instances. When a target upstream service instance experiences a widespread failure, the target API data flow accessing that instance can be quickly blocked, preventing continuous abnormal requests from impacting the failed service instance and effectively preventing further spread of the failure. Furthermore, the circuit breaker control only applies to the API data flow carried by the failed target upstream service instance, avoiding the accidental blocking of business traffic carried by other normal upstream service instances within the same interface path, effectively ensuring the overall operational stability of the entire interface path.
[0059] After determining that the circuit breaker is in the open state, the method further includes: after intercepting the new API data stream, determining the first upstream service instance that will accept the new API data stream; if the first upstream service instance is the same as the target upstream service instance, then blocking the new API data stream.
[0060] After determining that the circuit breaker corresponding to the upstream service instance of the target is in the open state, the gateway will continuously capture all uplink traffic in the transmission link in real time and continuously intercept every new API data stream subsequently initiated by the client.
[0061] For each new API data stream intercepted, the gateway first parses the client identity and interface path carried by the new API data stream, matches the corresponding policy identifier, and uses the policy identifier to query and determine the interface path corresponding to the new API data stream; then, based on the preset load balancing rules, it selects the first upstream service instance to take over the new API data stream from all upstream service instances under the interface path.
[0062] The gateway then compares the selected first upstream service instance with the target upstream service instance that triggered the circuit breaker. If the upstream service instances are identical, the new API data stream will be distributed to the faulty target upstream service instance, and the gateway will directly block the new API data stream. If the upstream service instances are different, the new API data stream will be distributed to other upstream service instances under the same interface path, and the gateway will then determine whether to block or allow the API data stream based on the circuit breaker status of the other upstream service instances.
[0063] This application, after the circuit breaker is activated, pre-matches all subsequent new API data flows to their assigned upstream service instances, blocking only new API requests assigned to the faulty upstream service instance, thus intercepting invalid traffic in advance and reducing unnecessary gateway computations. API data flows assigned to other upstream service instances are not subject to any blocking restrictions. This application implements fine-grained instance-level traffic control based on policy identifiers, accurately isolating traffic corresponding to faulty service instances, preventing the continued spread of the fault, while fully preserving the access capabilities of other healthy instances under the same interface path, effectively improving the overall operational stability of the distributed system.
[0064] The two embodiments described above have different impact ranges on the circuit breaking: The first embodiment uses the entire interface path as the circuit breaking unit. As long as the overall failure rate of the interface path exceeds the standard, all traffic on that interface path will be blocked. This allows for the rapid and complete cutoff of all traffic when the entire interface fails, quickly curbing the spread of the fault. The second embodiment uses a single upstream service instance as an independent circuit breaking unit. It only blocks traffic for the single instance that is faulty, while other normal upstream service instances under the same interface path can continue to work. This provides more precise control and prevents the situation where a local failure leads to the unavailability of the entire business, resulting in stronger business stability.
[0065] As an optional implementation, in step 204, performing billing log processing on the target API data stream according to the policy identifier includes: generating audit logs for the target API data stream; and performing billing operations on the target API data stream based on the audit logs and according to the pre-designed billing model of the interface path.
[0066] During the process of circuit breaker verification and token bucket rate limiting verification, the gateway simultaneously generates structured audit logs for this target API data stream. Regardless of whether the target API data stream is ultimately forwarded normally or directly blocked, the gateway will fully record the policy identifier, client identity, interface path, request initiation time, total amount of data transmitted in this request and response, and response status code returned by the upstream service for the target API data stream, and store all of the above information in the audit log.
[0067] After the audit logs are generated, the gateway reads the audit logs corresponding to the target API data stream, matches them with the pre-configured pre-designed billing model for that interface path, and performs billing operations on the target API data stream based on the access data stored in the audit logs. Different interface paths can be configured with different billing models, which include two mainstream statistical methods: billing based on the number of interface calls and billing based on the amount of data transmitted.
[0068] API data streams that have completed all policy validations and are free of anomalies will be forwarded by the gateway to the upstream service cluster for processing. After the upstream service generates response data, the gateway will send the response content back to the client that initiated the request via the original HTTP communication connection.
[0069] This application generates a complete, structured audit log independently for each API data stream. The logs retain comprehensive access information, and each log data is independently bound to a policy identifier, ensuring that access records for different API data streams within the same HTTP communication connection are not mixed up. On one hand, the audit logs allow for real-time monitoring of request access from each client and interface path, quickly identifying abnormal requests and completing business audit investigations. On the other hand, the billing system can leverage the complete access data within the logs to match the corresponding interface path's dedicated billing model for accurate billing, differentiating billing standards for different business interfaces, and achieving refined billing statistics based on both call count and transmission traffic. Simultaneously, the gateway retains log records for both successfully forwarded and failed API data streams, ensuring no data loss for any access behavior, fully meeting the data usage needs of multiple scenarios including business monitoring, security auditing, and traffic billing.
[0070] As an optional implementation, in step 204, performing rate limiting verification on the target API data stream based on the policy identifier includes: Retrieve the token bucket associated with the policy identifier and determine the number of target tokens required for the target API data stream, where the token is used to indicate the access permission for the interface call; If the number of remaining tokens in the token bucket is greater than or equal to the target number of tokens, then the target number of tokens is deducted from the token bucket, and the target API data stream is forwarded to the upstream service instance. If the number of remaining tokens in the token bucket is less than the target number of tokens, then the target API data flow will be blocked.
[0071] Each time a user triggers a business operation within the client, an independent API data stream is generated. The policy identifier is uniquely determined by the client's identity and the interface path. All API data streams from the same client accessing the same interface path match the same policy identifier and share the same token bucket. Each API data stream requires one token to be allowed. For example, if one hundred users simultaneously initiate an order creation operation in the mini-program, this belongs to the same client accessing the same interface path, resulting in one hundred independent API data streams, each consuming one token.
[0072] The gateway continuously adds tokens to the token bucket at a fixed rate, for example, 200 tokens per second.
[0073] The gateway reads the policy identifier bound to the target API data stream, retrieves the token bucket associated with the policy identifier, determines the number of remaining tokens in the token bucket, and determines the number of target tokens required to allow the target API data stream to pass. Then, it compares the number of remaining tokens with the number of target tokens required by the target API data stream.
[0074] If the remaining tokens in the token bucket are greater than or equal to the target token count, it means that the client has sufficient call quota to access the corresponding interface path. The gateway deducts the target token count from the token bucket and then forwards the target API data stream to the upstream service instance. For example, if a single user initiates a business request, generating a target API data stream, the target token count required is 1. If the token bucket currently has 20 remaining tokens, meeting the consumption condition, the gateway deducts 1 token, updating the remaining tokens in the bucket to 19, and forwards the API data stream normally.
[0075] If the number of remaining tokens in the token bucket is less than the target number of tokens, it means that the current client's call quota for accessing the corresponding interface path is insufficient, and the current batch business requests cannot be allowed. The gateway directly blocks the target API data flow and will not forward traffic to the upstream service instance.
[0076] This application assigns a dedicated token bucket to each client identity and interface path, with tokens continuously replenished at a uniform rate. Each API data stream generated by a single business operation consumes a separate token, achieving dual-dimensional isolation and rate limiting based on both the client and the interface path. Within the same HTTP communication connection, API data streams corresponding to different policy identifiers use their respective token buckets, with traffic quotas not competing for each other. This prevents a situation where exhausting the quota for one type of business request leads to the blocking of other normal business requests within the same HTTP connection. This approach can smoothly control the peak request volume of the interface per unit time, preventing upstream services from being overwhelmed by sudden surges in requests, while also achieving multi-business traffic isolation through single-stream granular control, improving the stability of concurrent access in distributed systems.
[0077] Figure 3 The overall flow diagram for the data flow execution provided in this application includes the following.
[0078] The gateway preloads all preset API governance policies. Each client establishes a unique HTTP / 2 communication connection with the gateway. After the link is built and the policies are preloaded, the gateway continuously receives HTTP / 2 data streams transmitted by the clients. Each independent data stream carries a HEADERS header data frame.
[0079] The gateway reads the HEADERS header data frame from the target API data stream, extracts the path pseudo-header field from the frame, identifies the interface path corresponding to the target API data stream, and parses the header authentication field to obtain the client identity. Then, it uses the parsed interface path and client identity as joint matching conditions to retrieve mapping configuration information and obtain a unique policy identifier.
[0080] After obtaining the policy identifier, the gateway initiates three types of policy processing: circuit breaker verification, rate limiting verification, and billing log processing. The execution relationship of the three types of policies is as follows: circuit breaker verification and rate limiting verification are executed sequentially. Billing log processing is carried out synchronously throughout the entire process of circuit breaker and rate limiting serial verification, and is not constrained by the order of the circuit breaker and rate limiting judgment results. Regardless of whether the data flow is ultimately allowed or blocked, audit logs will be generated synchronously.
[0081] Branch 1: Circuit break verification.
[0082] The gateway queries the corresponding circuit breaker status based on the policy identifier. If the circuit breaker is in the open state, it indicates that the upstream service has failed. The gateway blocks the target API data flow, returns service exception information to the client, and records the failure log of this access simultaneously. The process ends directly. If the circuit breaker is in the closed or half-open state, the circuit breaker verification passes, and the gateway enters the downstream serial rate limiting verification process.
[0083] Branch 2: Rate limiting verification.
[0084] The gateway retrieves the token bucket associated with the policy identifier and compares the remaining tokens in the token bucket with the target token count required by the target API data flow. If the remaining tokens are less than the target token count, it indicates that the call limit has been exhausted. The gateway blocks the target API data flow and returns a request exceeding the limit response to the client, simultaneously logging the failure and ending the process. If the remaining tokens are greater than or equal to the target token count, the rate limiting verification passes, the gateway deducts the corresponding target token count from the token bucket, and allows the target API data flow.
[0085] Branch 3: Billing Audit Log.
[0086] From the moment the gateway begins executing the entire set of governance logic corresponding to the policy identifier, it simultaneously and in parallel performs the audit log generation process, unaffected by circuit breaker or rate limiting decision branches. If the data flow is blocked due to circuit breaker or rate limiting verification failure, an audit log recording the abnormal information is generated and categorized as a failure log; if both circuit breaker and rate limiting verifications pass, the gateway deducts the token and forwards the target API data flow to the upstream service. After the upstream service completes its processing, the gateway receives the response data returned by the upstream and sends the response back to the client through the existing HTTP / 2 communication connection, simultaneously generating a success audit log recording the complete traffic and call information.
[0087] Regardless of whether the target API data stream ultimately fails to be intercepted or is successfully forwarded, the entire process of the target API data stream ends after logging is completed.
[0088] Based on the same technical concept, this application provides a data stream execution device, such as... Figure 4 As shown, the device includes: The interception module 401 is used to intercept the transmitted target API data stream. Each client is configured with a single HTTP communication connection with the gateway, and the single HTTP communication connection carries multiple independent API data streams. Parsing module 402 is used to parse the interface path and client identity corresponding to the target API data stream; Binding module 403 is used to match policy identifiers based on interface path and client identity, and bind policy identifiers to target API data streams, wherein the same policy identifier is bound to multiple API data streams; Processing module 404 is used to perform corresponding policy processing on the target API data stream according to the policy identifier.
[0089] Optionally, the processing module 404 is used for: Determine the interface path that matches the policy identifier; Select the target upstream service instance that will handle the target API data flow from all upstream service instances deployed under the interface path; Determine the circuit breaker status of the target upstream service instance based on its historical request failure rate. If the fuse is in the open state, then the target API data stream will be blocked.
[0090] Optionally, the device is also used for: After intercepting a new API data stream, determine the first upstream service instance to accept the new API data stream; If the first upstream service instance is the same as the target upstream service instance, the new API data stream will be blocked.
[0091] Optionally, the processing module 404 is used for: Determine the interface path that matches the policy identifier; Determine the circuit breaker status corresponding to the interface path based on the historical request failure rate of the interface path; If the fuse is in the open state, then the target API data stream will be blocked.
[0092] Optionally, the device is also used for: After intercepting a new API data stream, the interface path corresponding to the new API data stream is determined based on the policy identifier bound to the new API data stream. If the interface path corresponding to the new API data stream is the same as the interface path corresponding to the target API data stream, then the new API data stream will be blocked.
[0093] Optionally, the processing module 404 is used for: Retrieve the token bucket associated with the policy identifier and determine the number of target tokens required for the target API data stream, where the token is used to indicate the access permission for the interface call; If the number of remaining tokens in the token bucket is greater than or equal to the target number of tokens, then the target number of tokens is deducted from the token bucket, and the target API data stream is forwarded to the upstream service instance. If the number of remaining tokens in the token bucket is less than the target number of tokens, then the target API data flow will be blocked.
[0094] Optionally, the processing module 404 is used for: Generate audit logs for the target API data stream; Based on audit logs, billing operations are performed on the target API data stream according to the pre-designed fee model of the interface path.
[0095] like Figure 5As shown, this application provides an electronic device including a processor 501, a communication interface 502, a memory 503, and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0096] Memory 503 is used to store computer programs.
[0097] In one embodiment of this application, when the processor 501 executes the program stored in the memory 503, it implements the data stream execution method provided in any of the foregoing method embodiments.
[0098] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the data stream execution method provided in any of the foregoing method embodiments.
[0099] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0100] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general-purpose hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.
[0101] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “” used herein may also indicate the inclusion of the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated, unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.
[0102] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A data stream execution method, characterized in that, The method includes: The target API data stream is intercepted. Each client and the gateway are configured with a single HTTP communication connection, and each single HTTP communication connection carries multiple independent API data streams. Parse the interface path and client identity corresponding to the target API data stream; Match a policy identifier based on the interface path and the client identity, and bind the policy identifier to the target API data stream, wherein the same policy identifier is bound to multiple API data streams; The target API data stream is processed according to the policy identifier.
2. The method according to claim 1, characterized in that, Performing corresponding policy processing on the target API data stream based on the policy identifier includes: Determine the interface path that matches the policy identifier; Select the target upstream service instance that will receive the target API data flow from all upstream service instances deployed under the interface path; Based on the historical request failure rate of the target upstream service instance, determine the circuit breaker status corresponding to the target upstream service instance; If the fuse is in the open state, then the target API data stream will be blocked.
3. The method according to claim 2, characterized in that, After determining that the fuse is in the open state, the method further includes: After intercepting a new API data stream, determine the first upstream service instance to accept the new API data stream; If the first upstream service instance is the same as the target upstream service instance, then the new API data stream will be blocked.
4. The method according to claim 1, characterized in that, Performing corresponding policy processing on the target API data stream based on the policy identifier includes: Determine the interface path that matches the policy identifier; Based on the historical request failure rate of the interface path, determine the circuit breaker status corresponding to the interface path; If the fuse is in the open state, then the target API data stream will be blocked.
5. The method according to claim 4, characterized in that, After determining that the fuse is in the open state, the method further includes: After intercepting a new API data stream, the interface path corresponding to the new API data stream is determined based on the policy identifier bound to the new API data stream. If the interface path corresponding to the new API data stream is the same as the interface path corresponding to the target API data stream, then the new API data stream will be blocked.
6. The method according to claim 1, characterized in that, Performing corresponding policy processing on the target API data stream based on the policy identifier includes: Retrieve the token bucket associated with the policy identifier and determine the number of target tokens required for the target API data stream, wherein the token is used to indicate the access permission for the interface call; If the number of remaining tokens in the token bucket is greater than or equal to the target number of tokens, then the target number of tokens is deducted from the token bucket, and the target API data stream is forwarded to the upstream service instance. If the number of remaining tokens in the token bucket is less than the target number of tokens, then the target API data flow is blocked.
7. The method according to claim 1, characterized in that, Executing the corresponding policy processing on the target API data stream based on the policy identifier further includes: Generate audit logs for the target API data stream; Based on the audit logs, billing operations are performed on the target API data stream according to the pre-designed fee model of the interface path.
8. A data stream execution device, characterized in that, The device includes: The interception module is used to intercept the transmitted target API data stream. Each client is configured with a single HTTP communication connection with the gateway, and the single HTTP communication connection carries multiple independent API data streams. The parsing module is used to parse the interface path and client identity corresponding to the target API data stream; A binding module is used to match a policy identifier based on the interface path and the client identity, and bind the policy identifier to the target API data stream, wherein the same policy identifier is bound to multiple API data streams; The processing module is used to perform corresponding policy processing on the target API data stream according to the policy identifier.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.
