I like the books from the Head First O`Reilly series - they just talk about the difficult. And I try to do the same.
When it comes to databases, the magic words "ACID Requirements" can come up. In an interview or in a developer conversation - not the point. In this article I will talk about what it is, how ACID stands for and what each letter means.
ACID Requirements are a set of requirements that ensure the safety of your data. This is especially important for financial transactions. We don't want to run out of money due to a disconnected connection or a software bug, do we?
See also:
Let's go through each ACID letter and see examples of why an archive is better than 10 different files. And why a transaction is better than 10 separate requests.
Atomicity - Atomicity
Atomicity ensures that each transaction will be executed completely or not at all. Intermediate states are not allowed.
A friend is known in trouble, and a database is in dealing with errors. Oh, if only everything was always good and without mistakes! Then no ACIDs would be needed. But as soon as an error occurs, atomicity becomes very important.
Let's say you decide to send your mom money. When you make a transfer within a bank, what happens:
Your money was debited
Mom was admitted
And let's say we have 2 separate requests. Now let's see what happens when errors occur:
1. — , , .
2. , — . . ... !
. ... , .
, . ? . , , « » « »!
, . ! =)
, . « ». 10 , — , .
Consistency —
, (EOT — end of transaction, ) , , , . , © wikipedia
. , , . : « , ». ( — ).
, :
-
-
— ,
—
:
client
phone
address
«», 3 :
insert into client… -- -
insert into phone…
insert into address…
3 , , 3 .
, , , — . , , « », . , , .
. -, . , « » — , :
phone
client
, . « », , foreign key.
constraint. , « ». :
1. 100, 10
2. — « , X – 100».
3. , ! constraint, , .
4. .
, , . forein , - — . , — . -.
, , - , . , - :
— , , ?
— -, ?
, .
Isolation —
.
, . ? — . , - : « , 100 , ». ? !
. ?
1 : " "
, 500 ..
1 (1 ) 300 .. . 300, 200 = 500 - 300.
2 (2) , 300 .., 1 . , 500, 500 + 300 = 800.
— " " , = 800, 500. " - ". .
2 : " "
, 500 ..
1 300 .. . 300. - 500 ..
2 (2) , 1 .
— , / ..
3 : " "
.
1 . . , (, ).
, - .
2 .
1 . .
- .
4 : ""
.
1 . . , (, ).
, - .
2 / .
1 . .
— .
3- 4- , , — /. .
? . , — .
— . , . , .
:
— . , . , , , .
Durability —
, , , - - . , ? .
:
, ACID, CAP — geekbrains
Well, let me remind you the link to the article " What is a transaction ".
PS - Look for more helpful articles in my blog under the tag “useful” . And useful videos are on my youtube channel