High-concurrency System Data power and other solutions

Source: Internet
Author: User

High-concurrency System Data power and other solutions

Preface

During system development, repeated data insertion, reupdate, re-transmission, and other problems are often encountered. Because of the complex logic of the application system and the uncertainty of network interaction, this phenomenon may occur, but some logics require idempotent features. Otherwise, the consequences may be severe. For example, duplicate order creation may cause extraordinary problems.

What is the power equality of the system?

Idempotence is a concept in the data, indicating that the result of N transformations is the same as that of 1 transformation.

How can a high-concurrency system ensure idempotence?

1. Query

The query API can be said to be a natural idempotence, Because you query once and twice, there is no data change for the system, so, A query is the same as a query multiple times.

2. MVCC Solution

Multi-version concurrency control, update with condition, and update with conditions. This is also a reasonable choice of optimistic locks during system design. Optimistic locks are implemented through version or other conditions, this ensures that updates are updated in a timely and concurrent manner without too many problems.

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 deduplication tables

If there are a lot of de-duplication involved, for example, there are various business documents in the ERP system, each of which needs to be de-duplicated, at this time, you can create a separate de-duplicated table, when inserting data, insert the deduplication table to ensure unique logic by using the unique index feature of the database.

4. Distributed locks

Take the example of inserting data. If the distribution is a system, it is difficult to build a unique index. For example, if the unique field cannot be determined, a distributed lock can be introduced through a third-party system, insert data or update data in the business system, obtain distributed locks, perform operations, and release the locks. In this way, the thread-concurrent locks are introduced into multiple systems, that is, the solution to the distributed system.

5. delete data

Deleting data only means that the first deletion is the real operation data, and the second or third deletion means that the operation is successful, which guarantees power equality.

6. Unique index of inserted data

The uniqueness of inserted data can be constrained by the Business primary key. For example, in a specific business scenario, the three fields must be unique. Therefore, you can add a unique index to the database table for identification.

There is a scenario, such as the power of the API, such as submitting data and how to control repeated submission. Here we can add a unique identifier in the form or client software for data submission, and then the server, remove duplicates Based on the UUID, so that the unique identifier at the API level can be better achieved.

7. State Machine Power Equality

The business related to the design documents, or task-related business, will certainly involve the state machine, that is, there is a status on the business documents, the status will change under different circumstances, in general, there is a finite state machine. At this time, if the state machine is already in the next state, a change to the previous State will not be able to be changed theoretically. In this case, this guarantees the power of the finite state machine.

The above is the data sorting of High-concurrency System Data power solutions. We will continue to add relevant knowledge in the future. Thank you for your support for this site!

Related Article

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.