Flow control and session sharing system and method, and electronic equipment

By using Redis's ZSet and Spring Session, distributed rate limiting and session sharing are uniformly implemented in a distributed architecture, solving the problems of distributed rate limiting and session sharing, and realizing a high-concurrency, highly available Internet service system with simple configuration and low invasiveness.

CN122093379APending Publication Date: 2026-05-26CHINA ASSET MANAGEMENT CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA ASSET MANAGEMENT CO LTD
Filing Date
2026-01-20
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

In a distributed architecture, existing technologies struggle to simultaneously address the issues of distributed rate limiting and session sharing, making it difficult to achieve security risk control and session consistency, and also resulting in high intrusion into business code.

Method used

By using Redis's sorted sets (ZSet) and Spring Session, traffic control and session sharing are unified within the same technology stack. Redis is used as a remote dictionary service to achieve distributed rate limiting and session sharing, and a configuration center module is used for real-time parameter push and dynamic adjustment.

Benefits of technology

It implements a unified solution for distributed rate limiting and session sharing in high-concurrency, high-availability Internet service systems. It is simple to implement, flexible to configure, non-intrusive to business code, and supports dynamic scaling and high availability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122093379A_ABST
    Figure CN122093379A_ABST
Patent Text Reader

Abstract

The invention discloses a flow control and session sharing system and method and electronic equipment. The system comprises a flow control module, a session sharing module and a configuration center module, the flow control module and the session sharing module share the same Redis instance or Redis cluster; the traffic control module stores access records by using an ordered set in Redis, and controls the query time and the threshold value of the number of requests; and the session sharing module adopts a Spring session framework and takes Redis as external session storage, and any node acquires / updates the session through the Redis. Through an ordered set of Redis and a Spring session framework, 'distributed flow limiting 'and'session sharing' are unified in the same technology stack, and performance, expandability and usability are considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of distributed web service technology, and more specifically, to a distributed architecture traffic control and session sharing system and method, and electronic device based on caching technology. Background Technology

[0002] With the rapid growth of internet traffic, single-node web (wide area network) servers can no longer meet the demands of high concurrency and high availability. Enterprises commonly adopt backend cluster deployments to improve system throughput and stability. However, at least two problems urgently need to be addressed in distributed architectures: 1. Security and risk control: To prevent abuse such as "email bombing", it is necessary to limit the number of business transactions of a single customer (or IP, account) within a unit of time. 2. Session consistency: The HTTP protocol is stateless. When the load balancer distributes continuous requests from the same user to different nodes, the session data may show the phenomenon of "this node is available, that node is not available", which may force users to log in again or cause business interruption. Existing technologies typically address these two issues separately: 1. Traffic control often relies on local memory counters or independent gateways for rate limiting. The former cannot share state across nodes, while the latter requires additional deployment and is costly. 2. Session sharing relies on container-level replication, sticky sessions, or centralized caching. Replication incurs high synchronization overhead when network latency is high; sticky sessions contradict the purpose of load balancing; and traditional centralized caching (such as Memcached) only provides a key-value structure and cannot accurately count the number of requests by time window.

[0003] For example, Chinese patent document (application number: 202110525354.8, application date: 2021.05.12) provides a high-performance distributed session solution, including: ① Transparent replacement of the web container's HTTP session by Spring-Session; Spring Session is a sub-project of the Spring family, providing APIs and implementations for managing user session information. It replaces the Http Session implemented by the Servlet container with Spring-Session, focusing on solving session management problems. The core idea of ​​Spring-Session is to decouple the session from the web container and store it on an independent storage server. Currently, it supports various forms of session storage: Redis, Database, MongoDB, etc. The responsibility for session management is delegated to Spring-Session.

[0004] When a request enters the web container and the Session is retrieved based on the request, Spring-Session is responsible for retrieving the Session from storage. If it exists, it is returned; otherwise, it is created and persisted to storage. This solution uses Redis for centralized Session storage, but it does not simultaneously address the issue of "distributed rate limiting."

[0005] Therefore, how to simultaneously solve the problems of "distributed rate limiting" and "session sharing" is a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0006] In view of this, the present invention provides a distributed architecture traffic control and session sharing system and method based on caching technology. By utilizing the ordered set (ZSet) of a remote dictionary service (Redis) and SpringSession, it unifies "distributed rate limiting" and "session sharing" within the same technology stack, balancing performance, scalability, and ease of use. It can be widely applied to high-concurrency, high-availability internet service systems. This invention simultaneously solves the problems of "distributed rate limiting" and "session sharing," and features simple implementation, flexible configuration, and low intrusion into business code.

[0007] The first aspect of this application provides a distributed architecture traffic control and session sharing system based on caching technology, including: a traffic control module, a session sharing module, and a configuration center module; The configuration center module is coupled to the traffic control module and the session sharing module respectively. When the parameters change, the configuration center module pushes the changed parameters to the traffic control module and the session sharing module in real time. The parameters include time range threshold, set size threshold, and / or session timeout threshold. The flow control module and the session sharing module share the same remote dictionary service instance or remote dictionary service cluster. The flow control module uses an ordered set in the remote dictionary service to store access records and controls the time range and threshold of the number of requests for queries. The session sharing module adopts the Spring session framework and uses a remote dictionary service as an external session storage to generate globally unique session identifiers. Any node can obtain or update a session through the remote dictionary service.

[0008] Optionally, the configuration center module employs dynamic naming and configuration service components; The configuration center module provides a unified presentation layer state transformation interface for real-time modification of the parameters; After the configuration center module changes its parameters, each node in the distributed architecture detects this change and refreshes its local context through long polling or a message bus.

[0009] Optionally, the access record includes a unique identifier of the request and a timestamp of the request occurring; The unique identifier of the request includes at least one of the following: user identifier, Internet protocol, and interface name; The timestamp of the request is in milliseconds.

[0010] Optionally, the session sharing module includes a remote dictionary service hypertext transfer protocol session configuration unit, a session repository filtering unit, and a remote dictionary service operation session storage repository unit; The remote dictionary service hypertext transfer protocol session configuration unit is used to read the session timeout parameter of the configuration center module and complete the Spring container object assembly. The session repository filtering unit is a Servlet specification filter that intercepts Hypertext Transfer Protocol (HTTP) requests, wraps the HTTP request object into a session repository request wrapper, and wraps the HTTP response object into a session repository response wrapper, thereby taking over session management. The remote dictionary service operation session storage warehouse unit is used for adding, deleting, modifying, and querying sessions, and uses the remote dictionary service hash structure to store session attributes.

[0011] Optionally, the flow control module and the session sharing module sharing the same remote dictionary service instance or remote dictionary service cluster include: Flow control and session-shared storage are merged into the same remote dictionary service instance or remote dictionary service cluster, and data is isolated through namespaces.

[0012] A second aspect of this application provides a method for distributed architecture traffic control and session sharing based on caching technology, comprising: After a user submits a business request, the request is distributed to a service node in the service cluster according to the preset load balancing strategy. After a service node receives the service request, the traffic control module and the session sharing module obtain parameters from the configuration center module. The traffic control module determines whether the limit has been exceeded based on the query time range and the threshold for the number of requests. If the limit is not exceeded, the service request is allowed; if the limit is exceeded, the service request is blocked. For the first access request, the session sharing module generates a globally unique session identifier. For subsequent user requests, it obtains or updates the session through the remote dictionary service and deletes the corresponding key from the remote dictionary service for invalid or canceled sessions. Each service node is aware of this in real time.

[0013] Optionally, the traffic control module determines whether the limit has been exceeded based on the time range of the query and the threshold of the number of requests. If the limit is not exceeded, the business request is executed; if the limit is exceeded, the business request is blocked, including: When a business request arrives, the member is written into an ordered set using the current timestamp as the fraction. Use the command to delete members of an ordered set by score range to delete members that expired earlier than "current time - time range threshold"; Use the command to get the number of members in an ordered set to get the current size of the set; If the size of the set is greater than or equal to the set size threshold, the business request is rejected and an error code is returned; otherwise, the business request continues to be executed.

[0014] Optionally, the session sharing module generates a globally unique session identifier for the first access request, and for subsequent user requests, retrieves or updates the session through a remote dictionary service. For expired or logged-out sessions, the corresponding key is deleted from the remote dictionary service. Each service node is aware of this in real time, including: When a browser visits the site for the first time, the service node generates a globally unique session identifier and returns it to the client via Set-Cookie; Subsequent requests carry this session identifier, and any node can obtain or update the session through the remote dictionary service; When a session expires or is logged out, the corresponding key is deleted from the remote dictionary service, and each node is aware of this in real time.

[0015] Optionally, the method further includes: When the system starts, the flow control module and the session sharing module actively pull time range threshold, set size threshold, and session timeout threshold from the dynamic naming and configuration service component. When the parameters change, the dynamic naming and configuration service component will push the changed parameters to the application node. The parameters include time range threshold, set size threshold, and / or session timeout threshold.

[0016] A third aspect of this application provides an electronic device comprising: Memory, used to store computer programs; A processor, used to execute the computer program, implements the steps of the method for distributed architecture flow control and session sharing based on caching technology as described above.

[0017] Compared with existing technologies, the distributed architecture flow control and session sharing system and method, and electronic device based on caching technology provided by this invention achieve at least the following beneficial effects: First, dual functions in one: the same remote dictionary service (Redis) simultaneously serves as both a "counter" and a "session storage", simplifying operation and maintenance and increasing resource utilization; Second, precise rate limiting: Based on the ordered set (ZSet) time window algorithm, it can be accurate to the millisecond level, avoiding the critical change problem of traditional fixed windows; Third, non-intrusive: It has zero intrusion into business code, and business developers do not need to be aware of rate limiting and session sharing logic; Fourth, dynamic scaling: parameters are hot-updated without requiring application restarts; the remote dictionary service (Redis) itself can be horizontally scaled, supporting large-scale clusters; Fifth, high availability: The remote dictionary service (Redis) supports master-slave + sentinel or cluster mode, and a single point of failure will not affect the overall service.

[0018] Of course, any product implementing this invention does not necessarily need to achieve all of the technical effects described above at the same time.

[0019] Other features and advantages of the invention will become clear from the following detailed description of exemplary embodiments of the invention with reference to the accompanying drawings. Attached Figure Description

[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments of the invention and, together with their description, serve to explain the principles of the invention.

[0021] Figure 1This is an overall framework diagram of a distributed architecture flow control and session sharing system based on caching technology according to the present invention; Figure 2 This is a flowchart of the flow control module in a distributed architecture flow control and session sharing system and method based on caching technology according to the present invention. Figure 3 This is a timing diagram of the session sharing module in a distributed architecture flow control and session sharing system and method based on caching technology according to the present invention. Figure 4 This is a flowchart of a distributed architecture flow control and session sharing method based on caching technology according to the present invention. Detailed Implementation

[0022] Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps set forth in these embodiments do not limit the scope of the invention.

[0023] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.

[0024] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.

[0025] In all the examples shown and discussed herein, any specific values ​​should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.

[0026] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.

[0027] To facilitate understanding, the terms or nouns used in the embodiments of this invention will be introduced again first.

[0028] Redis: An open-source, high-performance key-value database that supports various data structures and is commonly used in caching, message queues, and other scenarios to improve system performance and scalability; ZSet: A sorted set, it's a data structure in Redis. It's similar to a set, but each element is associated with a score used to sort the elements. Spring Session is an open-source framework in the Spring ecosystem for managing user session information. It primarily solves the problem of "cross-node session failure" in traditional server in-memory sessions during cluster / distributed deployments, and it does not depend on any specific application container. Nacos: A dynamic service discovery, configuration management, and service management platform that provides a one-stop solution to the two core issues of "service addressing" and "configuration management" in microservice architecture. REST API: A lightweight API specification based on the HTTP protocol. It requires no additional protocol, expresses operation intent through HTTP methods, supports horizontal scaling with its stateless design, improves performance with caching mechanisms, and uses HTTP status codes to indicate results (e.g., 200 success).

[0029] In existing technologies, at least two pressing issues exist in distributed architectures: Security and risk control: To prevent abuse such as email bombing, the number of business transactions per customer (or IP address, account) within a given time frame must be limited; Session consistency: The HTTP protocol is stateless. When load balancing distributes consecutive requests from the same user to different nodes, session data may exhibit a "available on one node, unavailable on another" phenomenon, forcing users to log in again or causing service interruptions. Existing technologies typically address these two issues separately: traffic control often relies on local memory counters or independent gateways for rate limiting. The former cannot share state across nodes, and the latter requires additional deployment, resulting in high costs. Session sharing depends on container-level replication, sticky sessions, or centralized caching. Replication methods incur high synchronization overhead when network latency is high; sticky sessions contradict the purpose of load balancing; and traditional centralized caching (such as Memcached) only provides a key-value structure and cannot accurately count request counts by time window. Therefore, a unified solution is needed that can simultaneously address both "distributed rate limiting" and "Session (which can be understood as "session") sharing," and that is simple to implement, flexible to configure, and has low intrusion into business code.

[0030] This invention unifies "distributed rate limiting" and "Session sharing" within the same technology stack by using Redis's ZSet and Spring Session, taking into account performance, scalability, and ease of use. It can be widely applied to high-concurrency and high-availability Internet service systems.

[0031] Typical distributed architectures usually use an API gateway as the entry point, uniformly handling rate limiting and authentication before forwarding traffic to backend applications. However, legacy systems often lack this independent gateway layer. When transforming them into distributed systems, a non-intrusive, lightweight solution is needed to seamlessly and flexibly add gateway capabilities, minimizing transformation risks and workload. Compared to common solutions, this approach enables finer-grained traffic control. Furthermore, leveraging the hot-update capabilities of a configuration center, it allows for more flexible configuration of the entire module without requiring application restarts.

[0032] The purpose of this invention is to provide a distributed traffic control and session sharing system and method based on Redis (which can be understood as a "remote dictionary service"), which can achieve the following through a single middleware: 1. Accurately count and limit the number of requests for any dimension (user / IP / interface) within a time window; 2. Share session data among nodes in the cluster to ensure user session consistency; 3. Support dynamic adjustment of rate limiting parameters without restarting the application.

[0033] Reference Figure 1 , Figure 1 This is an overall framework diagram of a distributed architecture traffic control and session sharing system based on caching technology according to the present invention.

[0034] like Figure 1 As shown in the figure, this embodiment provides a distributed architecture traffic control and session sharing system based on caching technology. The distributed traffic control and session (which can be understood as "session") sharing module is deployed in the backend service cluster. Specifically, after the user's browser submits a business request, the business request is distributed to a service node in the service cluster according to a preset load balancing strategy. Both the traffic control module 100 and the session sharing module 200 are deployed in the backend service cluster. The configuration center module is deployed independently. Through the configuration center module, the rate limiting threshold (current time - range, collection size count) and SessionTimeout (which can be understood as "session timeout") are exposed as externalized parameters to achieve dynamic parameter tuning without business restart. The traffic control module and the session sharing module share the same Redis (which can be understood as "remote dictionary service") instance or Redis (which can be understood as "remote dictionary service") cluster. The storage required for traffic control and session sharing is merged into the same Redis instance. Data is isolated through namespaces (keyprefix) to reduce system complexity.

[0035] The distributed architecture traffic control and session sharing system based on caching technology includes: a traffic control module, a session sharing module, and a configuration center module. The configuration center module is coupled to the traffic control module and the session (which can be understood as "session") sharing module. When the parameters change, the configuration center module pushes the changed parameters to the traffic control module and the session sharing module in real time. The parameters include range (which can be understood as "time range threshold"), count (which can be understood as "set size threshold"), and / or sessionTimeout (which can be understood as "session timeout threshold"). The flow control module and the session sharing module share the same Redis (which can be understood as a "remote dictionary service") instance or Redis (which can be understood as a "remote dictionary service") cluster; The flow control module uses ZSet (which can be understood as an "ordered set") in Redis to store access records and control the time range of queries and the threshold of the number of requests. The Session sharing module uses the Spring Session framework (which can be understood as the Spring session framework) and Redis as the external session storage. It is used to generate a globally unique Session ID (which can be understood as a "session identifier"). Any node can obtain or update the session through Redis.

[0036] Specifically, the configuration center module needs to be deployed independently, while the traffic control and session sharing modules are embedded into the backend application as dependency packages. When the application starts, it actively pulls the configuration and establishes a listener. When the parameters change, the configuration center module pushes the changes in real time.

[0037] In some optional embodiments provided by the present invention, the configuration center module adopts the Nacos component (which can be understood as a "dynamic naming and configuration service component"). The configuration center module provides a unified REST interface (which can be understood as a "representation layer state transformation interface") for real-time parameter modification. The parameters include range (which can be understood as a "time range threshold"), count (which can be understood as a "set size threshold"), and sessionTimeout (which can be understood as a "session timeout threshold"). After the configuration center module changes its parameters, each node in the distributed architecture detects this through long polling or a message bus and refreshes its local context.

[0038] Specifically, the configuration center module is implemented using Nacos, providing a unified REST interface for operations personnel to modify parameters such as range, count, and sessionTimeout in real time. After parameter changes, each node detects the change through long polling or a message bus and refreshes its local context. In other words, Nacos configuration hot-updates and controls parameters such as range, count, and sessionTimeout. At system startup, the traffic control module and session sharing module actively retrieve parameters such as range, count, and sessionTimeout from Nacos and initialize the modules. When parameters change, Nacos pushes the updated parameters to the application nodes.

[0039] In some optional embodiments provided by the present invention, the access record includes a unique identifier of the request and a timestamp of the request occurring; The unique identifier of the request includes at least one of the following: user ID (which can be understood as "user identifier"), IP address (which can be understood as "Internet Protocol"), and interface name; The timestamp of the request is in milliseconds.

[0040] Specifically, the flow control module uses Redis's ZSet (which can be understood as an "ordered set") to store access records, where: Member (can be understood as "member"): A unique identifier for the request (such as user ID, IP, interface name or a combination thereof); Score (which can be understood as "score"): The timestamp (in milliseconds, Unix Time) at which the request occurred.

[0041] It should be noted that the choice of which identifier to use depends on the granularity of traffic control required by the business scenario. If only user-based rate limiting is needed, the user ID can be used as the identifier. If finer-grained control is required, such as "a specific user using a specific function", the user ID + interface name can be used as the identifier.

[0042] In this invention, the "pruning by score range" feature of Redis ZSet is used to abstract "time window rate limiting" into a sliding pruning operation of the set.

[0043] In some optional embodiments provided by the present invention, the Session sharing module includes a Redis HTTP session configuration unit (which can be understood as a "remote dictionary service hypertext transfer protocol session configuration unit"), a session repository filtering unit, and a Redis operation session storage repository unit (which can be understood as a "remote dictionary service operation session storage repository unit"). The Redis HTTP session configuration unit is used to read the session timeout parameter from the configuration center module and complete the Spring Bean assembly (which can be understood as "Spring container object assembly"). The Session Repository Filtering Unit is a Servlet specification filter that intercepts HTTP (which can be understood as "Hypertext Transfer Protocol") requests, wraps the HTTP request object into a Session Repository Request Wrapper, and wraps the HTTP response object into a Session Repository Response Wrapper, thus taking over session management. Redis operation session storage repository unit, used for adding, deleting, modifying and querying Session data, uses Redis Hash structure (which can be understood as "remote dictionary service hash structure") to store session attributes.

[0044] Specifically, the Session sharing module adopts the Spring Session framework and uses Redis as the external session storage. Its key components include: Redis Http Session Configuration (which can be understood as a "remote dictionary service Hypertext Transfer Protocol session configuration unit"): reads the sessionTimeout parameter (which can be understood as "session timeout") from the configuration center and completes the Spring Bean configuration; Session Repository Filter (can be understood as a "session repository filter unit"): A Servlet specification filter that intercepts all HTTP requests and wraps the Http Servlet Request (can be understood as a "Hypertext Transfer Protocol request") and Http Servlet Response (can be understood as a "Hypertext Transfer Protocol response object") into SessionRepository Request Wrapper (can be understood as a "session repository request wrapper") and SessionRepository Response Wrapper (can be understood as a "session repository response wrapper"), thereby taking over session management; Redis Operations Session Repository (which can be understood as a "remote dictionary service operation session storage repository unit"): It is responsible for adding, deleting, modifying, and querying sessions, and uses the Redis Hash structure to store session attributes.

[0045] In some optional embodiments provided by the present invention, the flow control module and the session sharing module sharing the same Redis instance or Redis cluster include: Flow control and Session-shared storage are merged into the same Redis instance or Redis cluster, and data is isolated through namespaces.

[0046] Specifically, the storage required for flow control and session sharing is merged into the same Redis instance, and data is isolated through namespaces (keyprefixes), reducing system complexity. It's important to note that namespaces are parameter settings; simply put, they add a prefix to key names. This is a logical method of grouping keys, which helps organize and manage data and avoids key name conflicts between different modules. For example, rateControl:user1 and rateControl:user2 can be used as keys.

[0047] In one embodiment, a method for distributed architecture traffic control and session sharing based on caching technology is provided, referring to... Figures 2-4 , Figure 2 This is a flowchart of the flow control module in a distributed architecture flow control and session sharing system and method based on caching technology according to the present invention. Figure 3 This is a timing diagram of the session sharing module in a distributed architecture flow control and session sharing system and method based on caching technology according to the present invention. Figure 4 This is a flowchart of a distributed architecture traffic control and session sharing method based on caching technology according to the present invention.

[0048] like Figure 4 As shown, a method for distributed architecture traffic control and session sharing based on caching technology includes: S100. After a user submits a service request, the service request is distributed to a service node in the service cluster according to the preset load balancing strategy. After receiving a business request, the S200 and service nodes retrieve parameters from the configuration center module. The traffic control module determines whether the limit has been exceeded based on the time range of the query and the threshold for the number of requests. If the limit is not exceeded, the business request is allowed; if the limit is exceeded, the business request is blocked. For the first access request, the session sharing module generates a globally unique session ID. For subsequent user requests, it retrieves / updates the session through Redis. For expired or deregistered sessions, the corresponding key in Redis is deleted. Each service node is aware of this in real time.

[0049] In some optional embodiments provided by the present invention, the traffic control module determines whether the limit has been exceeded based on the time range of the query and the threshold of the number of requests. If the limit has not been exceeded, the business request is executed; if the limit has been exceeded, the business request is blocked, including: When a business request arrives, the current timestamp is used as the score, and the member is written into an ordered set. Use the ZREMRANGEBYSCORE command (which can be understood as "delete members of an ordered set by a score range") to delete members that expired earlier than "current time − range" (which can be understood as "time range threshold"); Use the ZCARD command (which can be understood as "get the number of members in an ordered set") to get the current size of the set; If the size of the collection is greater than or equal to count (which can be understood as the "collection size threshold"), the business request is rejected and an error code is returned; otherwise, the business request continues to be executed.

[0050] Specifically, such as Figure 2 As shown: Step 1: Each time a business request arrives, add the member to the ZSet with the current timestamp as the score; where member is a unique identifier for the request (such as user ID, IP, interface name or a combination thereof). Step 2: Use the ZREMRANGEBYSCORE command to trim expired records, that is, delete members that expire earlier than "current time - range"; Step 3: Use the ZCARD command to calculate and obtain the current size of the collection; Step 4: Determine if the limit is exceeded. If the size of the collection is greater than or equal to count, the limit is exceeded, the request is rejected (i.e., the request is intercepted), and an error code is returned. If the size of the collection is less than count, the limit is not exceeded, the request is allowed, and the business request continues to be executed.

[0051] Dynamic configuration: The range and count parameters control the time range of the query and the threshold for the number of requests, respectively. They are uniformly distributed by the configuration center module and support hot updates.

[0052] In some optional embodiments provided by this invention, the Session sharing module generates a globally unique Session ID for the first access request, retrieves or updates the session through Redis for subsequent user requests, and deletes the corresponding key from Redis for expired or cancelled Sessions. Each service node is aware of this in real time, including: When a browser visits the site for the first time, the service node generates a globally unique Session ID and returns it to the client via Set-Cookie; Subsequent requests carry this Session ID, allowing any node to retrieve or update the session via Redis; When a Session expires or is deregistered, the corresponding key in Redis is deleted, and each node is aware of this in real time.

[0053] Specifically, such as Figure 3 As shown: S1. When the browser visits for the first time, it submits authentication credentials to the server via the POST / auth authentication interface; S2. After the server verification is successful, the service node generates a globally unique Session ID. S3 returns the information to the client (browser) via Set-Cookie (which can be understood as "setting a cookie"). S4. Create and set up a session (SET Session) stored in Redis; where HTTP 200 OK is the success response indicator, meaning that the browser's request was successfully received, parsed and processed by the server; S5. Subsequent requests can carry this Session ID and be sent to any node on the server via the GET / api interface; S6. Any node can obtain / update the session via Redis (GET Session); The S7 Session sharing module also includes the ability for each node to detect in real time when a Session expires or is logged out, as the corresponding key in Redis is deleted.

[0054] In some optional embodiments provided by the present invention, the method further includes: When the system starts, the flow control module and the session sharing module actively pull the time range threshold, set size threshold, and session timeout threshold from Nacos and initialize the modules. When the parameters change, Nacos will push the changed parameters to the application node. The parameters include the time range threshold, set size threshold, and / or session timeout threshold.

[0055] In one embodiment, the distributed architecture traffic control and session sharing system and method based on caching technology of the present invention can be used not only for email sending, but also for SMS, login, payment and any other business that requires rate limiting and session persistence.

[0056] In some optional embodiments provided by the present invention, in a distributed architecture traffic control and session sharing system and method based on caching technology, the member can be concatenated with multi-dimensional identifiers to expand the dimensions, such as "userId:api Name" to achieve fine-grained rate limiting "per user per interface".

[0057] In some optional embodiments provided by the present invention, the distributed architecture flow control and session sharing system and method based on caching technology of the present invention can be atomically executed using Lua scripts for scenarios with higher data consistency requirements, thereby avoiding concurrent competition.

[0058] In one embodiment, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps: After a user submits a business request, the business request is distributed to a service node in the service cluster according to a preset load balancing strategy; after the service node receives the business request, the traffic control module and the session sharing module obtain parameters from the configuration center module. The traffic control module determines whether the limit is exceeded based on the time range of the query and the threshold of the number of requests. If the limit is not exceeded, the business request is allowed; if the limit is exceeded, the business request is blocked; for the first access request, the session sharing module generates a globally unique session ID. For subsequent user requests, it retrieves or updates the session through Redis, and deletes the corresponding key in Redis for expired or canceled sessions. Each service node is aware of this in real time.

[0059] As can be seen from the above embodiments, the distributed architecture flow control and session sharing system and method, and electronic device based on caching technology provided by the present invention achieve at least the following beneficial effects: 1. Dual Functionality in One: The same Redis instance simultaneously serves as both a "counter" and a "session storage," simplifying operation and maintenance and maximizing resource utilization; 2. Precise rate limiting: Based on the ZSet time window algorithm, it can be accurate to the millisecond level, avoiding the critical change problem of traditional fixed windows; 3. Non-intrusive: Zero intrusion on business code; business developers need not be aware of rate limiting and session sharing logic. 4. Dynamic scaling: Parameters are hot-updated without requiring application restarts; Redis itself can be horizontally scaled and supports large-scale clusters. 5. High availability: Redis supports master-slave + sentinel or cluster mode, so a single point of failure will not affect the overall service.

[0060] While specific embodiments of the invention have been described in detail by way of examples, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. Those skilled in the art should understand that modifications can be made to the above embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.

Claims

1. A distributed architecture flow control and session sharing system based on caching technology, characterized in that, include: Traffic control module, session sharing module, configuration center module; The configuration center module is coupled to the traffic control module and the session sharing module respectively. When the parameters change, the configuration center module pushes the changed parameters to the traffic control module and the session sharing module in real time. The parameters include time range threshold, set size threshold, and / or session timeout threshold. The flow control module and the session sharing module share the same remote dictionary service instance or remote dictionary service cluster. The flow control module uses an ordered set in the remote dictionary service to store access records and controls the time range and threshold of the number of requests for queries. The session sharing module adopts the Spring session framework and uses a remote dictionary service as an external session storage to generate globally unique session identifiers. Any node can obtain or update a session through the remote dictionary service.

2. The distributed architecture traffic control and session sharing system based on caching technology according to claim 1, characterized in that, The configuration center module uses dynamic naming and configuration service components; The configuration center module provides a unified presentation layer state transformation interface for real-time modification of the parameters; After the configuration center module changes its parameters, each node in the distributed architecture detects this change and refreshes its local context through long polling or a message bus.

3. The distributed architecture traffic control and session sharing system based on caching technology according to claim 1, characterized in that, The access record includes a unique identifier for the request and a timestamp of when the request occurred; The unique identifier of the request includes at least one of the following: user identifier, Internet protocol, and interface name; The timestamp of the request is in milliseconds.

4. The distributed architecture traffic control and session sharing system based on caching technology according to claim 1, characterized in that, The session sharing module includes a remote dictionary service hypertext transfer protocol session configuration unit, a session repository filtering unit, and a remote dictionary service operation session storage repository unit. The remote dictionary service hypertext transfer protocol session configuration unit is used to read the session timeout parameter of the configuration center module and complete the Spring container object assembly. The session repository filtering unit is a Servlet specification filter that intercepts Hypertext Transfer Protocol (HTTP) requests and wraps the HTTP request object into a session repository request wrapper. Wrap the Hypertext Transfer Protocol response object into a session repository response wrapper to take over session management; The remote dictionary service operation session storage warehouse unit is used for adding, deleting, modifying, and querying sessions, and uses the remote dictionary service hash structure to store session attributes.

5. The distributed architecture traffic control and session sharing system based on caching technology according to claim 1, characterized in that, The flow control module and the session sharing module share the same remote dictionary service instance or remote dictionary service cluster, including: Flow control and session-shared storage are merged into the same remote dictionary service instance or remote dictionary service cluster, and data is isolated through namespaces.

6. A method for distributed architecture flow control and session sharing based on caching technology, characterized in that, include: After a user submits a business request, the request is distributed to a service node in the service cluster according to the preset load balancing strategy. After a service node receives the service request, the traffic control module and the session sharing module obtain parameters from the configuration center module. The traffic control module determines whether the limit has been exceeded based on the query time range and the threshold for the number of requests. If the limit is not exceeded, the service request is allowed; if the limit is exceeded, the service request is blocked. For the first access request, the session sharing module generates a globally unique session identifier. For subsequent user requests, it obtains or updates the session through the remote dictionary service and deletes the corresponding key from the remote dictionary service for invalid or canceled sessions. Each service node is aware of this in real time.

7. The method for distributed architecture traffic control and session sharing based on caching technology according to claim 6, characterized in that, The traffic control module determines whether the limit has been exceeded based on the query time range and the threshold for the number of requests. If the limit is not exceeded, the business request is executed; if the limit is exceeded, the business request is blocked, including: When a business request arrives, the member is written into an ordered set using the current timestamp as the fraction. Use the command to delete members of an ordered set by score range to delete members that expired earlier than "current time - time range threshold"; Use the command to get the number of members in an ordered set to get the current size of the set; If the size of the set is greater than or equal to the set size threshold, the business request is rejected and an error code is returned; otherwise, the business request continues to be executed.

8. The method for distributed architecture flow control and session sharing based on caching technology according to claim 6, characterized in that, For the first access request, the session sharing module generates a globally unique session identifier. For subsequent user requests, it retrieves or updates the session through a remote dictionary service. For expired or logged-out sessions, the corresponding key is deleted from the remote dictionary service. Each service node is aware of this in real time. When a browser visits the site for the first time, the service node generates a globally unique session identifier and returns it to the client via Set-Cookie; Subsequent requests carry this session identifier, and any node can obtain or update the session through the remote dictionary service; When a session expires or is logged out, the corresponding key is deleted from the remote dictionary service, and each node is aware of this in real time.

9. The method for distributed architecture flow control and session sharing based on caching technology according to claim 6, characterized in that, The method also includes: When the system starts, the flow control module and the session sharing module actively pull time range threshold, set size threshold, and session timeout threshold from the dynamic naming and configuration service component. When the parameters change, the dynamic naming and configuration service component will push the changed parameters to the application node. The parameters include time range threshold, set size threshold, and / or session timeout threshold.

10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the method for distributed architecture flow control and session sharing based on caching technology as described in any one of claims 6 to 9 when executing the computer program.