How to ensure high concurrency idempotency?

Idempotence this concept has been said that bad, that is, no matter how many times you perform many times, produce results and return the results are the same.

1, select operation

In the case of the same data, select multiple queries to the operating result is idempotent.

2. Delete operation

Delete the contents of the case statement constant, delete multiple result is the same. But get the return value is not the same.

3. unique index.

To add read dirty data. Such as Alipay account funds, Alipay allows a user to have a PayPal account, the capital account is to give the table a user ID plus a unique index, so a user to add a successful capital account records. When there is a unique index in the table, will add concurrency error, and then re-query it once.

4.token mechanism.

Prevent duplicate submission page.

Operational requirements: data page can only be submitted by clicking once;

Occurs because: due to repeated retransmission click or network, or retransmitted, etc. nginx cause data to be submitted repeated;

Solution: establish practical token cluster plus redis (redis is single-threaded processing to wait in line); single JVM environment: the use of token or token plus redis plus JVM memory.

Process flow: 1, before submitting data need to apply to the service token, token or Van Gogh redis jvm memory, token valid time.

2, after the submission of background check token, delete token generates a new token.

token features: To apply, once effective, can be limiting.

5. Lock

You can use optimistic and pessimistic locking distributed implementation.

Guess you like

Origin www.cnblogs.com/ffdsj/p/12387646.html