DURABILITY

Let me explain durability using accounts table

First, we have accounts table

Alice = 1000
Bob = 500

since, now we perform a normal money transfer.

BEGIN;

UPDATE accounts
SET balance = balance - 300
WHERE name = 'Alice';

UPDATE accounts
SET balance = balance + 300
WHERE name = 'Bob';

COMMIT;

since, we deduct from Alice and add to Bob.. and commit the transaction.

After transaction:

Alice = 700
Bob = 800

since, changes are successfully saved.

Now we simulate system restart (like closing and reopening database).

Reconnect and check data:

SELECT * FROM accounts;

Result:

Alice = 700
Bob = 800

since, even after restart.. data is still there.

Final understanding:

since, once COMMIT is done.. changes are permanently saved in database

this is called durability

Now think about failure cases

If failure happens before COMMIT:

since, transaction is not completed.. changes will not be saved

so, data remains old

If failure happens after COMMIT:

since, commit is already done.. data will not be lost

database ensures it is saved

because of this,

money will not disappear
no incorrect balance after crash
system remains safe

this is why payment apps depend on durability.

Comments

Popular posts from this blog

THE DELIVERY MAN

EC2 LAUNCHING

SORT A LINKED LIST USING MERGE SORT