Concurrency Control in Distributed Systems:

Problem :

When multiple users try to book the same seat.

Critical section: In which we are trying to access shared resources.

1st Solution:

Use synchronized blocks for the critical section. This can work on a single machine.

But this will not work in a distributed system because in a distributed system we have multiple processes running on different servers.

What is the usage of Transaction?

  • It help to achieve integrity and avoid inconsistency .

Either all success or rollback.

What is DB locking?

  • It is to make sure that no other transaction update the locked rows.
LockTypeAnother Shared LockAnother Exclusive Lock
Have Shared LockYesNo
Have an exclusive lockNoNo

Shared lock is used for reading a row.

Exclusive Lock : Used for writing purpose : Others can't do anything

Isolation Levels:

Dirty Read:

If a transaction A is reading the data that is written by B and not yet even committed. If transaction B does the rollback, then whatever data read by transaction A is known as dirty read.

Non-Repeatable Read:

If suppose transaction A, Read the same data several times and there is a chance that it reads different value (non-rrepeatable read).

Phantom Read:

If Suppose transaction A, execute some query several times, and there is a chance that the rows returned are different.

Distributed concurency control: