The Unit of Work Design Pattern Explained

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

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

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

    👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis.

  • @NewQuietBear
    @NewQuietBear 3 หลายเดือนก่อน

    Interessant, ik heb ORM's gebruikt bijvoorbeeld en alhoewel ik nog niet bekend was met de onderliggende patronen, herken ik een hoop terug doordat ik deze packages ooit heb gebruikt.

  • @iamkaransethi
    @iamkaransethi 6 หลายเดือนก่อน +3

    I liked your calm and composed style of explaining a complex topic.Well done, your 3rd example made the most sense to me in terms of rollbacks scenario - IaC setup seems like a good place to use this design pattern. Thanks, Arjan!

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

      Glad it was helpful!

  • @inhahe
    @inhahe 6 หลายเดือนก่อน +2

    You asked about other ideas for use of the unit of work..one thing that came to mind was installing programs. All program installations seem to be able to roll back everything if the installation fails for some reason.

  • @spanomatic
    @spanomatic 6 หลายเดือนก่อน +3

    Unit of work is used in Guaranteed messaging between systems and applications (messaging middleware). send message and ack that sort of thing. Redis also has batch functions to perform several ops at once.

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

      But in the case of unit of work between systems, you would need a separate system dedicated to centralizing these operations. Would it still be a good idea?

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

      @@kaosce In a best case I would think so too. But I have see it both ways with the middle ware running on the same server as the app, but it is a separate app for sure.

  • @avazart614
    @avazart614 6 หลายเดือนก่อน +4

    Session has method/contextmanager "begin" for control transaction.
    SQLAlchemy has special mixin for using as dataclass "MappedAsDataclass" (for __str__/__repr__)

    • @Lexaire
      @Lexaire 6 หลายเดือนก่อน +1

      SQLAlchemy is so powerful it's almost too powerful. Learning to use everything SQLAlchemy has is like a full time job in itself.

  • @uruzrune7216
    @uruzrune7216 6 หลายเดือนก่อน +1

    Would you consider doing a Saga Pattern video? Also, can you demonstrate using Saga and Unit of Work together to roll back a failed Saga?

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

    Excellent video! I had never heard of this, gives me good ideas how to change our code!

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

      Glad it was helpful!

  • @aashayamballi
    @aashayamballi 6 หลายเดือนก่อน +2

    can you please cover django concepts as well?

  • @klmcwhirter
    @klmcwhirter 6 หลายเดือนก่อน +5

    Please take a look at the echo=True option to the create_engine function. This will ask sqlalchemy to output db interaction info including the sql statements being executed and more ...
    Another great video. The UnitOfWork and Repository patterns are critical to building resilient, reliable persistence layers - and not just with db, but also filesystem, web service APIs, etc. !

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

    My favourite ORM for PHP (sorry) uses UOW... so much nicer than those other Active Record ORMs. I did an extension that logged database changes to.... the database by scanning and extending the UOW on a commit... I had Python friends (I was doing JS) at my old job who used SQL Alchemy and I was always curious as to what was inside... now I really want to try it. UOW is my favorite underrated pattern - "boo!" to Active Record.

  • @jamesclarke7259
    @jamesclarke7259 6 หลายเดือนก่อน +1

    As always thanks, could you maybe do one on django?

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

    I used to work for a PoS company and I accidentally implemented Unit of Work pattern without knowing it existed :) mine was a bit janky though, a dict of bools that was tracked between methods to know from which step we had to rollback

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

    Thank you....would be ideal scenario for embedded DBs (DuckDB, targeting scientific workloads, with specific pythonic libraries)

  • @BuFu1O1
    @BuFu1O1 6 หลายเดือนก่อน +1

    Do a coderoast of the nanogpt repo of Andrej Karpathy

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

    Do I need a different implementation of this pattern for each use-case in my domain?

  • @lucianop.3922
    @lucianop.3922 6 หลายเดือนก่อน

    This looks extremely similar to using an event queue. Throughout the lifetime of your program, you add events to a queue, and you delay their execution to a point where it is convenient (for any reason depending on context, in a game you might want to apply some filtering to change the order of events and process some before others), so it gives you full control on the order of execution. But, it can also help you to see which events failed, and then do the appropriate rollback.
    EDIT: On second thought, it is an event queue, but used in a different context with (potentially) different intentions.

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

      "Command" comes closest in the classic gang of four design patterns, and it mentions having a rollback queue.

    • @TheEvertw
      @TheEvertw 6 หลายเดือนก่อน +1

      Any design pattern is a combination of 4 (sometimes more) classes doing something together. The description of the context makes a design pattern useful.
      Personally, I consider the UoW pattern a merge of the Command and the Decorator patterns. Any queuing feature is not part of the actual pattern, though real implementation will usually have queuing as well. Like most real implementations of the Command Pattern also have queuing, but it is not part of the pattern itself.

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

      Yup, we use Workers in combo with UOWProviders that are responsible for orchestration /execution/rescheduling and gathering any required data to create a UOW.

  • @aflous
    @aflous 6 หลายเดือนก่อน +3

    1st?

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

    Nice video, very useful!

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

      Thank you, glad you enjoyed it!