Relational Database ACID Transactions (Explained by Example)

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.พ. 2025

ความคิดเห็น • 158

  • @hnasr
    @hnasr  4 ปีที่แล้ว +1

    Get my Fundamentals of Database engineering udemy course, head to database.husseinnasser.com for a discount coupon
    Timestamps
    2:00 What is a Transaction?
    4:30 Atomicity
    7:00 Isolation *
    9:30 Isolation - Read phenomena *
    11:40 Dirty Reads
    14:40 Non-repeatable Read
    17:00 Phantom read
    18:53 Isolation Levels*2
    19:20 Read uncommitted
    19:55 Read committed
    21:05 Non-repeatable Read
    23:40 Serializability
    25:00 Isolation Levels vs Read phenomena
    27:45 Consistency
    28:30 Consistency in Data
    33:50 Consistency in Reads
    35:00 Eventual Consistency
    40:30 Durability

  • @hnasr
    @hnasr  4 ปีที่แล้ว +39

    2:00 What is a Transaction?
    4:30 Atomicity
    7:00 Isolation *
    9:30 Isolation - Read phenomena *
    11:40 Dirty Reads
    14:40 Non-repeatable Read
    17:00 Phantom read
    18:53 Isolation Levels*2
    19:20 Read uncommitted
    19:55 Read committed
    21:05 Non-repeatable Read
    23:40 Serializability
    25:00 Isolation Levels vs Read phenomena
    27:45 Consistency
    28:30 Consistency in Data
    33:50 Consistency in Reads
    35:00 Eventual Consistency
    40:30 Durability

    • @pratikmakune2881
      @pratikmakune2881 4 ปีที่แล้ว

      Thanks a ton for the gold standard content. I have a question though, In Atomicity, you mentioned if the $100 debited and then the DB crash event occurred, after restart it was $900 w/o credit update query, so when will the rollback occur? After the DB restarts as it seems like if DB crashes, what happened to the Tx state, is it lost or recovered after restart?

  • @justsaysharu
    @justsaysharu 4 ปีที่แล้ว +45

    This is pure GOLD. Literally, one semester subject knowledge in less than an hour! Crazy-or-what :D

  • @sumeetracharla9316
    @sumeetracharla9316 4 ปีที่แล้ว +26

    you are really a talented person,one of the best video's i have seen in my life :)

    • @hnasr
      @hnasr  4 ปีที่แล้ว +12

      Thank you Sumeet, ! 🙏 I still think I have ways to go. We need to be able to keep an open mind and keep learning.

  • @jinendrakhabiya2646
    @jinendrakhabiya2646 4 ปีที่แล้ว +10

    Best video on ACID properties. Thanks!

  • @demislam0306
    @demislam0306 5 หลายเดือนก่อน

    great content! worth every second!! loved how you always highlighted the fact that its up to the developer to make the tradeoff in deciding what properties to satisfy and what to be loose about. That's basically what software engineering is, it's not just writing codes/queries and declaring models that the orm automatically creates a db out of.

  • @shabnamhaque3784
    @shabnamhaque3784 5 หลายเดือนก่อน

    hi hussein, a friend of mine introduced me to ur channel 5 days ago and let me tell you I'm hooked. you are doing great great work . Kudossss keep em coming!

  • @bhavanprajapati4773
    @bhavanprajapati4773 5 ปีที่แล้ว +46

    please make videos on indexing and normalization.

  • @ameyapatil1139
    @ameyapatil1139 4 ปีที่แล้ว +2

    No way ! No way someone makes a video so good ! Thanks !

  • @aduonye
    @aduonye 4 ปีที่แล้ว +2

    I enjoyed every bit of your lecture especially the lucid examples. Well done! I will be glued to your channel for a long time.

    • @hnasr
      @hnasr  4 ปีที่แล้ว +1

      Thank you Aduonye!! Enjoy the content ❤️

  • @wh264
    @wh264 4 ปีที่แล้ว +6

    The Isolation part is very interesting. Great examples to help me remember. If I can give a suggestion, a summary at the end to tie all things up would help me remember even better. I'm subscribing and liking for more!

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Thanks for the suggestion ❤️ great idea

  • @ary9344
    @ary9344 8 หลายเดือนก่อน

    Just discovered your channel yesterday, thanks for your videos! I love the way you explain things, not only the what, but also the why, showing us how to think, this will help me in my first job interview :)

  • @Sujankumarreddy
    @Sujankumarreddy 4 ปีที่แล้ว +6

    Why my University doesn't have a professor like you :( You are AMAZING! Thanks for the great content.

    • @CricMicroscope
      @CricMicroscope ปีที่แล้ว +2

      His accent is irritating

    • @amlanbiswas4526
      @amlanbiswas4526 ปีที่แล้ว

      @@CricMicroscope your comment is irritating

  • @mind77749
    @mind77749 4 ปีที่แล้ว +1

    wow really nice video, watched all and repeating many parts to understand better. More than one hour is gone! Really love the video!!

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Thank you! Glad you are enjoying the content and happy you didn’t get bored 😅

  • @sagartyagi2450
    @sagartyagi2450 3 ปีที่แล้ว +2

    I used to watch a lot of tech videos before discovering your channel. Now I just want everything to be taught by you, you're a legend sir. Can we please make a video about Distributed Database? I'm really interested in knowing how do we prevent concurrent writes/updates in a distributed db.

  • @fernard8985
    @fernard8985 3 ปีที่แล้ว

    Fantastic explanation, I was finally able to understand the isolation level concept and hopefully grasp it. Thank you very much, I have failed the ACID question during several interviews, what eventually led me to your material. Keep up with the great work!

    • @hnasr
      @hnasr  3 ปีที่แล้ว

      Glad it helps! I also go through more examples and more details on my fundamentals to database engineering udemy course.

  • @nmprecious
    @nmprecious 3 หลายเดือนก่อน +1

    Yes, I reached the end of the video. Thanks a ton.

  • @SwetPotato
    @SwetPotato 4 ปีที่แล้ว +1

    Thanks for clarifying all these.
    ACID was only on one slide in my Uni database subject and now we are asked to write something about it as part of an assignment.

  • @emiliosoto6521
    @emiliosoto6521 9 หลายเดือนก่อน

    You are a professional at teaching. Thank you !

  • @cw5948
    @cw5948 5 ปีที่แล้ว +2

    You've got some amazing content here! Good mix of breadth and depth for the topic discussed especially when analyzing isolation. Looking forward to viewing some of your other videos in the playlist, particularly if there's anything comparing SQL and NoSQL databases.

    • @hnasr
      @hnasr  5 ปีที่แล้ว +1

      cw Thanks cw Im glad you noticed because that is what Im doing, trying to go breadth and when I find the topic interesting or on demand I go deep. I am planning to do some more DB videos love those ... thanks for your comment enjoy the content!

    • @machaallahmariam3162
      @machaallahmariam3162 4 ปีที่แล้ว

      @@hnasr thank u

    • @amlanbiswas4526
      @amlanbiswas4526 ปีที่แล้ว

      ​@@hnasr I have a query. When you say versioning, do you mean MVCC? Also, I see that MVCC uses exclusive locks unlike 2PL (uses shared and exclusive) for updates and actually is more difficult to implement and have to address all the anomalies like handling edge cases. For instance, using MVCC, Oracle can only offer Snapshot Isolation, not Seralizable, which has Write Skews.
      Then, does MVCC still stop Phantom Reads and how?

  • @salmanbaig8088
    @salmanbaig8088 4 ปีที่แล้ว

    Liked your clean examples and Hollywood' style of teaching

  • @pratiyushprakash6509
    @pratiyushprakash6509 4 ปีที่แล้ว

    This is incredible. I have watched so many of your videos in just few days. Hope you keep making these great content.

  • @jayjay7333
    @jayjay7333 2 ปีที่แล้ว

    Best resource to understand acid tranction

  • @hashem467
    @hashem467 4 ปีที่แล้ว +36

    I wish you were my uni professor 😂

  • @bs7448
    @bs7448 2 ปีที่แล้ว

    The best ever tutorial on such a complex topic. Thanks 🙏

  • @mohamedadel936
    @mohamedadel936 4 หลายเดือนก่อน

    Really Useful Video.
    Thank You Hussein :)

  • @parasarora5869
    @parasarora5869 4 ปีที่แล้ว

    Never knew these important things about database. Thanks for such a great explanation !! 😇

  • @santoshbhatnagar2155
    @santoshbhatnagar2155 ปีที่แล้ว

    This video literally cleared my fundamentals, have read about this in college, didn't get it clearly understood.
    Thank you @hussein nasser

  • @mtnrabi
    @mtnrabi ปีที่แล้ว

    Amazing piece of content bro.
    Love that you bring examples and use-cases for each topic, because without a problem those don't worth a whole.
    Hoping to more see videos like this one from you :)

  • @NepaliBiraj
    @NepaliBiraj 4 ปีที่แล้ว

    Paid 6k to UNI and jump back here to get insight into it lol.....Thi is what it is..Thanks for the great video.

  • @abhishekbanerjee6140
    @abhishekbanerjee6140 2 ปีที่แล้ว +1

    This is just Gold mate.

    • @hnasr
      @hnasr  2 ปีที่แล้ว

      enjoy!

  • @KenanCasey
    @KenanCasey ปีที่แล้ว

    Great video! You explained a deeply complex topic really nicely. Thank you.

  • @siddharthsrivastava3961
    @siddharthsrivastava3961 3 ปีที่แล้ว

    Awsome.. the way you explain things is awsome..👍👍

  • @krishnasumanth007
    @krishnasumanth007 3 ปีที่แล้ว

    Good one. I was unable to get much on lost updates concept here.

  • @omarkamel9116
    @omarkamel9116 ปีที่แล้ว

    Great way of explaining complex things

  • @nagame859
    @nagame859 ปีที่แล้ว

    This is quite exceptional!!
    Thank you soo much!!

  • @devyetii
    @devyetii 4 ปีที่แล้ว +1

    Reached the end 🎉 .. Thanks for the great content ❤️

  • @saoudahmedkhan2549
    @saoudahmedkhan2549 ปีที่แล้ว

    Thanks, men Thanks a lot for such type of content. this is really appreciated. JazakAllah

  • @yarden2096
    @yarden2096 8 หลายเดือนก่อน

    Great video!! I was looking for something like that

  • @bitsofnacho
    @bitsofnacho 4 ปีที่แล้ว +1

    Your videos are amazing, great content and marvelous arrangement, thank you very much!

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Thank you very much!

  • @luizdebem
    @luizdebem 3 ปีที่แล้ว

    Thank you so much Hussein!
    Great class!

  • @mohamedswialm7534
    @mohamedswialm7534 2 ปีที่แล้ว

    thanks for sharing Hussein !

  • @user-EricLin0619
    @user-EricLin0619 10 หลายเดือนก่อน

    It's a golden channel

  • @SachinDolta
    @SachinDolta 4 ปีที่แล้ว

    Finally understood what ACID is

  • @InvincibleMan99
    @InvincibleMan99 9 หลายเดือนก่อน

    Hats off to you.
    God bless you

  • @danielschiffers9696
    @danielschiffers9696 4 ปีที่แล้ว

    Hey, thanks man! Really liked the video made allot clear.

  • @QuanNguyen-xq1jo
    @QuanNguyen-xq1jo 4 ปีที่แล้ว

    you re awesome ! it helps me understand DB transaction easily

  • @emmanuelonyebueke544
    @emmanuelonyebueke544 2 ปีที่แล้ว

    Hussein, you are amazing

  • @chenjun4151
    @chenjun4151 4 ปีที่แล้ว +1

    really really really clear explained and helpful!

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Happy to hear that!

  • @nguyenconghuy3847
    @nguyenconghuy3847 24 วันที่ผ่านมา +1

    thats how we teach 💯

  • @saravanasai2391
    @saravanasai2391 ปีที่แล้ว

    Hi hussain. The explanation is clear. Can you make video on how does a consistency maintained in distributed system among the multiple microservies & I really can't find a good content on how to build our small own database to understand the working of relational database.

  • @rodmajuelojr
    @rodmajuelojr 4 ปีที่แล้ว +2

    True story im watching video when I suddenly had Acid reflux. :( great contenr as always

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Ohh get well soon ! Take those nexum

  • @B-Billy
    @B-Billy 4 ปีที่แล้ว

    Boss level stuff!!! To the point.

  • @cymi2607
    @cymi2607 ปีที่แล้ว

    Thank you so much! amazing video!

  • @sridharramalingam329
    @sridharramalingam329 ปีที่แล้ว

    Nice video and explanation, agree with all except - traditional OLTP databases provides eventual consistency, I dont think any banking system will go for eventual consistency, though postgres has both syncronous(will provicde consistency with perfromancer compromise) and async replciation, but I think thats mostly for HA purpose for banking\critical systems, with these days everything running on VMs, the critical databases are mostly vertically scaled periodically and async sharding/replication is usually used for non critical reads like reporting etc never for banking\critical transactions, so we have no option but to live with these 70s RDBMS systems for some core businesses which require ACID to be stricltly implemeneted.

  • @emilmatei2258
    @emilmatei2258 4 ปีที่แล้ว

    very good video, the only thing I would like clarified is if there is a reason to store the image in the db as blob as in the example.

  • @AbleToLiveHere
    @AbleToLiveHere 4 ปีที่แล้ว

    The best. As usual. Thank you

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Thanks!!!

  • @benjaminkovackeber
    @benjaminkovackeber 4 ปีที่แล้ว +1

    This is a very good video, thank you:)

  • @asfar1984
    @asfar1984 4 ปีที่แล้ว +1

    I am looking at your videos for over a year, I will love if you touch Storage and big data processing also !! ETL/MapReuce/Hadoop !!

  • @fsl4faisal
    @fsl4faisal 2 ปีที่แล้ว +1

    phantom read and non-repeatable read looks the same to me, what am I missing?
    Okay so in case of non-repeatable we were updating the same row, and that was the cause of issue and in case of phantom read we created a new row which was the cause of the issue
    thank you for the amazing content. I have already bought your database course planning to watch that too.

  • @CODINC
    @CODINC 4 ปีที่แล้ว +1

    Hey man. Love your video but i am confused about dirty read example. You have mentioned that Transaction was Updated but not committed. How can the other session read different value other than what is in Database. Well unless it is committed it will read that updated value otherwise it will still read the value that is in database. Does it make sense?

    • @hnasr
      @hnasr  4 ปีที่แล้ว +1

      it means that the read transactions when in read uncommitted isolation level (sql server for example) are configured to read the latest row change wither this is committed or not. this could be in a different data structure usually called the WAL (write ahead log)
      what you described is a read committed isolation level where we read the value stored in the row and committed.

    • @CODINC
      @CODINC 4 ปีที่แล้ว

      @@hnasr thanks for quick reply. Thanks for explaining this to me. I always thought one can read updated value from database after committing, silly me. Always learn something new. Thanks again

  • @SanjanaSharma-h7x
    @SanjanaSharma-h7x ปีที่แล้ว

    Amazing content. thanks!

  • @chrisye2183
    @chrisye2183 2 ปีที่แล้ว +1

    Awesome! can you make video to explain difference between SQL and NoSQL ?

  • @kirillzlobin7135
    @kirillzlobin7135 ปีที่แล้ว

    33:26 I remember the time when on TH-cam we could see the "exact" number of subscribers and how I refreshed the page after several seconds on the channels with millions subscribers and this number chaged.
    Now I understand why they moved from this way and started just showing "5M" for example

  • @vishalsrane
    @vishalsrane ปีที่แล้ว

    Thank you for this video.

  • @deeraj3069
    @deeraj3069 4 ปีที่แล้ว

    Thank you so much for the video
    Can you please make a video on MongoDB architecture

  • @aymaneharmaz7126
    @aymaneharmaz7126 ปีที่แล้ว

    I have a question, do the changes made by a transaction before being commited or rolled back performaed directly on the database (on disk) or each transaction performs the changes on its own isolated memory ?

  • @dan-vw4ve
    @dan-vw4ve 5 ปีที่แล้ว +1

    awesome video

  • @SoeaOu
    @SoeaOu 4 ปีที่แล้ว

    This is hilarious, thanks. Very helpful.

  • @ahmedsallam2868
    @ahmedsallam2868 ปีที่แล้ว

    Thanks for your great content :)

  • @alexchernenko4901
    @alexchernenko4901 4 ปีที่แล้ว

    thanks! It's super nice and clear :)

  • @vyshnavramesh9305
    @vyshnavramesh9305 ปีที่แล้ว

    - Transaction: A bunch of queries
    - Atomicity: Either all the queries in a transaction must commit, or all of them must rollback
    - Isolation: is about isolating transactions to handle concurrency issues arising from concurrent transactions. How: versions and locks(shared/read) in db level, locks in application level.
    Problems = Dirty read, Non Repeatable read, Phantom read, Lost update.
    Solutions = Isolation levels like Read uncommitted, Read committed, Repeatable read, Serializable
    - Consistency: Is about Consistent data and Consistent read.
    Consistent data: Happens within a machine due to non-atomicity, non-isolation etc
    Consistent read: happens across machines, in both sql and nosql dbs when replicas are present. You update a record, but when you read after, you get old data. It is always eventual consistency when replocas are present
    - Durability: committed transactions must be persisted in a durable storage

  • @nero1375
    @nero1375 5 ปีที่แล้ว +1

    awesome content! Keep it up!

    • @hnasr
      @hnasr  5 ปีที่แล้ว

      Will do! Thanks for your comment 🙏

  • @marrallisa
    @marrallisa 4 ปีที่แล้ว +1

    i love you so much bc you are so funny and helpful

  • @pieicx
    @pieicx 4 ปีที่แล้ว +1

    my cat freaked out when you changed your tone lol

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Hằng 😂 sorry little kitty 😍

  • @pankajkaushik913
    @pankajkaushik913 3 ปีที่แล้ว

    Great stuff

  • @ibrahemmohammad-rl5rq
    @ibrahemmohammad-rl5rq 7 หลายเดือนก่อน

    Talking about isolation i kind of run into a weird issue while using Repeatable read level and locks
    If you have two transactions running at the same time and you use lock for update (select for update) to get the record (let's say wallet) on t1 (first transaction) and you update the balance column value from 10 to 20 and then it's committed, now since you used lock for update that means t2 was waiting for the wallet record to be released and now it can continue after t1 committed
    On t2 if you get select the wallet record normally (without using lock for update) you'll get the balance 10 because both transactions were running at same time and it makes sense because we're using Repeatable read isolation level
    BUT if you get the wallet using lock for update on t2 it gives you the balance 20 😅
    Does the locks have more priority over isolation? Is this a normal behaviour ?
    Because I'm using this trick to have a general isolation level of Repeatable read but in some cases i want to get the committed record even if it was committed during the transaction not before it
    So it's like having two isolation levels , the general Repeatable read and the Read committed but only on records that's i chose using lock for update .
    Wanna get your opinion to know if this "trick" gonna cause me a headache in the future 😅
    BTW AWESOME CHANNEL ❤❤

  • @JynyChen
    @JynyChen ปีที่แล้ว

    now u are my tech lead 😂😂😂

  • @malayrevanth5854
    @malayrevanth5854 4 ปีที่แล้ว

    can you share the slides used in the video? It would be very useful as a reference. Thanks for the detailed explanation on ACID.

  • @dgen77
    @dgen77 ปีที่แล้ว

    Thank you brother

  • @neerajcrespo
    @neerajcrespo 3 ปีที่แล้ว

    I was asked in an Interview How durability is internally achieved in postgres (something like when data from WAL is persisted)

  • @varunkumarsingh758
    @varunkumarsingh758 2 ปีที่แล้ว

    Thank you
    🙏

  • @neuodev
    @neuodev 2 ปีที่แล้ว

    Thanks for the great video 🙌! Can you share your slides? I want to use it as a reference!

  • @jiayuhe8659
    @jiayuhe8659 4 ปีที่แล้ว

    great video!

  • @paulfrischknecht3999
    @paulfrischknecht3999 ปีที่แล้ว

    depending on what you mean by lost updates, you can get them even with the serializeable isolation level: the second transaction loses all updates done by concurrent ones. At least in h2 db, serializeable just guarantees that you won't observe rows added since your transaction started (so no more phantom reads). But you can still end up updating the database unaware of any changes made by other concurrent transactions. I don't know if there is any database that allows only one transaction at once which would be required to avoid this

    • @paulfrischknecht3999
      @paulfrischknecht3999 ปีที่แล้ว

      well ok, the documentation says that their interpretation of serializeable doesn't actually guarantee that sequential execution of concurrent transactions gives the same result

  • @prostyxi2771
    @prostyxi2771 ปีที่แล้ว

    perfect more please

  • @dylanngo4454
    @dylanngo4454 ปีที่แล้ว

    Thanks😊🎉

  • @BaraaBakri123
    @BaraaBakri123 4 ปีที่แล้ว

    If i want to learn Database , Can i start with this playlist ?
    Thank you Hussain ❤️

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Yes, absolutely!

  • @ashutoshmishra2328
    @ashutoshmishra2328 4 ปีที่แล้ว

    Hey Hussein, Thanks for the great content.
    Can you make a video to give some idea about how Db Client and Server communicate like mySQL uses its own protocol mysql. and how they use TCP connection like do they create new TCP connection for each query similar to HTTP 1.0 or they use single TCP connection for entire Txn similar to HTTP 1.1 ?

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Ashutosh Mishra hey Ashutosh, I think I did this with mongodb and postgres
      Wiresharking MongoDB - Decrypting TLS traffic, mongo protocol, cursors and more
      th-cam.com/video/naJC-yuCZb8/w-d-xo.html
      Wiresharking PostgreSQL - SELECT * FROM on Postgres behind the scenes
      th-cam.com/video/vjWt-PF_6tA/w-d-xo.html

    • @ashutoshmishra2328
      @ashutoshmishra2328 4 ปีที่แล้ว

      @@hnasr Thanks.!
      You can add those videos to database engineering playlist so that other people will find it in the same playlist.

  • @raj_kundalia
    @raj_kundalia ปีที่แล้ว

    thank you!

  • @ru2979
    @ru2979 2 ปีที่แล้ว

    wow 🔥🔥

  • @coderkashif
    @coderkashif ปีที่แล้ว

    amazing

  • @AISynthetic
    @AISynthetic 5 ปีที่แล้ว +2

    Can you make series on System Design?

    • @hnasr
      @hnasr  5 ปีที่แล้ว

      Great idea! Will sure consider it

    • @AISynthetic
      @AISynthetic 5 ปีที่แล้ว

      Thank you

  • @siddharthsrivastava3961
    @siddharthsrivastava3961 3 ปีที่แล้ว

    Please make video on postgres WAL

    • @hnasr
      @hnasr  3 ปีที่แล้ว

      👍👍 on my plan for the next video

  • @nitingupta1591
    @nitingupta1591 3 ปีที่แล้ว

    From where do we get the slides of this course, once have joined as members?

    • @hnasr
      @hnasr  3 ปีที่แล้ว

      You can download it from here! payhip.com/b/07an

  • @bademo48
    @bademo48 5 ปีที่แล้ว

    This one is good 👍

    • @hnasr
      @hnasr  5 ปีที่แล้ว

      Mert Ertuğrul 😍😍😄 let me know what should I make next .. cheers

  • @pcp_greats
    @pcp_greats 2 ปีที่แล้ว

    Same as others. Hooked

  • @yumengsi
    @yumengsi 4 ปีที่แล้ว

    Very educational and funny

  • @thescubabuba6470
    @thescubabuba6470 3 ปีที่แล้ว +1

    Can you please use dark background in your future videos :) I usually watch your videos in the evening and the white background is really hard on my eyes. If it's causing you too much work then don't worry.

  • @mdsazidkhan4720
    @mdsazidkhan4720 2 ปีที่แล้ว

    From where I can download the slides for this @hussein ?