Тёмный

Idempotency in APIs: you should be aware of this! 

Software Developer Diaries
Подписаться 35 тыс.
Просмотров 14 тыс.
50% 1

Idempotency is an important aspect of designing APIs and how they interact with other microservices or external modules. It's definitely a best practice to consider when building an API. It's used to avoid critical errors in the system and keep the business logic in tact.
Consider becoming a member of the channel by joining me ❤️
/ @softwaredeveloperdiaries
🙌 Become my Patreon and get exclusive perks: / softdevdiaries
💼 Follow me on LinkedIn and drop me a message if you'd like: / gusgadirov
💻 Also, let's connect on GitHub: github.com/gusgad
📚 Resources:
A full article on Idempotency: www.baeldung.c...
And don't forget to subscribe for more videos like this 😊

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

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@onhazrat
@onhazrat 11 месяцев назад
🎯 Key Takeaways for quick navigation: 00:55 🔄 Item potency means the same operation produces the same result, crucial for consistent API behavior. 03:15 📝 Pay attention to the "post" and "patch" HTTP methods, as they can create or modify data, demanding careful handling of item potency. 04:41 🔑 The solution to item potency issues involves using an item potency key (X-Item-Poy-ID) to ensure requests aren't processed multiple times. 05:08 💾 Store the item potency key in a memory system, such as a database or cache, to manage consistent API behavior. 06:58 ✅ Attach the item potency key to your requests, preventing the same request from being processed twice. Made with HARPA AI
@mujibulhaquetanim
@mujibulhaquetanim 2 месяца назад
thanks man
@naveenkumar-pg7te
@naveenkumar-pg7te Месяц назад
Can this be achieved with transaction? If first request fails in service just revert everything dont create burger and send error message to client
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 дней назад
Yes, that's a great point!
@TannerBarcelos
@TannerBarcelos 5 месяцев назад
The best video explanation of this very critical issue high scale, highly reliable systems face. Subscribed!
@JohnSmithhh
@JohnSmithhh 27 дней назад
Cool video ! How to make ajax request idempotent in a situation where user can create for example cards on the page ?
@cariyaputta
@cariyaputta 11 месяцев назад
So it's equivalent to the concept of pure function?
@positivity1016
@positivity1016 11 месяцев назад
Good point, sounds similar
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
It is 🙂
@henrybigelow3570
@henrybigelow3570 Месяц назад
No. A pure function is a function that has no side effects. An idempotent function is one that, if called once, has the same side effect as if it is called more than once.
@MaartenRaasveldt
@MaartenRaasveldt 14 дней назад
Shouldn't you store the idempotency key in the database you're writing the order to so that it's transactional? Otherwise if the program crashes at any point between "executing" the order, and writing the idempotency key to storage (like redis), you'll still have the same problem
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 дней назад
Thanks for your comment, that's actually a good point. Storing it together with the main data that's being written is prob the best idea most of the times.
@milindsankeshware423
@milindsankeshware423 10 дней назад
Do you have any video posted on Spring Rest API/ Microservices ? If yes then could you please share ?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 дней назад
Hey mate, unfortunately I don't do Spring specific videos but I talk about microservices in my System Design & Architecture playlist: ru-vid.com/group/PL5Lsd0YA4OMFvX88T5xH93NqBALI7TENz
@abdrnasr
@abdrnasr 11 месяцев назад
Great video! Don't you think that storing this temp value on the client is not the most secure way? A client could easily clear cookie. If there is a mechanism in the backend that deals with duplicate requests, then this is a different story.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Good question! The user should be somewhat aware that if they face an error upon let's say, clicking the "Pay" button and clear their cookies right after that, then that's not in their best interest and can lead to unexpected consequences such as paying twice. At least that's how I see it :)
@idle.observer
@idle.observer Месяц назад
Can someone explain, when we should remove the idempotency key? I think we shouldn't save all the keys forever.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 9 дней назад
Either after the processing has been fully completed, for ex. the order has been delivered to the client or you set a custom TTL.
@josecarlostoscano5837
@josecarlostoscano5837 11 месяцев назад
Would repeated calls of the function ‘makeRequest’ have different values for the idempotency key? If they do, then the api would process both of them, wouldn’t it?
@juraev0056
@juraev0056 11 месяцев назад
Yes, `makeRequest` makes a new request. You should make retry requests with previous failed request's idempotent key. You can see he's handling retries with `shouldRetry`
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
No, the idempotency key is the same for all retries for a particular user. The client can save the key in the SessionStorage while the user is still on the "Order" page and delete it after the order has been placed successfully.
@cybersholt
@cybersholt 11 месяцев назад
Really interesting topic, been doing web development for 20 years and luckily never had anything like uber eats had! But the video was done really well and am looking forward to more from ya. Keep up the great work man
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
That's definitely for the best! :D Thanks mate!
@soulGrafitti
@soulGrafitti Месяц назад
Nice video. I really like your examples and approach. Around 03:33 you discuss why POST and PATCH require idempotentcy but the other HTTP methods don't. There is a lot of information arguing the opposite which I found when I googled POST and PUT. At a glance the reasoning one way or the other seems to depend on the exact use case and how effectively the return status codes are managed. Perhaps you could add some discussion or commentary addressing the divergence of opinion.
@AhmedAli-jx9ie
@AhmedAli-jx9ie 11 месяцев назад
how exactly the request will be retried with the same idempotency key?
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
The frontend can save the idempotency key in the SessionStorage as soon as the customer lands on the "Order" page and use it for every retry. Upon a success, the frontend clears the key.
@kazuar87
@kazuar87 11 месяцев назад
6:37 what kind of cache? The automatic subtitle does not get it either... :)
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Redis 😛
@yusufnurwahid898
@yusufnurwahid898 24 дня назад
Very clear explanation!!! Many thanks!!!
@jonatasdeoliveiracoelho4691
@jonatasdeoliveiracoelho4691 3 месяца назад
Extremely helpful! Thanks a lot! Subscribed!
@rahulbabbar555
@rahulbabbar555 5 месяцев назад
Hey! nice explanation.. Which software you are using to demonstrate this..
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 5 месяцев назад
Eraser.io :)
@CodingWithAuryn
@CodingWithAuryn 8 месяцев назад
Very helpful!! Thank you for this nice explanation!
@verb0ze
@verb0ze 8 месяцев назад
I don't know if I agree with not needing to concern ourselves with idempotency for other methods. I'd say it depends on the API. There are some cases where DELETE for example should be idempotent, like when deleting an item from a doing cart (and setting the total cost for the remainder of the cart
@MrMashyker
@MrMashyker 3 месяца назад
Exactly! HTTP methods are just conventions: devs are free to implement them however they like.
@viraj_singh
@viraj_singh 11 месяцев назад
When I was in my university, I ordered so many free food at the time of the glitch. Later on I was banned from uber eats and then uber and I just made a new uber account ande moved on. :) Great video by the way.
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Hahah nice one!
@developerfoe
@developerfoe 11 месяцев назад
amazing video
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Thanks!
@EmmanuelOdii80
@EmmanuelOdii80 11 месяцев назад
Hey, Great video. Meanwhile, I'd love to know if tou use Nest js :)
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Thanks mate! No I haven’t used it yet, do you? 🙂
@EmmanuelOdii80
@EmmanuelOdii80 11 месяцев назад
@@SoftwareDeveloperDiaries It's been the go-to for my SaaS products :)
@mansoormasoudifard8624
@mansoormasoudifard8624 3 месяца назад
I learned a lot 👌
@M0HCT3R
@M0HCT3R 11 месяцев назад
It would be interesting to see the solution for backend
@SoftwareDeveloperDiaries
@SoftwareDeveloperDiaries 11 месяцев назад
Hope this is somewhat of a help :) medium.com/dsc-hit/creating-an-idempotent-api-using-node-js-bdfd7e52a947
@rajaerobinson
@rajaerobinson 11 месяцев назад
Great video!
Далее
A Beginner's Guide to Event-Driven Architecture
37:28
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Просмотров 83 тыс.
The Thing No One Tells You About Microservices
13:40
Просмотров 61 тыс.
What is Span in C# and why you should be using it
15:15
Session Vs JWT: The Differences You May Not Know!
7:00
Idempotency - What it is and How to Implement it
8:05
Being Competent With Coding Is More Fun
11:13
Просмотров 83 тыс.
What is API Idempotency and Why Is It Important?
12:13
Rest API - Best Practices - Design
15:50
Просмотров 108 тыс.