Implementing Distributed Transactions using Two Phase Commit Protocol

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

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

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

    This channel is a gold mine, appreciate the efforts you put in.👏

  • @shikharsubedi
    @shikharsubedi 19 วันที่ผ่านมา

    thank you for the code demonstration. it really solidified the understanding. I really need to learn go.

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

    Your videos have so much information and to the point details in them, I am lucky that youtube has recommended me your videos

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

    This channel is a gold mine indeed

  • @VimalKumar-rd1ol
    @VimalKumar-rd1ol 2 ปีที่แล้ว +4

    Great video, keep adding more videos !

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

    Awesome Video
    Just to understand payment flow too.
    what should be the order for payment here
    1. Reserve -> Payment-(if payment fails then remove reservation, exit)> Assign (if assign fails then refund)
    2. Success Payment->Reserve(if reserve fails then refund, exit) -> Assign (if assign fails then refund)

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

      Payment flows are slightly different. Depends on the API exposed by then payment gateways.
      They do expose orders which acts as reservations but not concrete like distributed transaction.
      By the way, you should never model payments as a distributed transaction. It is always designed with eventual consistency in mind given how banks work.

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

    You channel has an addiction. Amazing content, loved it ❤️

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

    This was top notch, mazza aaya!

  • @xenky0
    @xenky0 11 หลายเดือนก่อน +1

    Good example, nice explanation, thank you.

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

    Literally this was an amazing hit

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

    Good video. Looking forward for implementation of Paxos and Raft as well.

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

    Absolutely beautiful!!

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

    Amazing man, just amazing!

  • @renbangbprd7236
    @renbangbprd7236 20 วันที่ผ่านมา

    Where is the link to the previous video? I can't seem to find it

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

    Very Informative channel and content . Keep it Up !! 👏👏👏

  • @NidhiSinghPersonal
    @NidhiSinghPersonal 6 หลายเดือนก่อน

    This video got me subscribed to your channel, Amazing content. Loved the implementation bit :)

  • @GauravSharma-wb9se
    @GauravSharma-wb9se 2 ปีที่แล้ว +1

    we can make transaction in only commit phase itself....if both commit phases goes fine then accept order or else throw unacceptable error...…isn't it?

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

    @AsliEngineering - what if in the placeOrder() we are able to make 3 api calls but the app instance crashes down before we book the agent for the order? I guess this case is not going to be handled.

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

    Thanks awesome! This is high quality explanation.

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

    Appreciate your efforts 👏👏👏

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

    Mazaa aa gya bhai sahab

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

    Great video loved it. btw which vs code theme your are using?

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

    Thanks nice explaination but how we can implement timer thing..

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

      1. Threads and executors 2. Distributed Event Generator 3. Specialised database like Redis

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

    I'm having difficulty understanding, how is the code representing distributed transactions?If I take it on literal face-value, there are no 2 different datasources so current scenario could have been done under same transaction, why going through the pain of taking locks and everything? Distributed transactions are hard because there are 2 or more services/datasources etc which don't share any transaction id/object/etc. This example doesn't fits the scenario.
    Please correct where I'm wrong. Thanks.

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

      Distributed does not just mean having two machines. It means having completely isolated processes/threads. The example I took mimics that. You can use this very example across machines and it would work.
      also,.I never ran entrie thing in one transaction.

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

    Quick question out of curiosity... There are scenarios when 1 agent gets 2 orders due to nearby geological of order delivery address ... How such things can be handled??

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

      Delivery service's delivery_agent/reserve api can have this logic in real scenario. And the same api can return the agent id so that the order service can book the same agent in the 2nd phase of the commit

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

    12:45 order service is acting as an orchestrator [* link: orchestration vs choreography]

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

    Could you please explain why did you use Select for update and then update it? I know it will lock that row in a write exclusive lock so that no other transaction can update that row. But what would happen if we directly update that row by using "update agents set is_reserved=true and order_id=1 where is_reserved = false and order_id = null"?

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

      Consider that there is one delivery agent and if we do not lock it then both the transaction might update the same row and both would think that it reserved the agent. In reality one ohs while the other has not.

    • @VikramSingh-oq7pe
      @VikramSingh-oq7pe ปีที่แล้ว

      @@AsliEngineering How does it work in the case of replicas? Let's suppose a transaction updates is_reserved=true but other transactions might read stale data and assign it to some other agent

    • @viewonly_akshay
      @viewonly_akshay 11 หลายเดือนก่อน

      I believe, in this case, reading a right state is critical and critical read or writes should go to master instead of read replicas.

    • @mahendrahegde6400
      @mahendrahegde6400 5 หลายเดือนก่อน +1

      But find and update is atomic so not sure if select for update is really needed here.
      In case of replicated dbs writes go to primary so select for update is run on primary not on secondary

  • @nontechnicalbaba
    @nontechnicalbaba 20 วันที่ผ่านมา

    Is it synchronous or asynchronous? Is it scalable in real toy environment?

    • @AsliEngineering
      @AsliEngineering  20 วันที่ผ่านมา

      distributed txn have to be synchronous. if you need strong consistency across machines, you have to do this.

  • @tjLearns-ps3bk
    @tjLearns-ps3bk 5 หลายเดือนก่อน

    💥

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

    Hi Aprit, when we reserve a food packet and delivery agent is not available, then should we not rollback the reservation since the order itself is not placed?

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

      Yes. We would roll back. Plus the timer would ensure that in case we don't the lock is auto-released.

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

      @@AsliEngineering Okay

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

    awesome content .. could you please suggest some beginner friendly resource?

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

      This is beginner friendly 🙂 would recommend going through it twice or thrice. More importantly prototype it locally.

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

    both parts of videos could have been under 30 min (total) if there is no repetitive talk.

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

      Sahi hai. Reel daalna chalu karta hu mai ab.

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

      @@AsliEngineering 😃

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

    Is there an github repo for this code

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

      Don't remember. Check my GitHub profile or description of this video.

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

    👌👌

  • @JUNO2206
    @JUNO2206 7 หลายเดือนก่อน

    Tried 2PC logically However, it's difficult in practice.

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

    can you please send the github link of this code

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

      There is no GutHub repo holding this code. It was a one time short code that I wrote.

  • @a.nk.r7209
    @a.nk.r7209 ปีที่แล้ว

    I've fallen to the right place probably 🤷🏽