Laravel solved race conditions

  Рет қаралды 14,577

Aaron Francis

Aaron Francis

Күн бұрын

Learn all about the power of Laravel's atomic locks! I demonstrate how to grant unique access to resources, mitigate race conditions, and draw pretty red and green boxes on the screen.
Follow me on Twitter at aarondfrancis or check out my website at aaronfrancis.com.
Links:
• laravel.com/docs/10.x/cache#a...
----
00:00 Demo
01:12 Compatible cache drivers
01:37 Creating a lock
04:00 Working with multiple processes
06:03 Running in a loop
07:10 Drawing red/green backgrounds
09:23 Choosing the right driver
10:38 Database locking
12:40 Locks versus queues
----

Пікірлер: 63
@ahmad-murery
@ahmad-murery 7 ай бұрын
I wish you can make more Laravel courses just like the MySql for developers series where you start with the basics but with good details. Thanks Aaron!
@Voltra_
@Voltra_ 6 ай бұрын
You'd be surprised how many web developers don't know/understand that the web is a fundamentally distributed system and thus don't use any kind of synchronization primitives when they're required
@bballantyne3
@bballantyne3 7 ай бұрын
Your presentation style is ideal for me. Thank you!!!
@SurprisingLee
@SurprisingLee Ай бұрын
Having written almost exactly this locking system to prevent a race condition on Laravel v9, for ecommerce checkout no less, I can appreciate the good design behind this.
@alchemist_dk
@alchemist_dk 7 ай бұрын
This channel is pure gold, thanks for all the info.
@spicynoodle7419
@spicynoodle7419 7 ай бұрын
I've requested this topic a few times. Thanks for delivering ❤
@irvanicsmoke1132
@irvanicsmoke1132 7 ай бұрын
this is why i subbed for!! Your explanation is always easy to understand and the delivery is so enjoyable :D Would be great if you also explain concurrency control like optimistic vs. pessimistic locking. Thanks once again Aaron!
@aarondfrancis
@aarondfrancis 7 ай бұрын
You mean database locking? I might cover that on the PlanetScale channel!
@agussumawigena4565
@agussumawigena4565 7 ай бұрын
sifu, you are very talented at transferring knowledge
@davidharting3119
@davidharting3119 7 ай бұрын
Maybe it’s a common Laravel idiom but doing while(1) instead of while(true) has a very devil-may-care attitude to it. I must say it shivered my timbers.
@davidharting3119
@davidharting3119 7 ай бұрын
Clutching my pearls!
@FarazSamapoor
@FarazSamapoor 7 ай бұрын
I'm just so happy that we have you on our side. You are a great teacher and visualizing the examples vastly improves the learning experience. Thank you, Aaron! As a side note, I think it would be great if you could clean up the IDE a bit, as it distracts the viewer from the main content. I think hiding the "Tool Window Bars" would be a great start. You can find the option to hide them under Settings => Appearance & Behavior => Appearance => Tool Windows. Or just hit the shift key twice and search for the "tool window bars".
@aarondfrancis
@aarondfrancis 7 ай бұрын
Good idea! Thank you
@GringoDotDev
@GringoDotDev 7 ай бұрын
I don't have anything to say except that you make fantastic videos!
@aarondfrancis
@aarondfrancis 7 ай бұрын
Well I'm glad you said that! That makes my day. Thank you
@Novica89
@Novica89 7 ай бұрын
Awesome video and explanation on how to use atomic locking :) Even though I've used them and know how they work, it was a nice overview and confirmation that I was using them properly :D
@JeremyAndersonBoise
@JeremyAndersonBoise 7 ай бұрын
I have been using Laravel for a ten years or so, but not in-depth for the last two. I need to look at this, this looks like a great improvement, thanks for the tip-off!
@aarondfrancis
@aarondfrancis 7 ай бұрын
Glad you liked it!
@kirayamato6128
@kirayamato6128 7 ай бұрын
love you Aaron! The way you explained really makes me easy to understand the laravel and mysql. kudos!
@demian.succs0
@demian.succs0 7 ай бұрын
I've seen your videos on the planet scale channel and didn't know you have yours own lol, thanks KZbin algorithm to take me to the right place
@asjidali5453
@asjidali5453 6 ай бұрын
Incredible!
@MrNichuya
@MrNichuya 7 ай бұрын
Great video!
@thegrumpydeveloper
@thegrumpydeveloper 7 ай бұрын
Nice that this is built in
@zinatziaee5000
@zinatziaee5000 7 ай бұрын
Thanks very good
@etiennez0r846
@etiennez0r846 7 ай бұрын
wow what a clever way to solve locks by inserting a unique key lol never thought of that xD
@aarondfrancis
@aarondfrancis 7 ай бұрын
Sneaky right
@aliffiansyahmaulana
@aliffiansyahmaulana 6 ай бұрын
I think its similar to withoutOverlapping() in task scheduler
@gfni
@gfni 7 ай бұрын
Great video as per! Can this be used in a simple user request so only one user can do something at once.. lets say on checkout? or is this used primarily in worker/job based solutions?
@aarondfrancis
@aarondfrancis 7 ай бұрын
It totally could, I suppose! You might need a little more scalable, robust strategy for that though. If you've got thousands of users fighting over a single lock, that's probably gonna create a pretty gnarly bottleneck. Something like this would be more useful for coordinating backed processes fighting for limited resources.
@aslamh
@aslamh 5 ай бұрын
Whats the different between pessimistic locking and cache lock?
@ajzack983
@ajzack983 Ай бұрын
does this relate to ShouldBeUnique interface of the laravel jobs ?
@thegrumpydeveloper
@thegrumpydeveloper 7 ай бұрын
Would be cool to make an equivalent in js with other db locks.
@aarondfrancis
@aarondfrancis 7 ай бұрын
Yup that'd be really neat! Could be a Prisma or Drizzle plugin maybe
@pablorgto
@pablorgto 7 ай бұрын
Please, make an video about the Drupal 10?? Thank you!!!
@aarondfrancis
@aarondfrancis 7 ай бұрын
You don't have to comment the same thing on every video 🫠
@TurkerTUNALI
@TurkerTUNALI 7 ай бұрын
Php guys finally enters the enterprise area. Great feature by the way.
@aarondfrancis
@aarondfrancis 7 ай бұрын
Haha, I guess?
@Stoney_Eagle
@Stoney_Eagle 7 ай бұрын
Did you just use tailwind in the terminal?!!!! Omg 😮😍🤩
@aarondfrancis
@aarondfrancis 7 ай бұрын
Haha yup! 07:10 I mention Termwind!
@Stoney_Eagle
@Stoney_Eagle 7 ай бұрын
@@aarondfrancis Yeah I could not believe my eyes, I had to verify this magic 😂
@norc
@norc 6 ай бұрын
Does someone know if the octane cache driver is supported?
@aarondfrancis
@aarondfrancis 6 ай бұрын
I'm not sure!
@lighty262
@lighty262 7 ай бұрын
Kinda similar to flock function in PHP
@aarondfrancis
@aarondfrancis 7 ай бұрын
Does that communicate across processes? I'm not familiar with it
@lighty262
@lighty262 7 ай бұрын
@@aarondfrancis It uses file system lock/release instead of caching driver in your video, all php process will use flock function to check wether the file is lock or not, that's how they communicate.
@labkita
@labkita 7 ай бұрын
give a real example using job with atomic locks on race condition case like inserting data
@brunocmesquita
@brunocmesquita 7 ай бұрын
Hey man, great content. Would you be interested in making a video on your IDE and terminal configuration?
@aarondfrancis
@aarondfrancis 7 ай бұрын
Potentially! Although I don't really customize my setup hardly at all. It's just pretty standard PHP storm
@thebirdhasbeencharged
@thebirdhasbeencharged 7 ай бұрын
@@aarondfrancis Font and theme
@SaiyanJin85
@SaiyanJin85 7 ай бұрын
we better stick with redis since it's really easy to share between completely different servers.
@aarondfrancis
@aarondfrancis 7 ай бұрын
Agreed! Redis or db.
@mohamedrifkan6577
@mohamedrifkan6577 7 ай бұрын
This is like golang 😮
@vsakthivel85
@vsakthivel85 7 ай бұрын
But this lock won’t works if we use file cache
@aarondfrancis
@aarondfrancis 7 ай бұрын
For multiple processes on the same server it will. Mentioned at the end
@iWhacko
@iWhacko 7 ай бұрын
how are database and file locks surprising? A database lock can be great when migrating data, so it's locked to prevent new data to be inserted. And file locks can be great if a file is still being written to, before reading it. or some other reason.
@aarondfrancis
@aarondfrancis 7 ай бұрын
A database lock is not surprising! Using a plain ol' unique key as a shared application lock is surprising, and quite clever. You might enjoy some of my database videos at youtube.com/@planetscale.
@iWhacko
@iWhacko 7 ай бұрын
@@aarondfrancis Maybe I'm misunderstanding the issue then. I come from a software engineering background. and worked with low-level hardware too. And using a Mutex (or semaphores) to lock stuff is not new, and can also be done with plain-text keys in most systems. so I must be too set into my mindset to miss a point here I think.
@aarondfrancis
@aarondfrancis 7 ай бұрын
Some of the things you learned a long time ago, other people have not yet learned! And thus the wheel of time continually turns.
@vsakthivel85
@vsakthivel85 7 ай бұрын
But this lock won’t works if we use file cache
@aarondfrancis
@aarondfrancis 7 ай бұрын
Across multiple processes on the same server it will!
@vsakthivel85
@vsakthivel85 7 ай бұрын
Thanks
Make self-healing URLs with Laravel
13:58
Aaron Francis
Рет қаралды 38 М.
Burned out on Javascript
10:08
Aaron Francis
Рет қаралды 13 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 78 МЛН
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 104 МЛН
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 2,6 МЛН
UFC Vegas 93 : Алмабаев VS Джонсон
02:01
Setanta Sports UFC
Рет қаралды 221 М.
Laravel + Livewire todo app (and so much more)
16:41
Aaron Francis
Рет қаралды 33 М.
Database Sharding in 200 Seconds
5:04
PlanetScale
Рет қаралды 20 М.
SQLite is enough
5:58
Martin Baun
Рет қаралды 12 М.
Код ревью участника Laravel комьюнити CutCode
14:46
Просто о Laravel. CutCode
Рет қаралды 4,5 М.
Customizing Laravel Pulse
21:42
Aaron Francis
Рет қаралды 9 М.
SSG is dead. Long live cache.
10:35
Aaron Francis
Рет қаралды 12 М.
Laravel Octane: supercharge your Laravel applications
8:34
Aaron Francis
Рет қаралды 31 М.
Laravel TALL vs VILT Stack: Explained with Examples
12:38
Laravel Daily
Рет қаралды 11 М.
Laravel Cache на Redis
1:02:00
Pavel Zloi aka EvilFreelancer
Рет қаралды 11 М.
How to prevent race conditions in a reservation system
6:34
Web Dev Cody
Рет қаралды 20 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 78 МЛН