Тёмный

The Unit of Work Design Pattern Explained 

ArjanCodes
Подписаться 241 тыс.
Просмотров 22 тыс.
50% 1

In today's video, I'll explain the Unit of Work design pattern, a crucial concept for anyone who regularly interacts with databases. This pattern plays a key role by accumulating all transactions and executing them collectively. But why is this necessary? Find out this video.
🔥 GitHub Repository: git.arjan.codes/2024/unit_of_...
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis.
💻 ArjanCodes Blog: www.arjancodes.com/blog
✍🏻 Take a quiz on this topic: www.learntail.com/quiz/jrbjzq
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/courses/tsdm
The Software Architect Mindset: www.arjancodes.com/courses/tsam
Next Level Python: Become a Python Expert: www.arjancodes.com/courses/nlp
The 30-Day Design Challenge: www.arjancodes.com/courses/30ddc
👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!
Social channels:
💬 Discord: discord.arjan.codes
🐦 X: x.com/arjancodes
🌍 LinkedIn: / arjancodes
🕵 Facebook: / arjancodes
📱 Instagram: / arjancodes
♪ Tiktok: / arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
- Kit Hygh
- Alexander Milden
- Bean
🎥 Video edited by Mark Bacskai: / bacskaimark
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes
🔖 Chapters:
0:00 Intro
0:41 What is the Unit of Work Pattern?
3:53 The Session Object as a Unit of Work
9:44 Benefits of Using the Unit of Work Pattern
11:43 Outro
#arjancodes #softwaredesign #python
DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!

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

 

21 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@ArjanCodes
@ArjanCodes 2 месяца назад
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis.
@iamkaransethi
@iamkaransethi 2 месяца назад
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 2 месяца назад
Glad it was helpful!
@inhahe
@inhahe 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.
@avazart614
@avazart614 2 месяца назад
Session has method/contextmanager "begin" for control transaction. SQLAlchemy has special mixin for using as dataclass "MappedAsDataclass" (for __str__/__repr__)
@Lexaire
@Lexaire 2 месяца назад
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 2 месяца назад
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 2 месяца назад
Excellent video! I had never heard of this, gives me good ideas how to change our code!
@ArjanCodes
@ArjanCodes 2 месяца назад
Glad it was helpful!
@spanomatic
@spanomatic 2 месяца назад
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 2 месяца назад
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 2 месяца назад
@@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.
@aashayamballi
@aashayamballi 2 месяца назад
can you please cover django concepts as well?
@hubstrangers3450
@hubstrangers3450 2 месяца назад
Thank you....would be ideal scenario for embedded DBs (DuckDB, targeting scientific workloads, with specific pythonic libraries)
@edgeeffect
@edgeeffect 2 месяца назад
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 2 месяца назад
As always thanks, could you maybe do one on django?
@greob
@greob 2 месяца назад
Nice video, very useful!
@ArjanCodes
@ArjanCodes 2 месяца назад
Thank you, glad you enjoyed it!
@obsidiansiriusblackheart
@obsidiansiriusblackheart 2 месяца назад
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
@StarLord1996
@StarLord1996 2 месяца назад
Do I need a different implementation of this pattern for each use-case in my domain?
@BuFu1O1
@BuFu1O1 2 месяца назад
Do a coderoast of the nanogpt repo of Andrej Karpathy
@klmcwhirter
@klmcwhirter 2 месяца назад
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. !
@lucianop.3922
@lucianop.3922 2 месяца назад
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 2 месяца назад
"Command" comes closest in the classic gang of four design patterns, and it mentions having a rollback queue.
@TheEvertw
@TheEvertw 2 месяца назад
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 2 месяца назад
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 2 месяца назад
1st?
Далее
The State Design Pattern in Python Explained
19:14
Просмотров 73 тыс.
D3 BMW XM LABEL Король.
31:52
Просмотров 296 тыс.
Stray Kids "Chk Chk Boom" M/V
03:26
Просмотров 31 млн
The Ultimate Guide to Writing Functions
24:31
Просмотров 179 тыс.
Why is Mojo's dictionary slower (!) than Python's?
12:16
Why Don't We Have A Laravel For JavaScript?
12:36
Просмотров 91 тыс.
Python 3.12 Generic Types Explained
18:27
Просмотров 59 тыс.
Should You Use Dependency Injection Frameworks?
14:43
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Unit of Work in ASP.NET Core
14:57
Просмотров 18 тыс.
D3 BMW XM LABEL Король.
31:52
Просмотров 296 тыс.