Тёмный

System Design: Concurrency Control in Distributed System | Optimistic & Pessimistic Concurrency Lock 

Concept && Coding - by Shrayansh
Подписаться 103 тыс.
Просмотров 55 тыс.
50% 1

➡️ Notes: Shared in the Member Community Post (If you are Member of this channel, then pls check the Member community post, i have shared the Notes link there)
➡️ Join this channel to get access to member only perks:
/ @conceptandcoding
Topics i have covered:
- Problem statement
- Synchronized keyword solution
- What is Transaction
- What is DB Locking and its Type
- What are Isolation Level
- Distributed Concurrency Control Techniques
Chapters:
00:00 - Introduction
00:43 - Problem Statement
02:47 - SYNCHRONIZED
07:05 - What is usage of TRANSACTION
11:15 - What is DB LOCKING (Shared and Exclusive Locking)
15:47 - ISOLATION Property Introduction
18:31 - DIRTY Read Problem
22:58 - NON-REPEATABLE Read Problem
25:31 - PHANTOM Read Problem
27:41 - 1st Isolation Level: READ UNCOMMITTED
31:43 - 2nd Isolation Level: READ COMMITTED
36:53 - 3rd Isolation Level: REPEATABLE READ
39:38 - 4th Isolation Level: SERIALIZABLE
45:57 - Optimistic Concurrency Control
53:26 - Pessimistic Concurrency Control
#concurrency #systemdesign #softwareengineer

Опубликовано:

 

8 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 215   
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
In Isolation Level Table: I meant Concurrency but instead i wrote Consistency. Read Uncommitted has high Concurrency and Serializable has Least Concurrency.
@akramwasim805
@akramwasim805 11 месяцев назад
I was about to post it 😀
@panmenia
@panmenia 11 месяцев назад
hi Shreyansh. Great video. When is the 2 phase locking video coming? And do you mean 2 phase commit by 2 phase locking?
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
@@panmenia no two phase commit is different and two phase locking is different
@tarunkundhiya5196
@tarunkundhiya5196 11 месяцев назад
@shreyansh you can consider adding an on-video note.
@basantrawat4279
@basantrawat4279 10 месяцев назад
@@ConceptandCoding Hi sir because of you I was able to crack lld ,hld rounds in companies like amex,paytm payments bank, cars24,clearTax and all and joiner paytm payments bank.Thank you so much sir for all your videos and content
@shrutikamboj4607
@shrutikamboj4607 5 месяцев назад
Extremely underrated playlist!! So happy to stumble upon it.
@ConceptandCoding
@ConceptandCoding 5 месяцев назад
Thanks for your feedback
@thisthatgirl5060
@thisthatgirl5060 10 месяцев назад
Truely a gem. Thanks for makling this series, I could learn the most difficult low level system design just because of you. May god bless you
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Thank you
@saurabhtiwari9614
@saurabhtiwari9614 11 месяцев назад
i'm really blessed for having u as my teacher and thanks for clearing all my doubts. thank u soo soo much bhayiyaaa
@basantrawat4279
@basantrawat4279 10 месяцев назад
Hi sir because of you I was able to crack lld ,hld rounds in companies like amex,paytm payments bank, cars24,clearTax and all and joiner paytm payments bank.Thank you so much sir for all your videos and content
@car_holic1995
@car_holic1995 10 месяцев назад
Congratulations bhai...can I get your mail for some guidance bhai.
@nishantkumar6116
@nishantkumar6116 9 месяцев назад
This video is a gem, got to know lot of concept in this 1 hr video. Thank you @Shreyans for making such videos. These contents need to be reached to larger groups surprised to see only 13k views on it
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
thanks for the feedback buddy
@mr_world_wide
@mr_world_wide 11 месяцев назад
Essential topic for understanding what your system might be doing, but rarely used in day to day tasks
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
This topic is very very frequently used buddy in day to day work.
@mr_world_wide
@mr_world_wide 11 месяцев назад
Optimistic and pessimistic locking yes, but the mvcc is taken care by the database.
@meharwaheed4742
@meharwaheed4742 2 месяца назад
Very interesting. I've learned a lot. Thank You
@user-og7de8ih4f
@user-og7de8ih4f 8 месяцев назад
Outstanding video Sir, and the way you explain in depth about the problem and solution is exceptional❤❤
@ConceptandCoding
@ConceptandCoding 8 месяцев назад
Thanks
@rahulsaini202
@rahulsaini202 11 месяцев назад
@ConceptandCoding informative Video, depth explained. Please share the notes. It will be handy during the preparation of interviews. 🙏
@vineettalashi
@vineettalashi 4 месяца назад
Thank you for this very informative and knowledgeable session.
@ConceptandCoding
@ConceptandCoding 4 месяца назад
thanks
@kumarashutosh229
@kumarashutosh229 9 месяцев назад
Nice stuff! To add to it, the `Serializable` isolation level has the lowest efficiency/concurrency because it processes the tasks submitted to it in a sequential or serial fashion. It picks the tasks in the `ORDER OF SUBMISION` from the queue, and that's why it guarantees correctness.
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
Right
@ANSHULGUPTA880
@ANSHULGUPTA880 10 месяцев назад
Thanks bro for this video. 1 Question, isolation level is working fine multiple application instances. But what if DB is also distributed, with active-active connection (2 primary DB)?
@tejass5060
@tejass5060 11 месяцев назад
Hey Shreyansh, Thanks for discussing the important topic it'll definitely help a lot of backend engineers. I just wanted to point something on consistency, I think consistency is low for "Read Uncommitted" isolation level and High for "Serializable"
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Nope it's opposite. Serializable has the least concurrency as it use range lock.
@vivekjha6990
@vivekjha6990 11 месяцев назад
Actually it is written "consistency" in the notes, but what Shrayansh meant is "concurrency"..
@tejass5060
@tejass5060 11 месяцев назад
@@ConceptandCoding Yes, in notes it is mentioned as "consistency" next to the table but it should have been "concurrency". Anyways, mentioning it here so that people can get clarity on that.
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Oops my bad. Just now saw it again. Sorry for this
@tejass5060
@tejass5060 11 месяцев назад
No need to be sorry you have done a good job discussing this topic we appreciate your efforts and corrections can be done in the comments section.
@akramwasim805
@akramwasim805 11 месяцев назад
Nice Explanation, Keep up the momentum.
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Thank you
@Newbie789
@Newbie789 4 месяца назад
Shaandar jabardust jindabaad very clear explanation thank you 🙏🙏
@ConceptandCoding
@ConceptandCoding 4 месяца назад
thanks
@manojkumar-dv8pf
@manojkumar-dv8pf 8 месяцев назад
Hey Shreyansh, Can you please explain the Range lock? Is this a lock on the whole table or what? In a transaction, I can have a query `select * from table1 where name='abc'` which can be executed more than one time. And I don't want a phantom read issue. Then I am left with 2 kinds of isolation levels - snapshot isolation and serializable isolation. In snapshot isolation, the DB can create a snapshot for my transaction and I will only see that snapshot in my whole transaction. In serializable isolation There should be a lock on the whole table, then only phantom read can be avoided.
@shubhampatidar6116
@shubhampatidar6116 Месяц назад
Thanks Shrayanah Bhai
@av21015
@av21015 10 месяцев назад
You have such an in-depth knowledge, great video. I have this doubt when you said no chance of deadlock in OCC when TA has to write on row 1,2 and TB has to write on 2,1 after first step if TA takes exclusive lock on 1 and TB takes exclusive lock on 2 and for second step both cant proceed as the shared resources needed are locked then in that case we get a deadlock even in OCC.
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Yes, i think the best way to say is OOC reduce the probability of deadlock, rather than it fully removes it.
@vishnuvadhandevandla4110
@vishnuvadhandevandla4110 10 месяцев назад
really you way of explanation awesome 👌now i got very much clarity how transactions happening because i saw so many videos this much explanation i never seen , really thanks so much once again , one request pls provide English version of lld
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Thanks, all latest videos of LLD are in English only and few initial which are in hindi, i have explained in English in LLD live playlist
@himanshubhandari7222
@himanshubhandari7222 5 месяцев назад
In pcc, If some transaction has started (say T1) and then we are reading a row (say row A) then T1 itself won’t be able to update row A, as there is shared lock already on it.. Am I correct..?
@awadeshtalks
@awadeshtalks 28 дней назад
Hey @shrayansh, I have a question please clarify. If only read is required, then I think no isolation required, then when this Read Committed isolation will be used?
@mariselvamdheivasigamani578
@mariselvamdheivasigamani578 2 месяца назад
nicely explained
@chellimalayilradhakrishnan7872
@chellimalayilradhakrishnan7872 2 месяца назад
Awesome explanation
@akshaymahajan9626
@akshaymahajan9626 4 месяца назад
Very well explained !
@ConceptandCoding
@ConceptandCoding 4 месяца назад
thanks
@abhinavsinghal1530
@abhinavsinghal1530 3 месяца назад
For read uncommitted, why does it have highest consistency?? Shouldn't it be the lowest?
@AtharvaRao0104
@AtharvaRao0104 Месяц назад
Also at the end, when you show optimistic concurrency control can prevent deadlocks - If the isolation level was SSI instead of read committed: In transaction 2, The read of B will be outdated because of the commit by T1 as there is a new version of B. If a stale value of B was used to make some decision and that decision involves writing to A, then the decision becomes invalid. I think, the algorithm of optimistic concurrency control atleast in SSI will detect that the read of B has become stale and T2 will be aborted and T2 would have to be retried.
@roufshaik3530
@roufshaik3530 9 месяцев назад
Great content Shreyansh, I think after deadlock detection not every DB aborts all the transactions. For instance Postgresql aborts the transaction based on the victim selection and executes the other transactions post lock release
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
True depends upon locking mechanism.
@aneksingh4496
@aneksingh4496 10 месяцев назад
Very nicely explained....
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Thank you
@vivekjha6990
@vivekjha6990 11 месяцев назад
Can you provide a brief overview on the transaction isolation levels that is employed in systems like BookMyShow and Tatkal booking on IRCTC to handle concurrency during their respective booking processes? I think strict isolation level like SERIALIZABLE suits best for BookMyShow to avoid phantom reads by applying range lock, because here the requirement is - user should get the ticket either Booked or Not Booked, there is no concept of Waiting ticket. But in terms of IRCTC Tatkal booking, there is short window of time with lot of concurrent requests and Waiting ticket is also a thing, So To trade of System performance, do you think they apply less strict Isolation Level?? ( Not sure on this- but they allow some level of incorrect reads, if we check ticket availability status on 2 laptops, one shows available, but when you book with other at the same time, it can give Waiting ticket),
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
In my view, BookMyShow might be using optimistic concurrency Control (with Read Committed) isolation level. Couple of reasons: 1. As you and me can select same seat at the same time but at the time of checkout one of us will see the issue. 2. I can select/ unselect multiple seats, i can not put locks on all seats, as you know, in pessimistic if lock is put it will be released only after end of txn. So optimistic is the best option. For IRCTC, i will think and get back to you (but seems very similar to BookMyshow usecase only)
@shivashankarm78
@shivashankarm78 8 месяцев назад
Hi @Shreyansh, First of all a very big Thanks for all your efforts for educating the community. My doubt is platforms like BookmyShow and IRCTC, we can also book multiple seats in single transaction right. Shouldnt we use Serailizable isolation level as it involves range of seats to be booked.
@NeverGiveUp186
@NeverGiveUp186 10 месяцев назад
Great video as always Shrayansh!! Thanks a lot! I had one doubt though. How do we go about acquiring locks in case of replicated dbs ? For example, lets say I acquired an exclusive lock on row1 in db1, but some other server gets redirected to db2, and the user is able to update row1 in that replica. Can you please explain in brief about this ? Thanks!
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
There are distributed lock mechanism like usage of Zookeeper, which will send the msg to all the active dbs that put a lock on this data. There are other mechanism too , will cover that may be in separate video buddy
@NeverGiveUp186
@NeverGiveUp186 10 месяцев назад
@@ConceptandCoding Ohh..ok. Thanks for the response!
@vyshnavramesh9305
@vyshnavramesh9305 4 месяца назад
​@@ConceptandCodingIsn't Zookeper to hold locks for multiple nodes of the microservice? I don't think Zookeeper has any relation with database or its replicas.
@rahuljha8038
@rahuljha8038 11 месяцев назад
very helpful video
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Thanks
@anusuyaganguly6009
@anusuyaganguly6009 8 месяцев назад
Very useful content .Waiting for your 2-phase locking session
@ConceptandCoding
@ConceptandCoding 8 месяцев назад
It's already there
@prajyotlawande193
@prajyotlawande193 8 месяцев назад
Hi Shrayansh, the default isolation level in MySQL is REPEATABLE_READ. So, if we have to use optimistic locking in MySQL, is it required to change the isolation level to READ_COMMITTED first?
@ConceptandCoding
@ConceptandCoding 8 месяцев назад
Optimistic runs below Repeatable read. We can define the isolation level while creating the Txn.
@Vinod-zs4dj
@Vinod-zs4dj Месяц назад
how can you say that consistency is high on read uncommitted isolation ?? let say transaction t1 and t2 is there, and t2 made some change and didn't commit and rolled that back so dirty read would be there by t1 which an inconsistency case because latest changes are not there in DB.
@anupamjaiswal299
@anupamjaiswal299 11 месяцев назад
How can one transaction can read uncommited changes ... will they be under same session?
@garimadhanania1853
@garimadhanania1853 Месяц назад
thank you!!
@manoharmanu9240
@manoharmanu9240 2 месяца назад
Great explanation👏👏
@ConceptandCoding
@ConceptandCoding 2 месяца назад
thanks
@kent.johnson
@kent.johnson 6 месяцев назад
Great content
@ConceptandCoding
@ConceptandCoding 6 месяцев назад
Thanks
@ankitgupta-ph4nk
@ankitgupta-ph4nk 11 месяцев назад
Very well explained.. Thanks Brother.. But can you how to take the shared and exclusive lock on table/resource in distributed env
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Select for update query, Insert, update query put Exclusive lock. Normal select query internally put shared lock based on Isolation Level set for the txn.
@swarnenduhazra6094
@swarnenduhazra6094 Месяц назад
41:14 why lock 4 ? when the query clearly makes the range and inclusive both the limits .. locking the range 1-3 makes sense though.. someone please clarify this
@mayankkumarprajapati2337
@mayankkumarprajapati2337 6 месяцев назад
hi shreyanh ,wanted to ask a question, the following video could be answer to a scenario where multiple resources are trying to access a shared resource to compute on it right?
@ConceptandCoding
@ConceptandCoding 6 месяцев назад
Yes
@vyshnavramesh9305
@vyshnavramesh9305 4 месяца назад
​@@ConceptandCodingIsn't Zookeper (ZAB) solving the same problem? I think consensus algorithms like AB, RAFT, PAXOS solve the same
@kamalkishorsharma6406
@kamalkishorsharma6406 10 месяцев назад
Awesome video
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Thanks!
@shashisharma307
@shashisharma307 17 дней назад
Since Transactions are atomic, how come TA reads the data written by TB which is not yet committed, can anyone help me to understand?
@bangbang86
@bangbang86 11 месяцев назад
I appreciate you sharing knowledge. I think optimistic locking is essentially lock free, decision to commit or rollback depends on version values In your video you have mentioned that optimistic locking uses SELECT FOR UPDATE, this is inaccurate, taking a lock means pessimistic locking
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
I am not inline with it buddy. While comparing the version, that time you have to take lock else how you will handle the scenario when 2 request read and compare the version with DB at same time too? Both will go ahead and update the DB and "Lost Update" issue will arise. But glad you raised the point.
@bangbang86
@bangbang86 11 месяцев назад
@@ConceptandCoding the way it is done is let say we have 2 sessions trying to update a row with primary key R1 and with Version V10 Both sessions will read V10 version and will try to update the row using following UPDATE SQL pattern UPDATE table SET someCol=someVal WHERE primaryKey=R1 AND version=V10 Since both sessions are firing the SQL, there will be a race condition and one will succeed and update one row while the other will update 0 rows, the session which updated 0 rows now knows that its update failed and it throws an exception(ORM such as Hibernate throw OptimisticLockException) As a programmer we can choose to retry this request being OPTIMISTIC that there will not a race condition again and its request will succeed this time.
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
@@bangbang86 make sense, as DB for each insert/update puts lock and during race condition one will fail. Generally handling this at application is faster than at DB. As you know that, in real code, application never directly connects with DB, there is one mediator which do lot of stuff like grouping of queries, diverting the query so that one DB server do not get overload etc. I am totally agree with your point, but i still feel handling this at application layer is much better. What do you think?
@bangbang86
@bangbang86 11 месяцев назад
@@ConceptandCoding in any real world application there will be at least two application servers for fault tolerance and in such a scenario if the two requests working on same entity for e.g. user bank balance row, land on different app servers then it is impossible to do concurrency handling on app side since the conflicting requests lie outside the scope of each app server. This is why concurrency handling on common/converging part such as DB or any datastore is a better option as it has context of every request and is the place which stores the state of the entity. Hope I was able to explain my thought.
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Agree, and that's why we are discussing distributed locking mechanism (lock on DB rather than distributed synchronised which app server do). But we both agree here now, optimistic is not actually Lock free. It does put a lock during update/insert :)
@pavankumar-cy6mg
@pavankumar-cy6mg 4 месяца назад
hi, @conceptandcoding, in OCC you have said that no deadlock is possible, take this case ID:1 and ID:2 ,Trans-A has acquired ex-lock on ID1 and trans-B has acquired ex-lock on ID2 after that Trans-A wants to put a shared lock on the ID2 and Trans-B wants to put a lock on ID1, in this case it is a deadlock right?
@ConceptandCoding
@ConceptandCoding 4 месяца назад
hi Pavan, pls check in comment section my discussion with @bangbang86 member. That will clarify your doubts fully. let me know if you able to find and got your answer.
@pavankumar-cy6mg
@pavankumar-cy6mg 4 месяца назад
@@ConceptandCoding i gone through all the conversation, it means that OCC never acquires the lock at all and it only checks while writing the data has been modified or not? am i right
@ConceptandCoding
@ConceptandCoding 4 месяца назад
@@pavankumar-cy6mg yes lock is done at DB level but application do not put the lock, application just add the row version in the query
@pavankumar-cy6mg
@pavankumar-cy6mg 4 месяца назад
@@ConceptandCoding and we could say then the Read committed does not comes under OCC, there is mistake in video
@ConceptandCoding
@ConceptandCoding 4 месяца назад
@@pavankumar-cy6mg no OCC does help to achieve the isolation level below repeatable read. Only part is, application do not explicitly put lock, it adds the db row version in the query. thats it.
@user-eb6zj6us6c
@user-eb6zj6us6c 8 месяцев назад
Kudos @ConceptandCoding Good Explanation and great effort. Watching from Tamilnadu without knowing Hindi. Please give english subtitles when you explain in your native language. In other videos, few places you explained in your native language. So I need to deeply concentrate to understand.
@ConceptandCoding
@ConceptandCoding 8 месяцев назад
Sorry for that, i will make sure that I will do in full English
@bhaskarsharan4280
@bhaskarsharan4280 11 месяцев назад
A little more into repeatable read , phantom read is possible in repeatable read because the shared lock can only be acquired on rows which are already present in table, not on rows which are new to table. Hence on multiple query we may see new rows. My question is will these new rows get shared locked during any read after they are inserted?
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Could you please elaborate, i did not understand the question well. Repeatable read do not put range lock.
@bhaskarsharan4280
@bhaskarsharan4280 11 месяцев назад
@@ConceptandCoding at time t0, transaction with repeatable read isolation level got some N rows on executing a query, it put shared lock on all of them, at time t2 some new M records satisfying the same condition were inserted in table, at time t4 same query was executed again with shared locks resulting in phantom read situation - N+M records will be fetched with shared lock on all N rows and no lock on all M rows, will these new M rows be given a lock after 2nd time read?
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
@@bhaskarsharan4280thanks for explaining. Yes, shared lock will be put on these new rows fetched
@dimplamen
@dimplamen 2 месяца назад
Well done, a really well structured and clear explanation! PS: A little bit confused by the "consistency" scale decreasing while the isolation level is increasing. Perhaps you really meant "concurrency" there?
@ConceptandCoding
@ConceptandCoding 2 месяца назад
yes
@Aakashkumar-re7gk
@Aakashkumar-re7gk 6 месяцев назад
Hey Shreyansh, Great video, just one minor clarification related to optimistic concurrency control both user will read that seat is free with version 1 now in your example you said first user will take the exclusive lock till the end of the transaction and if other user tries to update he will check first the version if version is different rollback and try again. one doubt here like both tries to read the row parallely both got the shared lock now if both tries to take exclusive lock parallely will database will handle this thing to give one transaction exclusive lock and other will be in waiting state am I right here it is database responsibility to give exclusive lock to a particular transaction if many are coming parllely
@ConceptandCoding
@ConceptandCoding 6 месяцев назад
Yes it is database responsibility to provide only 1 exclusive lock to 1 txn at a time. And just one correction buddy, in optimistic concurrency control there is no lock required, (so that select for update, is generally select only, no lock is required ) In comment section, there is one long discussion happened, see if you can get that, that will clarify you, if not let me know, we will connect and try to clarify buddy.
@swatisuman1990
@swatisuman1990 11 месяцев назад
Hi Shreyansh, Can you please make a video on Kubernetes?
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Noted
@pradnyeshaglawe351
@pradnyeshaglawe351 3 месяца назад
Non-repeatable read❌ Non-repetetable read✅
@nishantkumar6116
@nishantkumar6116 9 месяцев назад
This version checking and updating the version is this done by db or is it to handled by application developers? Can someone help on this
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
In optimistic locking, it is handled by application. For example Oracle DB, they do not support row version concept, so it's on application to manage the version column by itself
@vivekjha6990
@vivekjha6990 11 месяцев назад
I was waiting for this one..thanks ❣️
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Hope you will find it useful.
@mohammadkaif8143
@mohammadkaif8143 4 месяца назад
Hi Shreyanh @ConceptandCoding, You skipped one very important scenario i.e how repeatable read does not solves phanton read. Can you give the same example using lock strategy?
@ConceptandCoding
@ConceptandCoding 4 месяца назад
let me check
@mohammadkaif8143
@mohammadkaif8143 4 месяца назад
Can you please explain by taking scenario of two transactions T1 and T2 that how Repeatable Read is not able to solve phantom problem@@ConceptandCoding
@suranjanachattopadhyay4979
@suranjanachattopadhyay4979 10 месяцев назад
If one transaction has obtained shared lock on a db row, then how many more transactions can get the lock for reading the row?
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Share lock can be taken by many txns at same time buddy. I don't think there is as such limit
@callmepolice100
@callmepolice100 10 месяцев назад
Seems to be both phantom and non repeatable are the same in both the cases we are reading the value multiple times, can anyone tell me the difference
@AtharvaRao0104
@AtharvaRao0104 10 месяцев назад
Phantom is seen when you do a query for multiple rows - the number of rows returned are different when you do that query multiple times in the same transaction. "One transaction changing the result of another transaction's search query" Non repeatable read - when you read same object multiple times within a transaction - you see different values . IT happens in READ COMMITTED isolation level because another transaction which started later than the first transaction can update and commit a new value. The first transaction which is long running can see old value as well as new value in different reads.
@devape9653
@devape9653 10 месяцев назад
when the next video on 2-phase-locking will come? are you preparing for it?
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Yes working on it
@car_holic1995
@car_holic1995 10 месяцев назад
thanks for the videos but i could not understand how these strategies managed the distributed architecture..if read calls are to be done from different server of db...all the transaction are being on hit on same node even for the read?
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
There is a concept of distributed locking, means if there are multiple instance of DB having similar record, there there are service like zookeeper which make sure that all instances of db put the lock on that row, there are more apart from zookeeper
@car_holic1995
@car_holic1995 10 месяцев назад
@@ConceptandCoding bhaiya thanks a lot apne toh abhi reply kar diya..bhai in technologies ko code level pe kaise seeekhein...scaler jaise course bhut mahnge hain..internet pe proper resouce smj nhi aa rhe bhai....please reply please...
@car_holic1995
@car_holic1995 10 месяцев назад
bhai ek baar apse baat ho jaaye toh jeevan sudhar jaaye😀😀 ...itni confusion h bhai..kya karein
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
@@car_holic1995 code level Pe bhi Sikh jaoge. 1 way is as you grow in your career, you will automatically get exposed to these things. 2nd way is, take a sample app and start building it (take guidance from your seniors or other people)..
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
@@car_holic1995 :) i am also learning buddy
@engineersCode
@engineersCode 21 день назад
Nice video "-)
@sheikhmuhammedshoaib1124
@sheikhmuhammedshoaib1124 9 месяцев назад
Hi can you suggest me some Db books where i can get lot of practice question on isolation, transaction and concurrency.
@ConceptandCoding
@ConceptandCoding 8 месяцев назад
Design data intensive application book is one of the best book
@sheikhmuhammedshoaib1124
@sheikhmuhammedshoaib1124 8 месяцев назад
@@ConceptandCoding thanks...
@nitishprasadkushwaha
@nitishprasadkushwaha 10 месяцев назад
Concureeency is low for serialiser and high for red uncommited right ?
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Yes right
@jayak3768
@jayak3768 7 месяцев назад
Next to your table for transaction Isolation, it should concurrency going from high to low. Consistency goes from low to high, in your table from top to bottom.
@ConceptandCoding
@ConceptandCoding 7 месяцев назад
Your are right, i have pinned that in comment too.
@harshagarwal_net
@harshagarwal_net 4 месяца назад
​@@ConceptandCoding If possible, could you please add asterisks (*) to the videos? The absence of asterisks is causing confusion.
@ConceptandCoding
@ConceptandCoding 4 месяца назад
@@harshagarwal_net * sorry did not bot get it, for what reason could you pls elaborate
@khushgandhi6638
@khushgandhi6638 5 месяцев назад
Why optimistic locking can only work with READ_COMITTED isolation level , can’t we have REPEATABLE_READ with optimistic locking…
@DSA_Coding
@DSA_Coding 4 месяца назад
video is gem
@ConceptandCoding
@ConceptandCoding 4 месяца назад
thank you
@yaseenshaik2284
@yaseenshaik2284 9 месяцев назад
Thanks for the detailed explanation 😊
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
Thanks
@UtkarshSingh-cb8fq
@UtkarshSingh-cb8fq 10 месяцев назад
Where are we applying these Locks? On Db-Level or Code-Level( duty of AppDev or DBDev) ? How does the code look like ? 2 more requests: - Can you tell What Common Concurrency-questions, that are asked in interviews ? - Pls explain Class-level & Object-level lock.
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Transaction and isolation level we have to define at code level, locks is at DB level. This is the most frequently asked interview question in concurrency buddy.
@UtkarshSingh-cb8fq
@UtkarshSingh-cb8fq 10 месяцев назад
@@ConceptandCoding for isolation we will be writing code to get the shared / exclusive lock ? How does that look in Java? What are good books to refer concurrency ?
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
@@UtkarshSingh-cb8fq any SQL book is okay for it. When you do Select query it put shared lock. When you use update, delete, select for update it put exclusive lock
@UtkarshSingh-cb8fq
@UtkarshSingh-cb8fq 10 месяцев назад
@@ConceptandCoding so when you say put shared lock at start of Read and hold it till transaction completes , then it will be DB property/responsibility to hold shared lock until transaction completed? And how DB knows about the transaction , like how many statements/operations are present in a transaction
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
@@UtkarshSingh-cb8fq DB does not know about how Many statements, DB know about Transaction start or aborted or committed
@AdityaKumar-is9tk
@AdityaKumar-is9tk 6 месяцев назад
Hey nice tutorial, but there are some of wrong things taught in this tutorial. Optimistic locking doesn't use any lock. And what you mean db put share lock and after reading it releases the lock? Whats point of putting shared lock, it can just read it
@ConceptandCoding
@ConceptandCoding 6 месяцев назад
right, and same has been discussed in the comment section. Do check it out, hope that will clarify your doubt.
@rabindradocument8934
@rabindradocument8934 11 месяцев назад
Concurrency is distributed system: how we will handle Concurrency between many microservices. How do we rollback complete transaction if one of the service fails.
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Already explained this in: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ET_DnJgfplY.html
@sujayghosh5128
@sujayghosh5128 Месяц назад
How do you decide when to use which isolation level?
@ConceptandCoding
@ConceptandCoding Месяц назад
based on the trade off between consistency, concurrency and performance your application requires
@sujayghosh5128
@sujayghosh5128 Месяц назад
@@ConceptandCoding Thanks for your reply. To help me understand better, can you give me some examples?
@ganapatimarathi2643
@ganapatimarathi2643 11 месяцев назад
Hi.... Interesting topic.... But can i get one POC.. Meaning full low level code ????
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
I will write it and upload on gitlab and update
@ganapatimarathi2643
@ganapatimarathi2643 11 месяцев назад
@@ConceptandCoding thank you sooo much. 🥰
@user-et1lp1kp4m
@user-et1lp1kp4m 9 месяцев назад
When is the 2PL session coming up ? :)
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
It's already live, pls check the HLD playlist. Today I have made it live buddy
@anantjain1263
@anantjain1263 10 месяцев назад
Can you provide notes of the same by uploading it somewhere?
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
pls check the description of the video buddy.
@user-et1lp1kp4m
@user-et1lp1kp4m 9 месяцев назад
WHo writes these transactions ? DB developers ?
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
No, transactions (begin, rollback, commit) we app developer write it.
@tejass5060
@tejass5060 11 месяцев назад
I think the DB locks that are used on processing the transaction are not same among all the DB's. In postgres, if you try to execute a deadlock scenario using repeatable read isolation level. It will commit without any issues. Any comments on this @Shreyansh?
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
In postgres too, definitely One of the txn should get aborted (as postgres automatically detect deadlock and abort only 1 txn). Have you tried testing this usecase?
@tejass5060
@tejass5060 11 месяцев назад
@@ConceptandCoding Yes, I had a table called test with two rows. Tried executing 2 different transactions according to the deadlock scenario but it is not giving any error. I tried the same with serializable and it gives error
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
@@tejass5060 can you notice and tell one thing buddy: In Postgres for repeatable read deadlock scenario, does one txn getting rolled back or not?
@tejass5060
@tejass5060 11 месяцев назад
@@ConceptandCoding Not rolling back.
@tejass5060
@tejass5060 11 месяцев назад
Both the rows are getting updated.
@bluesteel1
@bluesteel1 2 месяца назад
Good video but too many ads
@piyushshukla5125
@piyushshukla5125 10 месяцев назад
most of the imp low level design video are available only to join member. can you please make it public
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Only interview questions i have kept for the members buddy. But all the fundamentals and concepts are available public
@bishtsaurabh5
@bishtsaurabh5 9 месяцев назад
Yes but those videos were initially free and now become paid which is not a good thing in my opinion . Although the content is great 👍
@nirutgupta5894
@nirutgupta5894 8 месяцев назад
I think in optimistic also deadlock possible? T1 Write A Write B T2 Write B Write A Both will wait for each other at time t2 to release exclusive lock.
@nirutgupta5894
@nirutgupta5894 8 месяцев назад
Okay I think in OCC we dont do locks on db rows
@nirutgupta5894
@nirutgupta5894 8 месяцев назад
Instead we go with versioning
@ConceptandCoding
@ConceptandCoding 8 месяцев назад
Yes OCC use version
@asktostranger8296
@asktostranger8296 9 месяцев назад
Next video 🥺
@ConceptandCoding
@ConceptandCoding 9 месяцев назад
Next week.
@sahilgarg3460
@sahilgarg3460 10 месяцев назад
Hello sir, Just visited your channel after long time again, but videos are now paid , feeling bad .😢
@ConceptandCoding
@ConceptandCoding 10 месяцев назад
Only interview questions are Locked buddy, rest all available for free.
@AtharvaRao0104
@AtharvaRao0104 Месяц назад
Serializable Snapshot Isolation as explained in DDIA describes optimistic concurrency control technique is an easy way. "when a transaction wants to commit- the DB checks whether anything bad happened" (i.e whether isolation was violated), if so the transaction is aborted and has to be retried." " SSI has an algorithm for detecting serialization conflicts among writes and determining which transactions to abort" The key idea is to detect if any read in a transaction has become outdated because of a write in another transactions. Such stale reads can lead to an invalid decision(writes) and hence the transaction is aborted and has to be retried. Versions are used to detect this.
@AmareshwarBhat800
@AmareshwarBhat800 3 месяца назад
Waste of time. Not recommended video.
@sarvagyaagarwal2823
@sarvagyaagarwal2823 7 месяцев назад
RIP English
@fooballers7883
@fooballers7883 4 месяца назад
LOL India would return back to the 5 century without English
@fooballers7883
@fooballers7883 4 месяца назад
Thanks for a great tutorial... I can feel the passion in your teaching....Any one interested in forming a group to learn... as I am just starting out would be a great help
@logicalrisi
@logicalrisi 4 месяца назад
hello
Далее
23. Two Phase Locking (2PL) | System Design
41:25
Просмотров 10 тыс.
20 System Design Concepts Explained in 10 Minutes
11:41
ASMR CORTE DE CABELO COM EMOÇÃO
01:00
Просмотров 1,3 млн
How to answer any system design interview question?
1:37:51
How I Mastered System Design Interviews
10:22
Просмотров 86 тыс.
Optimistic Locking - What, When, Why, and How?
16:34
Просмотров 11 тыс.