Solution of high concurrent system data power and so on _mssql

Source: Internet
Author: User

Objective

In the system development process, often encountered data repeatedly inserted, repeated updates, message resend, and so on, because the application of complex logic and network interaction uncertainty, can lead to this duplication, but some logic is required to have power characteristics, otherwise the consequences will be more serious, such as the creation of duplicate orders, The problem that this time brings is very unusual.

What is the power of the system

Idempotent is a concept in the data, which means that the results of N-Time transformations and 1-times transformations are the same.

How does a high concurrency system guarantee power?

1. Query

Query the API, can be said to be a natural power, because you query once and query two times, for the system, there is no change of data, so, query once and query the same as many times.

2.MVCC Solution

Multi-version concurrency control, update with condition, updated with conditions, which is also in the system design, reasonable choice of optimistic lock, through version or other conditions, to do optimistic lock, so as to ensure that the update in a timely manner in the case of concurrency, there will not be too big problem.

For example: Update table_xxx set name= #name #,version=version+1 where version= #version #, or update table_xxx set quality=quality- #subQuality # where quality-#subQuality # >= 0.

3. Separate to the heavy table

If it involves going to heavy places particularly much, for example, ERP system has a variety of business documents, each business document needs to be heavy, at this time, you can make a separate to heavy table, insert the data, insert to heavy table, using the unique index of the database to ensure the only logic.

4. Distributed lock

Or take the example of inserting data, if the distribution is a system, it is difficult to build a unique index, such as the uniqueness of the field can not be determined, at this time, the introduction of distributed locks, through Third-party systems, in the business system to insert data or update data, acquire distributed locks, then do the operation, then release the lock, This is actually a multithreaded concurrent lock thinking, the introduction of more than one system, that is, distributed systems have to solve the idea.

5. Delete data

Delete data, only the first deletion is the real operation of the data, the second or even the third delete, direct return success, so that the power and so on.

6. Insert unique index of data

The uniqueness of inserting data, which can be constrained by a business primary key, such as a particular business scenario, where three fields are definitely unique, you can add a unique index to the database table to mark it.

Here's a scene, the power of the API level, such as the submission of data, how to control the repeated submissions, here can be submitted in the form of the data form or client software, add a unique indicator, and then the server, according to the UUID to carry out the weight, so that it can better achieve the API level unique identification.

7. State machine Power, etc.

In the design of documents related to the business, or the task-related business, will certainly involve the state machine, that is, the business document has a state, the state in different circumstances will change, in general, there is a finite state machine, at this time, if the state machine is already in the next state, then come to a previous state of change, Theoretically, it cannot be changed, so that the power of the finite state machine is guaranteed.

The above is the high concurrent system data power and other solutions to the data collation, follow-up continue to supplement the relevant knowledge, thank you for your support of this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.