Distributed cluster session sharing method, system, device and storage medium
By generating globally unique session identifiers in a distributed cluster and performing unified storage and validity verification, the problem of user login status loss and duplicate login caused by scattered storage of session data in a distributed microservice architecture is solved. This enables cross-instance sharing and efficient access of session data, improving system stability and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI YUNDA HIGH TECH CO LTD
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-16
AI Technical Summary
In a distributed microservice architecture, the scattered storage of session data leads to problems such as loss of user login status, duplicate logins, and business process interruptions. Existing solutions cannot meet the actual needs of large-scale microservice clusters.
A distributed cluster session sharing method is adopted. A globally unique session identifier is generated, written into the dictionary service cluster for unified storage, and then used for validity verification in subsequent login requests. Based on preset routing rules, the request is routed to the corresponding business service instance to obtain session data and complete the user login.
It enables global sharing and cross-instance access of session data, solves the problems of lost login status and duplicate login, improves system stability and user experience, and reduces storage resource overhead and operation and maintenance costs.
Smart Images

Figure CN122226342A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of session sharing technology, and in particular to a distributed cluster session sharing method, system, device and storage medium. Background Technology
[0002] In a distributed microservice architecture, services are often split according to business dimensions and deployed using a multi-instance model. This exacerbates the problem of fragmented session storage, becoming a core factor restricting system stability and user experience. Specifically, this issue manifests as a lack of real-time session synchronization mechanisms between multiple instances of the same service. When user requests are routed to different instances via load balancing, login status loss and session interruptions are likely to occur. Furthermore, when different services are deployed across domains, session data is strongly bound to its respective service, preventing cross-service communication. This forces users to log in repeatedly when switching between services, severely disrupting business processes.
[0003] Existing traditional solutions all have significant shortcomings and are difficult to adapt to the actual needs of large-scale microservice clusters. Session replication solutions rely on the service's native synchronization mechanism, which not only consumes a large amount of network bandwidth to transmit the full session data, but also suffers from memory limitations due to all instances storing the complete session set, making horizontal scaling impossible. Client-side storage solutions store session data in cookies, which are limited by data length and cannot store large amounts of information, and also pose security risks of data leakage and tampering, while increasing the bandwidth consumption of HTTP requests. Although hash consistency solutions do not require modification to application code, sessions are still stored locally on the service instance. When the instance restarts or is expanded, rehashing can easily cause some sessions to be lost, leading to duplicate login issues for users. Summary of the Invention
[0004] In order to overcome the shortcomings of the prior art, the present invention aims to provide a distributed cluster session sharing method, system, device and storage medium, which aims to solve the problems of user login status loss, duplicate login and business process interruption caused by the scattered storage of session data and the lack of a global unified sharing mechanism.
[0005] The first aspect of this invention provides a distributed cluster session sharing method. The distributed cluster session sharing system includes a client, a control unit, multiple service instances, and a storage unit. The client communicates with each service instance through the control unit, and each service instance communicates with the storage unit. The method includes: acquiring an initial login request sent by the client and generating a session identifier; returning the session identifier to the client and writing the session identifier into a dictionary service cluster of the storage unit; acquiring subsequent login requests sent by the client containing the session identifier; performing a validity check on the subsequent login requests based on the dictionary service cluster; when the validity check passes, routing the subsequent login requests to the corresponding service instances based on preset routing rules; and controlling the service instances to obtain session data corresponding to the session identifier from the dictionary service cluster to complete the user login.
[0006] Optionally, in a first implementation of the first aspect of the present invention, the distributed cluster session sharing system further includes a microservice gateway, and the control unit communicates with each of the business service instances through the microservice gateway; the step of generating a session identifier based on the first login request includes: controlling the microservice gateway to receive the first login request and routing the first login request to the corresponding business service instance based on the routing rules, wherein the first login request includes account and password information; controlling the business service instance to perform information verification on the account and password information to obtain an information verification result; when the information verification result is successful, controlling the business service instance to trigger a built-in session management component to generate session data based on the first login request, wherein the session data includes the session identifier.
[0007] Optionally, in a second implementation of the first aspect of the present invention, the account password information includes account information and password information; controlling the business service instance to perform information verification on the account password information to obtain an information verification result includes: controlling the business service instance to call a preset user database and verifying whether the account information is correct based on the user database; when the account information is incorrect, obtaining the information verification result, which is a failure; when the account information is correct, controlling the business service instance to verify whether the status of the account information is normal; when the status of the account information is abnormal, obtaining the information verification result, which is a failure; when the status of the account information is normal, controlling the business service instance to verify whether the password information is correct; when the password information is correct, obtaining the information verification result, which is a pass; when the password information is incorrect, obtaining the information verification result, which is a failure.
[0008] Optionally, in a third implementation of the first aspect of the present invention, after writing the session identifier into the dictionary service cluster of the storage unit, the method further includes: controlling the dictionary service cluster to monitor in real time whether the preset TTL expiration time of the session identifier has expired; when the preset TTL expiration time has expired, controlling the dictionary service cluster to clean up the session data corresponding to the session identifier.
[0009] Optionally, in a fourth implementation of the first aspect of the present invention, the step of validating the subsequent login request based on the dictionary service cluster includes: controlling the microservice gateway to receive the subsequent login request and parse the subsequent login request to obtain the session identifier and the timestamp corresponding to the session identifier; controlling the microservice gateway to verify whether the session identifier exists based on the dictionary service cluster; and when the session identifier exists, controlling the microservice gateway to verify whether the validity period of the timestamp has expired based on the dictionary service cluster.
[0010] Optionally, in a fifth implementation of the first aspect of the present invention, the distributed cluster session sharing system further includes an exception handling unit, and the microservice gateway communicates with each of the business service instances through the exception handling unit; after the subsequent login request is validated based on the dictionary service cluster, the system further includes: when the validation fails, controlling the microservice gateway to send the session identifier corresponding to the subsequent login request to the exception handling unit; controlling the exception handling unit to perform exception encoding matching processing on the session identifier based on a preset unified exception enumeration rule to obtain an exception response message; controlling the microservice gateway to receive the exception response message and return the exception response message to the client.
[0011] Optionally, in a sixth implementation of the first aspect of the present invention, the distributed cluster session sharing system further includes a load balancer, which is communicatively connected between the microservice gateway and the exception handling unit; after routing the subsequent login request to the corresponding business service instance based on preset routing rules, the system further includes: controlling the load balancer to monitor the running status of the business service instance in real time; when the running status of the business service instance is abnormal, controlling the load balancer to resend the subsequent login request to a new business service instance, and sending the business service instance identifier of the business service instance with the abnormal running status to the exception handling unit; and controlling the exception handling unit to register the abnormal status of the business service instance identifier.
[0012] A second aspect of the present invention provides a distributed cluster session sharing system, applied to the distributed cluster session sharing method described in any one of the preceding claims. The system includes a client, a control unit, a service instance unit, and a storage unit. The service instance unit includes multiple service instances. The client communicates with each service instance through the control unit, and each service instance communicates with the storage unit. The client sends an initial login request to each service instance, causing the service instance to generate a session identifier based on the initial login request and return the session identifier to the client. Simultaneously, the client writes the session identifier into the dictionary service cluster of the storage unit. The storage unit performs validity checks on subsequent login requests sent by the client based on the dictionary service cluster. When the validity check passes, the client is allowed to route the subsequent login requests to the corresponding service instance based on preset routing rules. The service instance retrieves session data corresponding to the session identifier from the dictionary service cluster to complete the user login.
[0013] A third aspect of the present invention provides a distributed cluster session sharing device, the distributed cluster session sharing device comprising: a memory and at least one processor, the memory storing instructions; at least one processor calling the instructions in the memory to cause the distributed cluster session sharing device to execute the various steps of the distributed cluster session sharing method described in any of the preceding claims.
[0014] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed by a processor, implement the steps of the distributed cluster session sharing method described in any of the preceding claims.
[0015] In the technical solution of this invention, the initial login request sent by the client is first obtained and a session identifier is generated. The session identifier is returned to the client and written into the dictionary service cluster of the storage department. Then, subsequent login requests containing the session identifier sent by the client are obtained. The validity of the subsequent login requests is verified based on the dictionary service cluster. When the validity verification is successful, the subsequent login requests are routed to the corresponding business service instance based on preset routing rules. Finally, the business service instance is controlled to obtain the session data corresponding to the session identifier from the dictionary service cluster to complete the user login. This invention aims to solve the problems of user login status loss, duplicate login, and business process interruption caused by the scattered storage of session data and the lack of a globally unified sharing mechanism. Attached Figure Description
[0016] Figure 1 This is a first flowchart of a distributed cluster session sharing method provided in an embodiment of the present invention; Figure 2 This is a second flowchart of the distributed cluster session sharing method provided in an embodiment of the present invention; Figure 3 This is a third flowchart of the distributed cluster session sharing method provided in the embodiments of the present invention; Figure 4 This is a fourth flowchart of the distributed cluster session sharing method provided in the embodiments of the present invention; Figure 5 This is a fifth flowchart of the distributed cluster session sharing method provided in an embodiment of the present invention; Figure 6 This is a sixth flowchart of the distributed cluster session sharing method provided in an embodiment of the present invention; Figure 7 The seventh flowchart of the distributed cluster session sharing method provided in the embodiments of the present invention; Figure 8 This is a schematic diagram of the structure of the distributed cluster session sharing device provided in an embodiment of the present invention; Figure 9 This is a schematic diagram of the structure of a distributed cluster session sharing device provided in an embodiment of the present invention. Detailed Implementation
[0017] This invention provides a distributed cluster session sharing method, system, device, and storage medium. In this invention, the terms "first," "second," "third," "fourth," etc. (if present)," in the specification, claims, and accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" or "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0018] For ease of understanding, the specific process of this embodiment of the invention is described below. The distributed cluster session sharing system includes a client, a control unit, multiple service instances, and a storage unit. The client communicates with each service instance through the control unit, and each service instance communicates with the storage unit. Please refer to [link to relevant documentation]. Figure 1 One embodiment of the distributed cluster session sharing method in this invention includes: 101. Obtain the first login request sent by the client and generate a session identifier; 102. Return the session identifier to the client and write the session identifier into the dictionary service cluster of the storage department; In this embodiment, the system first receives the initial login request initiated by the client. After the business service instance verifies the user's identity credentials in the initial login request and the verification is successful, a session identifier is generated based on the initial login request. This identifier serves as an index of the user session, possessing uniqueness and identifiability. It can accurately associate the user's login status and related session data, effectively avoiding session confusion issues in multi-instance deployment scenarios. After generating the session identifier, the system sends it back to the client. The client can retain it according to its own storage mechanism, allowing it to carry the identifier when making subsequent requests. This provides a basis for the system to quickly identify the user's session identity, improving the efficiency of session verification. Simultaneously, the system writes the session identifier to the dictionary service cluster in the storage department. That is, the session identifier and service identifier are used as storage keys to write to the dictionary service cluster in the storage department. The dictionary service cluster completes the association storage of the session identifier with the user's login status and session data, realizing distributed persistent storage of session data. This makes the dictionary service cluster a globally unified storage carrier for session data, providing data support for subsequent session verification and invocation. It breaks away from the limitation of traditional mode where session data depends on local storage of service instances, achieving global sharing of session data. This fundamentally solves the problem of session data synchronization failure caused by single-instance storage. Furthermore, the distributed nature of the dictionary service cluster ensures the reliability of session data storage and the efficiency of access, avoiding session data loss and synchronization issues, and improving the overall availability and scalability of the distributed cluster.
[0019] 103. Obtain the subsequent login request sent by the client, which includes the session identifier; 104. Perform a validity check on the subsequent login request based on the dictionary service cluster; In this embodiment, the system first acquires subsequent login requests initiated by the client after the initial login. These requests carry a session identifier previously generated and returned for the user. This identifier serves as the basis for identifying the user's session identity and verifying session validity, and is a key index for subsequent request processing. The system uses the dictionary service cluster in the storage department as a unified data support carrier to conduct comprehensive legitimacy checks on subsequent login requests. The verification process relies on historically stored session identifiers and associated session data in the cluster to perform dual verification of the existence and validity of the session identifier. Simultaneously, it verifies core information such as the session's expiration status, ensuring that the session corresponding to the request to be processed is legitimate and within its valid lifespan. By performing session legitimacy checks upfront in the subsequent request stage, illegal and invalid access requests can be directly intercepted, improving the overall security of the system from the access entry point and preventing illegal session requests from causing meaningless resource consumption and interference to business service instances within the cluster. By using a dictionary service cluster as a unified verification data carrier, the verification process relies on globally shared session data. This overcomes the data silo problem caused by local storage of session data in traditional models, ensuring high consistency of session verification standards across nodes in the distributed cluster and effectively avoiding verification result deviations caused by data asynchrony. Furthermore, completing pre-verification and admission screening before requests reach business service instances effectively reduces unnecessary processing overhead on business service instances and improves the overall resource utilization efficiency of the distributed cluster.
[0020] 105. When the legitimacy verification passes, the subsequent login request is routed to the corresponding business service instance based on the preset routing rules; 106. Control the business service instance to obtain session data corresponding to the session identifier from the dictionary service cluster to complete user login.
[0021] In this embodiment, the dictionary service cluster, also known as a Redis cluster, adopts a highly available distributed architecture. The number of nodes is configured with an odd number of nodes, with 3 nodes as the smallest unit, and can be expanded to 5 or 7 nodes as needed. Read and write operations are handled uniformly by the master node, and logs are synchronized to the slave nodes. When the master node fails, a new master is automatically elected. The fault tolerance mechanism includes automatic takeover of node failures, multiple data replica backups, and split-brain protection based on the Quorum (quorum) mechanism to ensure that data is not lost and services are not interrupted.
[0022] In this embodiment, after the session validity verification is passed, the system will route subsequent login requests from the client to the corresponding business service instance according to the pre-configured routing rules. These routing rules are set based on the distributed cluster deployment architecture, business requirements, and load balancing objectives, and are configured with multiple core factors, typically including the operating load of each business service instance, business affiliation, session stickiness requirements, and instance health status, adapting to the dynamic deployment characteristics of the distributed cluster. Specifically, the load dimension sets distribution weights based on real-time operating metrics such as CPU utilization, memory usage, and request queue length of each business service instance to avoid overloading a single instance; the business affiliation dimension routes requests to the service instance cluster responsible for that business based on the corresponding business module, achieving precise matching between business and instance; the session stickiness dimension binds fixed service instances based on session identifiers, reducing the frequency of cross-instance session data retrieval and improving processing efficiency. This routing rule, through comprehensive consideration of multiple factors, achieves standardized request distribution and reasonable load balancing across the cluster, while also considering business adaptability and operational stability. After request routing is completed, the system controls the target business service instance to retrieve the session data associated with the session identifier carried in the request from the dictionary service cluster in the storage department, using the session identifier as a unique index. The system then parses and verifies the session data to confirm the user's login status, ultimately closing the loop of the subsequent login process and establishing a valid session connection for the user's subsequent business operations. By retrieving session data from the dictionary service cluster, the business service instance completely eliminates the limitations of local session data storage in traditional models, achieving global sharing of session data across instances. Regardless of which normal business service instance the user request is routed to within the cluster, complete and valid session data can be quickly obtained, ensuring the consistency of the user's login status within the cluster. This fundamentally solves the problem of lost login status and interrupted business processes caused by instance switching in distributed deployments. Simultaneously, the precise retrieval method using the session identifier as an index improves the efficiency of session data retrieval, enabling rapid confirmation of the user's login status, effectively shortening request processing response time, and ensuring a good user experience. Furthermore, the business service instance does not need to maintain local session data, significantly reducing the storage resource overhead for each instance.
[0023] In this embodiment of the invention, the distributed cluster session sharing system further includes a microservice gateway, and the control unit communicates with each of the business service instances through the microservice gateway; please refer to... Figure 2 The step of generating a session identifier based on the initial login request includes: 201. Control the microservice gateway to receive the first login request, and route the first login request to the corresponding business service instance based on the routing rules. The first login request includes account and password information. 202. Control the business service instance to perform information verification on the account password information and obtain the information verification result; 203. When the information verification result is passed, control the business service instance to trigger the built-in session management component to generate the session data based on the first login request. The session data includes the session identifier.
[0024] In this embodiment, when the client initiates its first login request, the microservice gateway receives the request, which carries the user's account and password information for authentication. The microservice gateway then routes the first login request precisely to the corresponding business service instance according to the preset routing rules, and the instance performs the user's identity verification. The business service instance systematically verifies the received account and password information. After verifying the compliance and validity of the user's identity information, it generates the corresponding verification result. Only when the verification result is successful, i.e., the user's identity verification is successful, will the business service instance trigger its built-in session management component. This ensures the security of session establishment from the source, effectively avoids the security risk of creating valid sessions with unauthorized identities, and improves the system's identity authentication security. Based on the core identity and request information in the initial login request, the session management component generates session data containing a session identifier. The session identifier, as the core index identifier of the user session, has global uniqueness and is the key basis for subsequent session identification, verification, and data association. This ensures the uniqueness of the session identifier within the distributed cluster, avoids session confusion in multi-instance deployment scenarios, and achieves standardized and unique storage of session data. This lays the core foundation for subsequent cross-instance and cross-service session sharing and unified management, while also facilitating accurate retrieval, verification, and retrieval of session data, significantly improving the efficiency of session processing.
[0025] Please see Figure 3 In this embodiment of the invention, the account password information includes account information and password information; controlling the business service instance to verify the account password information and obtain the verification result includes: 301. Control the business service instance to call the preset user database, and verify whether the account information is correct based on the user database; 302. When the account information is incorrect, the information verification result is obtained, and the information verification result is failure; 303. When the account information is correct, control the business service instance to verify whether the status of the account information is normal; 304. When the status of the account information is abnormal, the information verification result is obtained, and the information verification result is failure; 305. When the account information is in a normal state, control the business service instance to verify whether the password information is correct; 306. When the password information is correct, the information verification result is obtained, and the information verification result is passed; 307. When the password information is incorrect, the information verification result is obtained, and the information verification result is failure.
[0026] In this embodiment, the business service instance verifies account password information based on a pre-built and maintained user database. This database is a structured database that stores all legitimate user identity information and account status information. It retains the user's valid account information, the encrypted password information bound to the account, and the real-time usage status information of the account. It is uniformly managed and maintained by the system to ensure the real-time performance, accuracy, and integrity of the data. Account password information can be broken down into two core verification dimensions: account information and password information. The business service instance will conduct verification of each dimension step by step according to a progressive logical hierarchy and generate corresponding information verification results based on the verification results.
[0027] After verification begins, the business service instance first calls the preset user database to precisely match the account information in the client request with the legitimate account information stored in the database. If the two cannot match, the account information is directly determined to be incorrect, and a failed verification result is immediately generated. If the account information verification matches correctly, the validity of the account status corresponding to that account information is further checked to confirm whether the account is in normal use. If the account status is abnormal, a failed verification result is also generated. Only when the account information verification is correct and the account status verification is normal will the business service instance further match the password information in the request with the unique encrypted password information bound to that account in the database. If the password information matches, a successful verification result is generated; if the password information does not match, a failed verification result is generated. The entire verification process proceeds step by step according to a predetermined logical hierarchy. If any step fails verification, the verification process is directly terminated and a failed verification result is returned. This progressive account and password verification logic relies on a unified and accurately managed preset user database to verify identity information, ensuring the authenticity and accuracy of user identity authentication from the root and effectively blocking login requests from unauthorized accounts. In addition, the layered verification design makes the abnormal results of identity authentication clearly traceable, and can accurately locate different verification failure reasons such as incorrect account, abnormal status, and incorrect password.
[0028] Please see Figure 4 In this embodiment of the invention, after writing the session identifier into the dictionary service cluster of the storage unit, the method further includes: 401. Control the dictionary service cluster to monitor in real time whether the preset TTL expiration time of the session identifier has expired; 402. When the preset TTL expiration time expires, the dictionary service cluster is controlled to clean up the session data corresponding to the session identifier.
[0029] In this embodiment, after the session identifier is written to the dictionary service cluster in the storage department, the system relies on the distributed caching characteristics of the dictionary service cluster to carry out full lifecycle management of session data. The preset TTL expiration time is the effective duration of the session configured in advance by the system according to the needs of the business scenario, which can take into account both user experience and reasonable utilization of storage resources. The dictionary service cluster will continuously monitor the preset TTL expiration time corresponding to each session identifier in real time. When the user is in an active state, the built-in session management component will be triggered every time the business service instance processes the user's request. The component will automatically update the TTL expiration time of the session data associated with the corresponding session identifier in the dictionary service cluster, realizing dynamic renewal of the session. This ensures the validity of the session during continuous user operation and avoids the loss of login status due to premature session expiration during normal use. Only when the user does not initiate any requests for a long time, causing the preset TTL expiration time of the session identifier to expire, the dictionary service cluster will automatically trigger the data cleanup mechanism to accurately and thoroughly clean up the session identifier and all associated session data, remove invalid session data from the cluster, and release the storage resources occupied by it in a timely manner. The dictionary service cluster's automatic cleanup mechanism after the TTL expiration time can promptly reclaim storage resources occupied by invalid sessions, preventing redundant accumulation of invalid session data within the cluster, optimizing the storage resource allocation efficiency of the dictionary service cluster, and improving the cluster's high-concurrency read and write performance for valid session data. Simultaneously, the entire renewal and cleanup process is automated by system components, requiring no manual intervention, significantly reducing system operation and maintenance costs. Furthermore, the TTL expiration time renewal and cleanup logic effectively prevents the accidental deletion of valid session data, ensuring both security and reliability in session management.
[0030] Please see Figure 5 In this embodiment of the invention, the legitimacy verification of subsequent login requests based on the dictionary service cluster includes: 501. Control the microservice gateway to receive the subsequent login request, and parse the subsequent login request to obtain the session identifier and the timestamp corresponding to the session identifier; 502. Control the microservice gateway to verify the existence of the session identifier based on the dictionary service cluster; 503. When the session identifier exists, control the microservice gateway to verify whether the validity period of the timestamp has expired based on the dictionary service cluster.
[0031] In this embodiment, the microservice gateway, acting as a front-end admission node for distributed cluster session sharing, is responsible for receiving subsequent login requests initiated by users. Upon receiving a subsequent login request, it first performs structured parsing, extracting the session identifier from the request header or cookie, and simultaneously extracting the timestamp bound to the session identifier. The timestamp records the initiation time of the session request and is core auxiliary information for preventing request replay attacks and strengthening session verification security. After parsing, the microservice gateway, in conjunction with the session management component built into the business service instance, relies on the dictionary service cluster of the storage department to conduct layered legality verification. First, it verifies the existence of the session identifier by querying whether the dictionary service cluster retains valid session data corresponding to the session identifier, completing the basic session legality screening. If the session identifier exists, it further verifies the validity period of the timestamp based on the dictionary service cluster, checking whether the request initiation time is within a preset valid range. At the same time, it limits the access frequency by combining the association between IP and session identifier, constructing a multi-dimensional verification system. If any step fails verification, the request is directly intercepted without forwarding it to the backend business service instance. The collaborative verification of session identifiers and timestamps not only intercepts illegal and invalid session requests through identifier existence checks but also prevents request replay attacks through timestamp validity checks. Combined with access frequency limits, this effectively mitigates the impact of malicious high-frequency requests on the cluster, reducing security risks from unauthorized access. Verification based on a dictionary service cluster ensures consistent verification standards across nodes in the distributed cluster, avoiding verification discrepancies caused by data asynchrony. It adapts to multi-instance deployment and horizontal scaling requirements, while improving request response efficiency and ensuring session continuity and smooth operation for users accessing across instances and services. The automated verification process requires no manual intervention, adapting to the operational needs of large-scale microservice clusters and reducing the operational costs of session management.
[0032] In this embodiment of the invention, the distributed cluster session sharing system further includes an exception handling unit, and the microservice gateway communicates with each of the business service instances through the exception handling unit; see also Figure 6 After performing legality verification on subsequent login requests based on the dictionary service cluster, the method further includes: 601. When the validity check fails, the microservice gateway is controlled to send the session identifier corresponding to the subsequent login request to the exception handling department; 602. Control the exception handling unit to perform exception encoding matching processing on the session identifier based on the preset unified exception enumeration rules to obtain an exception response message; 603. Control the microservice gateway to receive the exception response message and return the exception response message to the client.
[0033] In this embodiment, after verifying the legitimacy of subsequent login requests, if the verification fails (e.g., due to a non-existent session identifier, expired timestamp, or access frequency exceeding a threshold), the microservice gateway extracts the session identifier corresponding to the subsequent login request and sends it to the exception handling department. The exception handler relies on a pre-built and maintained standardized exception mapping system that covers all possible illegal scenarios triggered during session verification. Each scenario corresponds to a unique exception code, exception level, and standardized response text, uniformly configured by operations personnel based on business security requirements and user experience goals. This system is scalable and maintainable; adding new exception scenarios only requires updating the rule entries. When the exception handler receives a session identifier, it first associates it with the verification failure scenario corresponding to that identifier, then accurately matches the corresponding exception code and response content from the pre-built exception enumeration rules to generate a uniformly formatted exception response message. For example, if the session identifier does not exist, it matches an invalid session entry; if the timestamp expires, it matches a request timeout entry, ensuring that the response format and content of all exception scenarios remain consistent. Upon receiving an exception response message from the exception handler, the microservice gateway directly forwards the message to the client, eliminating the need to pass the request further to the backend business service instance. This enables rapid handling of illegal requests, preventing invalid requests from entering the backend business service instance, significantly reducing the unnecessary consumption of cluster resources, and improving overall operational efficiency. The pre-defined exception enumeration rules ensure consistent exception response formats for all illegal session requests, facilitating unified exception handling and user prompts on the client side, optimizing the user experience, and avoiding client adaptation costs caused by heterogeneous exception information returned by different nodes. Furthermore, it makes the exception handling process traceable, with each exception code corresponding to a specific scenario, allowing operations personnel to quickly locate the root cause of problems through logs, conduct security audits and troubleshooting, significantly improving system maintainability and security capabilities.
[0034] In this embodiment of the invention, the distributed cluster session sharing system further includes a load balancer, which is communicatively connected between the microservice gateway and the exception handling unit; see also Figure 7 After routing subsequent login requests to the corresponding business service instance based on preset routing rules, the method further includes: 701. Control the load balancer to monitor the running status of the service instance in real time; 702. When the running status of the business service instance is abnormal, control the load balancer to resend the subsequent login request to the new business service instance, and send the business service instance identifier of the business service instance with abnormal running status to the exception handling unit; 703. Control the exception handling unit to register the abnormal status of the business service instance identifier.
[0035] In this embodiment, after routing subsequent login requests to the corresponding business service instances based on preset routing rules, the system continuously monitors the operational status of all business service instances within the cluster in real time through a load balancer. The monitoring dimensions cover core indicators such as CPU utilization, memory load, network connectivity, and service health check results of the business service instances, ensuring awareness of abnormal instance states. When the load balancer detects an abnormal operation such as abnormal offline status, performance overload, or service unavailability of a business service instance, it immediately triggers a disaster recovery scheduling mechanism. Based on the preset routing rules, it redistributes subsequent login requests to other normally operating business service instances within the cluster, and simultaneously synchronizes the unique identifier of the abnormal business service instance to the exception handling department. Upon receiving this identifier, the exception handling department includes it in the exception status registration system, fully recording key information such as the exception occurrence time, instance identifier, exception type, and duration, forming a traceable exception event ledger to provide data support for subsequent operation and maintenance analysis and fault location. Meanwhile, relying on the high-availability architecture built on the dictionary service cluster's master-slave replication and sentinel mode, all session data has been implemented in multi-replica distributed storage. Newly routed normal business service instances can directly read complete session data from the dictionary service cluster, ensuring the continuity of user login status and preventing login status loss or business process interruption due to the original instance's abnormality. This effectively avoids the impact of abnormal instances on user requests, ensuring service continuity and availability. The load balancer's automated rerouting mechanism requires no manual intervention, significantly shortening service recovery time in abnormal scenarios and reducing losses caused by business interruptions. The status registration function of the exception handling department enables full-link traceability of abnormal events. Operation and maintenance personnel can quickly locate the root cause of the fault through the exception log and carry out targeted optimization and repair, improving the cluster's operation and maintenance efficiency and fault response speed.
[0036] The above describes the distributed cluster session sharing method in the embodiments of the present invention. The following describes the distributed cluster session sharing system in the embodiments of the present invention. Please refer to [link / reference]. Figure 8 One embodiment of the distributed cluster session sharing device in this invention includes: The system includes a client 801, a control unit 802, a service instance unit 803, and a storage unit 804. The service instance unit 803 includes multiple service instances. The client 801 communicates with each service instance through the control unit 802, and each service instance communicates with the storage unit 804. The client 801 sends an initial login request to each service instance, causing the service instance to generate a session identifier based on the initial login request and return the session identifier to the client 801. Simultaneously, the session identifier is written to the dictionary service cluster of the storage unit 804. The storage unit 804 performs validity checks on subsequent login requests sent by the client 801 based on the dictionary service cluster. When the validity check passes, the client 801 is allowed to route the subsequent login requests to the corresponding service instance based on preset routing rules. The service instance retrieves session data corresponding to the session identifier from the dictionary service cluster to complete the user login.
[0037] In this embodiment, the system adopts a layered distributed architecture design. Client 801, as the user-side request initiator, is mainly responsible for initiating the initial login and subsequent access requests to the business service instance unit 803, serving as the entry point for user-system interaction. Control unit 802, as the communication hub between client 801 and business service instance unit 803, undertakes the core functions of request forwarding, routing scheduling, and connection management. By establishing a stable communication link, it ensures that client 801's requests can be accurately distributed to the target business service instance within the cluster. Business service instance unit 803 contains multiple independently running business service instances. As the core business logic execution unit, upon receiving the initial login request from client 801, it completes user identity verification and generates a globally unique session identifier based on the verification result. This identifier serves as the core index of the user session and is synchronously returned to client 801 for storage, while also being written to the dictionary service cluster of storage unit 804 for persistent storage. Storage Unit 804, with the dictionary service cluster as its core, is responsible for the distributed storage of session identifiers and associated session data. During subsequent login request validation, it relies on the session data stored within the dictionary service cluster to verify the existence and timeliness of session identifiers. Only after successful validation is client 801 allowed to route subsequent login requests to the corresponding business service instance based on preset routing rules. This business service instance then retrieves the complete session data associated with the session identifier from the dictionary service cluster to confirm the user's login status and support the execution of subsequent business logic. The distributed deployment mode of multiple business service instances, combined with the routing and scheduling capabilities of Control Unit 802, enables load balancing of requests, avoids overloading of a single instance, and improves the overall request processing throughput and concurrency capacity of the cluster. Storage Unit 804's dictionary service cluster employs distributed caching technology, achieving global sharing and high-concurrency access of session data. This completely solves the problem of session data not being able to be synchronized across instances in traditional local storage modes, ensuring that user requests can obtain consistent session data regardless of which business service instance they are routed to, guaranteeing the continuity of login status and preventing repeated logins or operation interruptions.
[0038] above Figure 8 The distributed cluster session sharing system in this embodiment of the invention will be described in detail from the perspective of modular functional entities. The distributed cluster session sharing device in this embodiment of the invention will be described in detail from the perspective of hardware processing.
[0039] Figure 9This is a schematic diagram of the structure of a distributed cluster session sharing device 900 provided in an embodiment of the present invention. The distributed cluster session sharing device 900 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 910 (e.g., one or more processors) and a memory 920, and one or more storage media 930 (e.g., one or more mass storage devices) for storing application programs 933 or data 932. The memory 920 and storage media 930 can be temporary or persistent storage. The program stored in the storage media 930 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the distributed cluster session sharing device 900. Furthermore, the processor 910 may be configured to communicate with the storage media 930 and execute a series of instruction operations on the distributed cluster session sharing device 900 to implement the steps of the distributed cluster session sharing method provided in the above-described method embodiments.
[0040] The distributed cluster session sharing device 900 may also include one or more power supplies 940, one or more wired or wireless network interfaces 950, one or more input / output interfaces 960, and / or one or more operating systems 931, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 9 The distributed cluster session sharing device structure shown does not constitute a limitation on the distributed cluster session sharing device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0041] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the steps of a distributed cluster session sharing method.
[0042] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system, device, or unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0043] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0044] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A distributed cluster session sharing method, characterized in that, The distributed cluster session sharing system includes a client, a control unit, multiple service instances, and a storage unit. The client communicates with each service instance through the control unit, and each service instance communicates with the storage unit. The method includes: Obtain the first login request sent by the client and generate a session identifier; The session identifier is returned to the client, and the session identifier is written to the dictionary service cluster of the storage department; Obtain subsequent login requests sent by the client that include the session identifier; The subsequent login requests are validated based on the dictionary service cluster. When the legitimacy verification passes, the subsequent login request is routed to the corresponding business service instance based on the preset routing rules; The service instance is controlled to obtain session data corresponding to the session identifier from the dictionary service cluster in order to complete the user login.
2. The distributed cluster session sharing method according to claim 1, characterized in that, The distributed cluster session sharing system also includes a microservice gateway, through which the control unit communicates with each of the business service instances respectively. The generation of a session identifier based on the initial login request includes: The microservice gateway is controlled to receive the first login request and to route the first login request to the corresponding business service instance based on the routing rules. The first login request includes account and password information. The service instance is controlled to verify the account password information and obtain the verification result. When the information verification result is successful, the business service instance is controlled to trigger the built-in session management component to generate the session data based on the first login request. The session data includes the session identifier.
3. The distributed cluster session sharing method according to claim 2, characterized in that, The account password information includes account information and password information; controlling the business service instance to verify the account password information and obtain the verification result includes: The system controls the business service instance to call a preset user database and verifies the account information based on the user database. When the account information is incorrect, the information verification result is obtained, and the information verification result is failure; When the account information is correct, control the business service instance to verify whether the status of the account information is normal; When the account information is in an abnormal state, the information verification result is obtained, and the information verification result is a failure. When the account information is in a normal state, control the business service instance to verify whether the password information is correct; When the password information is correct, the information verification result is obtained, and the information verification result is passed; When the password information is incorrect, the information verification result is obtained, and the information verification result is failure.
4. The distributed cluster session sharing method according to claim 2, characterized in that, After writing the session identifier into the dictionary service cluster of the storage unit, the method further includes: The dictionary service cluster is controlled to monitor in real time whether the preset TTL expiration time of the session identifier has expired; When the preset TTL expires, the dictionary service cluster will clean up the session data corresponding to the session identifier.
5. The distributed cluster session sharing method according to claim 2, characterized in that, The legitimacy verification of subsequent login requests based on the dictionary service cluster includes: The microservice gateway is controlled to receive the subsequent login request and parse the subsequent login request to obtain the session identifier and the timestamp corresponding to the session identifier; The microservice gateway is controlled to verify the existence of the session identifier based on the dictionary service cluster; When the session identifier exists, the microservice gateway is controlled to verify whether the validity period of the timestamp has expired based on the dictionary service cluster.
6. The distributed cluster session sharing method according to claim 2, characterized in that, The distributed cluster session sharing system also includes an exception handling unit, and the microservice gateway communicates with each of the business service instances through the exception handling unit. After performing validity verification on subsequent login requests based on the dictionary service cluster, the process further includes: When the validity check fails, the microservice gateway is controlled to send the session identifier corresponding to the subsequent login request to the exception handling department. The exception handling unit controls the session identifier to perform exception encoding matching processing based on the preset unified exception enumeration rules to obtain an exception response message; The microservice gateway is controlled to receive the exception response message and return the exception response message to the client.
7. The distributed cluster session sharing method according to claim 6, characterized in that, The distributed cluster session sharing system further includes a load balancer, which is communicatively connected between the microservice gateway and the exception handling unit; after routing subsequent login requests to the corresponding business service instances based on preset routing rules, it also includes: The load balancer is controlled to monitor the running status of the service instance in real time. When the running status of the business service instance is abnormal, the load balancer is controlled to resend the subsequent login request to a new business service instance, and the business service instance identifier of the business service instance with abnormal running status is sent to the exception handling unit. The exception handling unit is controlled to register the abnormal status of the service instance identifier.
8. A distributed cluster session sharing system, characterized in that, The distributed cluster session sharing method according to any one of claims 1-7, the system includes a client, a control unit, a business service instance unit, and a storage unit. The business service instance unit includes multiple business service instances. The client communicates with each of the business service instances through the control unit. Each business service instance communicates with the storage unit. The client sends an initial login request to the business service instance, so that the business service instance generates a session identifier based on the initial login request and returns the session identifier to the client. At the same time, the session identifier is written into the dictionary service cluster of the storage unit. The storage unit is used to perform legality verification on subsequent login requests sent by the client based on the dictionary service cluster. When the legality verification is successful, the client is allowed to route the subsequent login request to the corresponding business service instance based on preset routing rules. The business service instance is used to obtain session data corresponding to the session identifier from the dictionary service cluster to complete the user login.
9. A distributed cluster session sharing device, characterized in that, The distributed cluster session sharing device includes: a memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause the distributed cluster session sharing device to perform the steps of the distributed cluster session sharing method as described in any one of claims 1-7.
10. A computer-readable storage medium storing instructions thereon, characterized in that, When the instructions are executed by the processor, they implement the steps of the distributed cluster session sharing method as described in any one of claims 1-7.