Test data integrity using MySQL Transactions

3

I am using an ecommerce system where you use MySQL Transactions to maintain data integrity , for example in the simultaneous purchase of several customers of the same product where the system needs to decrease inventory and prevent it from being negative.

Technically, how does MySQL control to prevent a user's query from appearing to conflict with that of another user (s) and thus maintaining that integrity?

What is the best practice to test this integrity? Maybe use some HTTP client to generate multiple HTTP requests on which to simulate purchases?

Is there a number of concurrent queries where using Transactions turns out to be unnecessary? If so, from how many concurrent users do we have to worry about integrity using MySQL Transactions?

    
asked by anonymous 05.09.2015 / 02:50

1 answer

0

Before answering your question, note that to ensure the atomicity of your operations in the database, you should be concerned about Isolation Level , that is, ensure that during your purchase the executed selects and subsequent commits are executed atomically, that is, without competition. Note that without this, even with transactions you may still have competition issues.

Another way to solve your problem is to make the code that performs such operations to be synchronized , that is, only one Thread is executed at a time for purchase operations. >

Now, by answering your question, you can create unit tests that perform the same purchase operation on separate Threads . Another way is to use JMeter or gatling > to run these tests.

    
05.09.2015 / 03:30