Optimistic Locking - What, When, Why, and How?

  Рет қаралды 12,245

Arpit Bhayani

Arpit Bhayani

11 ай бұрын

System Design for SDE-2 and above: arpitbhayani.me/masterclass
System Design for Beginners: arpitbhayani.me/sys-design
Redis Internals: arpitbhayani.me/redis
Build Your Own Redis / DNS / BitTorrent / SQLite - with CodeCrafters.
Sign up and get 40% off - app.codecrafters.io/join?via=...
In the video, I explained how optimistic locking can be used as an alternative to pessimistic locking in multi-threaded programs to improve performance. By utilizing the compare and swap semantic, optimistic locking allows one thread to succeed while another fails, reducing contention and improving throughput. I demonstrated the implementation of optimistic locking using a simple C code example and discussed its advantages and disadvantages. Leveraging the underlying CPU architecture for atomic operations is key to efficient optimistic locking. Overall, understanding and implementing optimistic locking can significantly enhance system performance.
Recommended videos and playlists
If you liked this video, you will find the following videos and playlists helpful
System Design: • PostgreSQL connection ...
Designing Microservices: • Advantages of adopting...
Database Engineering: • How nested loop, hash,...
Concurrency In-depth: • How to write efficient...
Research paper dissections: • The Google File System...
Outage Dissections: • Dissecting GitHub Outa...
Hash Table Internals: • Internal Structure of ...
Bittorrent Internals: • Introduction to BitTor...
Things you will find amusing
Knowledge Base: arpitbhayani.me/knowledge-base
Bookshelf: arpitbhayani.me/bookshelf
Papershelf: arpitbhayani.me/papershelf
Other socials
I keep writing and sharing my practical experience and learnings every day, so if you resonate then follow along. I keep it no fluff.
LinkedIn: / arpitbhayani
Twitter: / arpit_bhayani
Weekly Newsletter: arpit.substack.com
Thank you for watching and supporting! it means a ton.
I am on a mission to bring out the best engineering stories from around the world and make you all fall in
love with engineering. If you resonate with this then follow along, I always keep it no-fluff.

Пікірлер: 24
@abdulwakeel6363
@abdulwakeel6363 11 ай бұрын
This channel has enough content to become a senior backend engineer who are at beginner or mid senior level. Thank you Arpit so much
@cooldudecs
@cooldudecs 10 ай бұрын
My goal is Staff is so this has been great , even for references to modeling what already is out there rather than re inventng the wheel. Thanks!
@thegreekgoat98
@thegreekgoat98 10 ай бұрын
Hey Abdul, can you please tell me where to start. Right now I have just passed out in 2023, and joined a company as a backend developer.
@sandy4799
@sandy4799 2 ай бұрын
This is really awesome. Got satisfying answers for the doubts I had on contention for CAS operation by two threads. If one wants to be like him your thinking should be like DFS graph traversal, keep digging the problem deeper until all your doubts are resolved.
@jaimalad2902
@jaimalad2902 10 ай бұрын
Great teaching technique. Awesome videos. There lot of senior engineers but very few of them has such great teaching skill like arpit
@advaitpundlik8797
@advaitpundlik8797 11 ай бұрын
Great Video !!! I wonder how do you choose your content and what resources you used to learn fundamental concepts in multithreading ? Really Great Work and I look forward to every new video.
@LeoLeo-nx5gi
@LeoLeo-nx5gi 11 ай бұрын
Thanks a ton, it was quite clear!!
@ashishsinghchauhan6304
@ashishsinghchauhan6304 11 ай бұрын
Good tutorial Arpit sir.
@bhanuarora4504
@bhanuarora4504 3 ай бұрын
Amazing content, these internals are very interesting, thank you so much arpit
@prashantgupta6160
@prashantgupta6160 10 ай бұрын
Amazing bro, learned a lot
@rahulkapoor7305
@rahulkapoor7305 5 ай бұрын
In optimistic locking there is a concept of Time-of-check to time-of-use when we are checking the old value to be old value => so that we can write it to the new value. there can be another thread which will actually update it in the time being of this checking and updating. and current thread might be a case of also picking up old value = old value. here the race condition might occur
@samworldpk
@samworldpk 2 ай бұрын
Please help me in this scenario, If my app is load balanced and I have 2 nodes running under it. When 2 requests arrived to update the same resouce. How can Optimistic Locking works? There will be 2 machines and each can execute compare_and_swap or (TOC and TOU) same time.
@samworldpk
@samworldpk 2 ай бұрын
Please help me in this scenario, If my app is load balanced and I have 2 nodes running under it. When 2 requests arrived to update the same resouce. How can Optimistic Locking works? There will be 2 machines and each can execute compare_and_swap or (TOC and TOU) same time or a race condition may be.
@shishirchaurasiya7374
@shishirchaurasiya7374 9 ай бұрын
Today, I realised going through the content only once is not enough, as a human we loses many important points, finally completing this series for the 2nd time 😍😍 and what I am feeling right now I can't even express, feeling like I can be a TEAM LEAD 😅 at this time by knowing these little little minute details
@rajatmehta8499
@rajatmehta8499 11 ай бұрын
This CaS operation is used in lmax disruptor too
@aditya7955
@aditya7955 11 ай бұрын
Quick question around cpu context switch. Most CPU’s have multiple cores and this comparison function would be running on a single core. Does that mean other cores are also at halt for the time being or they can execute a parallel thread?
@AsliEngineering
@AsliEngineering 11 ай бұрын
It depends on the architecture. Some block the cores, while other block the memory location.
@joobis.b4568
@joobis.b4568 11 ай бұрын
@@AsliEngineering had this question in mind, thanks for clarifying
@queenslayerthefifth1771
@queenslayerthefifth1771 9 күн бұрын
Why loading the count variable is atomic?
@sachinpandhare5143
@sachinpandhare5143 9 ай бұрын
Nice! But example is misleading, if goal is to just increase the count, then atomic increment is a better choice, better example for compare and exchange would be implementing mutex itself or spinlock, correct me if I am wrong :)
@akhilpandey9054
@akhilpandey9054 10 ай бұрын
I have one question, you mentioned pessimistic locking might become a bottleneck in your multithreaded application if the number of cofilicts (threads) to aquire a lock is very high. How does optimistic locking help here in increasing the throughput, as you mentioned during the same situation optimistic locking will also not perform well?
@user-kq5om9bi3i
@user-kq5om9bi3i 3 ай бұрын
arpit bhaiya ji please recommend a book to learn all of these CPU instructions and also linux commands for accessing process control blocks
@SaketAnandPage
@SaketAnandPage 7 ай бұрын
Using complex variable name.
@Xresus
@Xresus 10 ай бұрын
Bro Hindi mein Bana sakti ho ,agar ATI ho to English mein content bhaut hai youtube par Par Hindi mein kam😅
Peeking into assembly code to understand why count++ is not atomic
14:12
Why do databases store data in B+ trees?
29:43
Arpit Bhayani
Рет қаралды 30 М.
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 9 МЛН
Children deceived dad #comedy
00:19
yuzvikii_family
Рет қаралды 7 МЛН
what is OPTIMISTIC LOCK?
18:41
Tech Dummies Narendra L
Рет қаралды 57 М.
How Giphy uses CDN to serve 10 billion GIFs every day
16:33
Arpit Bhayani
Рет қаралды 10 М.
Designing Idempotent API Endpoints for Payments at Stripe
14:26
Arpit Bhayani
Рет қаралды 22 М.
How Instagram efficiently serves HashTags ordered by count
12:18
Arpit Bhayani
Рет қаралды 13 М.
What is an API and how do you design it? 🗒️✅
15:26
Gaurav Sen
Рет қаралды 713 М.
Coding Was Hard Until I Learned THESE 5 Things!
7:40
Pooja Dutt
Рет қаралды 1 МЛН
FASTEST Way To Learn Coding and ACTUALLY Get A Job
10:44
Brian Cache
Рет қаралды 962 М.
CAP Theorem - From the First Principles
42:42
Arpit Bhayani
Рет қаралды 22 М.
После ввода кода - протирайте панель
0:18
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 2,4 МЛН