Multi-field linkage state machine system for describing complex business scene
By designing a multi-domain linkage state machine system, the problem of multi-domain state machine linkage in complex business scenarios in securities trading systems was solved, realizing efficient and flexible trading system development and high-concurrency, low-latency processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIANGSU SECURITIES
- Filing Date
- 2025-12-19
- Publication Date
- 2026-05-08
AI Technical Summary
Existing technologies lack multi-domain state machine linkage solutions to support complex business scenarios in brokerage trading systems and cannot meet the requirements of high concurrency and low latency.
Design a multi-domain linkage state machine system, including a state machine and process configuration parser, a state machine and process filler, an event queue router, a worker thread pool, and a multi-domain state machine management center. The system achieves flexible combination and sequential processing of state machines through configurability and multi-threading technologies.
It improved development efficiency, reduced development complexity and iteration costs, enhanced system flexibility and scalability, and ensured high concurrency and low latency performance of the transaction system.
Smart Images

Figure CN121998757A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of brokerage trading systems, and particularly to a multi-domain linkage state machine system for describing complex business scenarios. Background Art
[0002] Brokerages focus on the rapid implementation of complex business scenarios and polish the development framework for securities business trading links suitable for the event-driven microservices architecture. The design and development of brokerage trading systems have many difficulties and have high requirements in terms of product diversity, business complexity, expansion flexibility, high concurrency and low latency of trading, etc.
[0003] [[ID=**11**]]The core system of the trading link is the system for generating and managing orders, and the core point of order management is the life cycle management of orders. Order life cycle management includes the management of the order state machine, and before the order state changes driven by external messages, the order needs to complete a series of process management. The processes and state machines of different trading varieties have different parts and also some identical parts. If the identical parts can be abstracted to form common modular components, and then various modular components are combined in a configurable manner to implement the state machines and processes of different trading varieties, the efficiency of building new trading varieties will be greatly improved. For some complex trading scenarios, it may also involve the linkage between multiple state machines, that is, an external message causes a change in one state machine, and this change in the state machine will in turn affect the changes in other associated state machines. Therefore, the linkage between state machines is also a problem that the system needs to solve. The trading scenarios and deployment environments may require the system to use different types of worker thread queue models for processing, and various thread queue models that can be flexibly configured in various scenarios are needed.
[0004] Existing open-source state machine frameworks such as spring statemachine and squirrel-foundation have relatively complete state machine description functions, but they do not have the ability of process parsing and process orchestration, and no solution suitable for the complex business scenarios of brokerage trading systems and supporting the linkage between state machines in multiple domains can be found in the existing frameworks and technologies. In the trading field of brokerages, the business not only has complex state machines, but also has the linkage between multiple associated state machines, and the brokerage trading system also has relatively high requirements for latency and throughput. Summary of the Invention
[0005] The technical problem to be solved by the present invention is: to provide a multi-domain linkage state machine system for describing complex business scenarios. This system needs to meet the following core requirements:
[0006] Note: There seems to be a formatting issue with the numbering in the original text. The numbering jumps from 11 directly to 12 without 11 being in a proper numbered list format in the original. I've translated it as it is but this might need to be adjusted depending on the correct formatting requirements.(1) Configurable state machine + process parsing: It has a state machine + process parsing engine, which can realize order lifecycle management in various business scenarios through modularization and configuration.
[0007] (2) Support for multi-domain state machine linkage: It is necessary to support linkage operations between multiple state machines;
[0008] (3) Use multithreading technology and maintain order: Use multithreading concurrency technology to improve system performance and increase system throughput, but it is necessary to ensure that the processing order of the same order and the order of receiving external requests are consistent.
[0009] (4) Flexibility and scalability: The system should have good flexibility and scalability to adapt to changes in future transaction business scenarios.
[0010] To solve the above problems, the present invention adopts the following technical solution:
[0011] First, this invention proposes a multi-domain linkage state machine system for describing complex business scenarios, comprising:
[0012] A state machine and process configuration parser is used to load and parse configuration files to obtain the configuration definitions of state machines and processes.
[0013] State machines and process fillers are used to convert external business requests into internal events through an internal and external model conversion factory, and to fill the corresponding state machines and processes for the internal events.
[0014] An event queue router is used to route internal events to a specified worker thread queue based on a unique service number.
[0015] A worker thread pool is used to concurrently execute internal events in the worker thread queue;
[0016] A process execution engine is used to execute the processes populated in the internal events;
[0017] The multi-domain state machine management center is used to drive the state machine transition and automatically trigger the linkage operation of associated state machines when a state transition triggers a linkage condition.
[0018] Preferably, the multi-domain state machine management center is configured to perform the following steps:
[0019] After the process execution engine completes the process execution of an internal event, it receives the internal event and performs a state reversal operation on the associated state machine.
[0020] When it is determined that a state transition operation will affect at least one other associated state machine, the context data corresponding to the associated state machine is retrieved from the context structure stored in memory.
[0021] The found context data is encapsulated into an internal event that describes the changes in the linked state machine, and the event is sent to the event queue router.
[0022] The event queue router, worker thread pool, process execution engine, and multi-domain state machine management center sequentially process the encapsulated event, execute the process it fills, and drive the corresponding state machine to perform state transitions, thereby completing the linkage between multi-domain state machines.
[0023] Preferably, the event queue router uses the unique order number as the routing number and employs a hash consistency algorithm for routing to ensure that events for the same order are routed to the same worker thread queue for sequential execution.
[0024] Preferably, the system further includes a thread queue model assembler for assembling a thread queue model for the worker thread pool; the thread queue model includes at least one of a single-threaded queue model, a lock-free queue thread model, a Disruptor thread queue model, and a priority-based lock-free queue thread model.
[0025] Preferably, the priority-based lock-free queue thread model adopts a lock-free queue based on ConcurrentSkipListSet that supports priority sorting.
[0026] Preferably, the state machine and process configuration parser convert configuration data into internal static data instances and place them in memory.
[0027] Meanwhile, this invention proposes a brokerage trading system implemented using the aforementioned multi-domain linkage state machine system. The external business request in the state machine and process filler is an order request. In the multi-domain state machine management center, the multi-domain includes a quotation request domain and a quotation domain.
[0028] Meanwhile, the present invention proposes a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the operation of the multi-domain linkage state machine system described in the present invention.
[0029] Furthermore, the present invention proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed, it implements the operation of the multi-domain linkage state machine system as described in the present invention.
[0030] Finally, this invention proposes a computer program product, including a computer program / instruction, which, when executed by a processor, implements the operation of the multi-domain linkage state machine system as described in this invention.
[0031] The present invention adopts the above technical solution and has the following technical effects compared with the prior art.
[0032] (1) The state machine and process execution engine involved in this invention can abstract the business capabilities accumulated in different business scenarios into reusable components. These components can be orchestrated into multiple business scenarios for reuse. As the number of supported scenarios increases and the system functions are continuously enhanced, when adding new business scenarios in the future, it is only necessary to arrange and combine the existing functional components without writing a lot of new code, which significantly improves development and maintenance efficiency.
[0033] (2) This invention allows for flexible orchestration of state machines and process components through a configurable approach, enabling the rapid construction of different transaction scenarios. When adding new transaction services, the required business scenario can be formed simply by configuring and aggregating the functional components, significantly reducing development complexity and iteration costs.
[0034] (3) The state machine and process execution engine involved in this invention aggregate different capabilities into single functional components according to their responsibilities, such as verification, assembly, and calculation, each performing its own function, thereby improving the clarity and maintainability of the code structure.
[0035] (4) By reusing existing capabilities and only coding a small number of new capabilities, the present invention can quickly complete the construction of business processes and continuously accumulate new business capabilities to meet subsequent demand iterations, thereby effectively shortening the project development cycle and promoting the continuous evolution of the system.
[0036] (5) This invention standardizes the coding method and guides developers to focus on the design of business process lines and the implementation of functional points. Following the principle that "all business processes can be programmed", the process lines are designed first and then the functional points are implemented, which is conducive to team collaboration and the decomposition of development tasks, and improves the overall development efficiency and quality. Attached Figure Description
[0037] Figure 1 This invention relates to a schematic diagram of a multi-domain linkage state machine system structure that describes complex business scenarios.
[0038] Figure 2 This is a schematic diagram of the internal structure of the system after introducing a state machine and a process orchestration engine, as described in the embodiment.
[0039] Figure 3 This is a schematic diagram of a single-threaded queue model involved in an embodiment.
[0040] Figure 4This is a schematic diagram of the Disruptor thread queue model involved in the embodiment.
[0041] Figure 5 This is a schematic diagram of the lock-free queue thread model involved in the embodiment. Detailed Implementation
[0042] The technical solution of the present invention will be described in detail below with reference to the accompanying drawings.
[0043] Example 1: To address the state machine linkage problem in complex business scenarios within the securities trading sector, this example provides a novel multi-domain linkage state machine system. This system not only effectively solves the complex problem of multi-domain state machine linkage but also significantly improves development efficiency, enabling the standardization and normalization of business service development. (Reference) Figure 1 The processing flow of the entire multi-domain linkage state machine system is as follows:
[0044] (1) Loading state machine and process configuration: When the system starts, it loads and obtains relevant data of state machine and process configuration from the local configuration file, and then converts the configuration data into internal static data instances and places them in memory through the state machine and process configuration parser.
[0045] (2) State machine and process filling: The order system receives external order requests through the request listener, converts them into internal events through the internal and external model conversion factory, and then fills the internal events with the state machine and corresponding processing flow corresponding to the business type through the state machine and process filler according to the different business types of the order, and puts the event-related information in a memory context storage structure.
[0046] (3) Thread pool execution of internal events: The internal events will be executed by the process execution engine and the state machine management center. These are the core processes of the order system and need to be executed concurrently to improve performance. Therefore, the encapsulated and filled internal events are put into the worker thread pool to execute the subsequent core operations.
[0047] (4) Event queue router distribution: In order to ensure that events of the same order are executed in sequence, the unique order number is used as the routing number and the hash consistency algorithm is adopted so that the internal events of the same order are queued in the same worker thread queue, thus ensuring the order of execution of events of the same order.
[0048] (5) Execution of the process engine: Internal events pass through the process execution engine, which automatically executes each configured process by parsing the execution process information filled in the event.
[0049] (6) State machine transition: After the process is completed, the internal events are sent to the multi-domain state machine management center for corresponding state machine reversal operations. For example... Figure 2 As shown, if it is found that the torsion of this state machine will affect the changes of other state machines, the corresponding context data is found in the context structure stored in memory, and encapsulated as an internal event of the linkage state machine change is sent to the event queue router. After routing, it enters the worker thread pool for execution. Since the found context structures are all filled by state machines and processes, the corresponding processes and state torsions will also be executed through the process execution engine and the state machine management center. In this way, the linkage of state machines in multiple domains is completed.
[0050] The worker thread pool handles the core business logic of the system. To meet the needs of different use cases, different thread queue models can be flexibly assembled through the thread and queue model assembler. Currently supported thread queue models include: single-threaded queue model, lock-free queue thread model, Disruptor thread queue model, and priority-based lock-free queue thread model.
[0051] The most important aspect of this system is that it solves the problem of linkage between state machines in multiple domains. Specifically, multiple domains refer to multiple domain entities divided according to the DDD domain design. Each domain entity can maintain its own state machine. At any given time, each domain entity is in a certain state of its own state machine without interfering with each other. However, when some domain entities change state, state machine linkage is involved. That is, the change of the state machine of one domain entity needs to affect the change of the state machine of another domain entity.
[0052] In interbank bond quotation requests, the linkage of multi-domain state machines has been widely applied, and the process is as follows:
[0053] (1) Domain entity division
[0054] In the scenario of requesting a quote on a current bond, we use Domain-Driven Design (DDD) to abstract the quote request and the quote into two domain context entities: QuoteRequest (requesting a quote) and Quote (quoting a quote).
[0055] (2) State machine isolation
[0056] The different domain context entities defined above are equipped with different state machines and processes. The state machines and processes corresponding to the two domain context entities are completely different and isolated from each other.
[0057] (3) Packaging-related events
[0058] When the state of a Quote changes, such as from active to completed, the Quote context entity will find the corresponding QuoteRequest context entity through the associated QuoteRequestId, encapsulate an internal completed event containing the QuoteRequest context entity, and then send the completed event to the underlying worker thread pool to queue for execution.
[0059] (4) Complete the linkage of the state machine
[0060] Once the corresponding worker thread becomes idle, it acquires the transaction event and hands it over to the process execution engine and state machine management center for processing. The QuoteRequest context entity in the transaction event has its own corresponding state machine and process. Then, the process execution engine executes the corresponding process, and the state machine management center reverses its state to the transaction state. In this way, the state machine linkage between the Quote and QuoteRequest states and the transaction state is finally completed.
[0061] In addition, the thread queue assembler can be used to assemble the implemented worker thread queue model according to different business scenario requirements, which greatly improves development efficiency and solves the complex development and debugging problems in the underlying thread queue model.
[0062] (1) Single-threaded queue model
[0063] like Figure 3 As shown, this thread queue model is the simplest and least error-prone because it uses a single thread and a single queue for processing. Message events received in sequence will wait in the queue for processing, and all message events are executed sequentially. While this thread queue model cannot leverage the multi-core processors of a server to improve throughput, it eliminates the need for locking, makes the code easy to maintain, and reduces the likelihood of program errors.
[0064] (2) Disruptor thread queue model
[0065] like Figure 4 As shown, the Disruptor thread group is actually a group of Disruptors. Each Disruptor has only one thread. The event is routed to a fixed Disruptor based on the hash consistency of the key. In this way, the enqueueing and dequeueing of events are lock-free, and the events of the same Disruptor are also executed sequentially.
[0066] Disruptor offers superior performance, but since it cannot support prioritizing events, the Disruptor thread queue model can be used in scenarios where event priority is not required.
[0067] (3) Lock-free queue thread model
[0068] like Figure 5 As shown, the lock-free queue thread model has high performance, and this embodiment also developed a lock-free queue thread model that supports event priority sorting.
[0069] If event sorting is not required, use the MpscLinkedQueue lock-free queue. This lock-free queue uses the Compare-and-Swap (CAS) principle to achieve thread-safe lock-free enqueue and dequeue processing.
[0070] If event sorting functionality is required, this embodiment provides a lock-free queue, NonBlockingPriorityQueue, which can sort events. This lock-free queue uses ConcurrentSkipListSet, which allows thread-safe enqueueing and dequeueing, and employs a skip list data structure to sort events by priority. The skip list is a simplified version of a red-black tree implemented under thread-safe conditions, thus achieving both event sorting and thread safety.
[0071] Example 2: This example demonstrates how the system of the present invention manages the state machines and their complex linkages in the core securities trading business of transaction orders, fund accounts, and securities holdings.
[0072] Step 1: Order Creation and Fund Freeze. A user's buy request triggers an internal event, which is ordered via an event queue router. The process execution engine sequentially performs risk control checks and fund availability verification. Upon success, the multi-domain state machine management center sets the order status to pending and automatically generates a linked event, driving the corresponding funds in the fund account to change to frozen status.
[0073] Step 2: Transaction Report and Position Update. The exchange's transaction report arrives, triggering a new event. The process engine executes the transaction confirmation process. The state machine center changes the order status to "completed." Subsequently, the system automatically detects and triggers a dual linkage:
[0074] Generate a new funding event: deduct the frozen funds and complete the payment;
[0075] Generate holding event: Increase the holding quantity of the corresponding security.
[0076] Step 3: Exception Handling Linkage. If an order is ultimately rejected, the state machine center will automatically trigger a linkage mechanism when reversing the order status to rejected, generating a funds unfreezing event to ensure the funds are restored synchronously.
[0077] This embodiment demonstrates how an external request can trigger an automated, sequential state transition across three domains through this system.
[0078] Example 3: This example proposes a computer-readable storage medium storing a computer program thereon. When the program is executed by a processor, it implements the operation of the multi-domain linkage state machine system as described in Example 1.
[0079] Example 4: This example proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed, it implements the operation of the multi-domain linkage state machine system as described in Example 1.
[0080] Example 5: This example proposes a computer program product, including a computer program / instruction, which, when executed by a processor, implements the operation of the multi-domain linkage state machine system as described in Example 1.
[0081] It should be noted that the processing flow of embodiments 2-5 corresponds to the operation of the corresponding functional modules and beneficial effects of the multi-domain linkage state machine system described in embodiment 1 of the present invention. Technical details not described in detail in this embodiment can be found in the system provided in embodiment 1 of the present invention.
[0082] The specific implementation schemes described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific implementation schemes of the present invention and are not intended to limit the scope of the present invention. Any equivalent changes and modifications made by those skilled in the art without departing from the concept and principles of the present invention should fall within the scope of protection of the present invention.
Claims
1. A multi-domain linkage state machine system for describing complex business scenarios, characterized in that, include: A state machine and process configuration parser is used to load and parse configuration files to obtain the configuration definitions of state machines and processes. State machines and process fillers are used to convert external business requests into internal events through an internal and external model conversion factory, and to fill the corresponding state machines and processes for the internal events. An event queue router is used to route internal events to a specified worker thread queue based on a unique service number. A worker thread pool is used to concurrently execute internal events in the worker thread queue; A process execution engine is used to execute the processes populated in the internal events; The multi-domain state machine management center is used to drive the state machine transition and automatically trigger the linkage operation of associated state machines when a state transition triggers a linkage condition.
2. The multi-domain linkage state machine system for describing complex business scenarios according to claim 1, characterized in that, The multi-domain state machine management center is configured to perform the following steps: After the process execution engine completes the process execution of an internal event, it receives the internal event and performs a state reversal operation on the associated state machine. When it is determined that a state transition operation will affect at least one other associated state machine, the context data corresponding to the associated state machine is retrieved from the context structure stored in memory. The found context data is encapsulated into an internal event that describes the changes in the linked state machine, and the event is sent to the event queue router. The event queue router, worker thread pool, process execution engine, and multi-domain state machine management center sequentially process the encapsulated event, execute the process it fills, and drive the corresponding state machine to perform state transitions, thereby completing the linkage between multi-domain state machines.
3. The multi-domain linkage state machine system for describing complex business scenarios according to claim 1, characterized in that, The event queue router uses the unique order number as the routing number and employs a hash consistency algorithm for routing to ensure that events for the same order are routed to the same worker thread queue for sequential execution.
4. A multi-domain linkage state machine system for describing complex business scenarios according to claim 1, characterized in that, The system also includes a thread queue model assembler for assembling thread queue models for the worker thread pool; the thread queue model includes at least one of a single-threaded queue model, a lock-free queue thread model, a Disruptor thread queue model, and a priority-based lock-free queue thread model.
5. A multi-domain linkage state machine system for describing complex business scenarios according to claim 4, characterized in that, The priority-based lock-free queue thread model is implemented using a lock-free queue that supports priority sorting and is based on ConcurrentSkipListSet.
6. A multi-domain linkage state machine system for describing complex business scenarios according to claim 1, characterized in that, The state machine and process configuration parser convert configuration data into internal static data instances and place them in memory.
7. A brokerage trading system implemented using the multi-domain linkage state machine system described in any one of claims 1-6, characterized in that, The external business request in the state machine and process filler is an order request. In the multi-domain state machine management center, the multi-domain includes the quotation request domain and the quotation domain.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the operation of the multi-domain linkage state machine system as described in any one of claims 1 to 7.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is executed, it implements the operation of the multi-domain linkage state machine system as described in any one of claims 1 to 7.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the operation of the multi-domain linkage state machine system as described in any one of claims 1 to 7.