Idempotency in APIs: you should be aware of this!

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ต.ค. 2023
  • 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.com/cs/idempoten...
    And don't forget to subscribe for more videos like this 😊
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    The best video explanation of this very critical issue high scale, highly reliable systems face. Subscribed!

  • @onhazrat
    @onhazrat 9 หลายเดือนก่อน +7

    🎯 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

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

    Very helpful!! Thank you for this nice explanation!

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

    Extremely helpful! Thanks a lot! Subscribed!

  • @rajaerobinson
    @rajaerobinson 9 หลายเดือนก่อน

    Great video!

  • @cybersholt
    @cybersholt 9 หลายเดือนก่อน +3

    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

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

    I learned a lot 👌

  • @cariyaputta
    @cariyaputta 9 หลายเดือนก่อน +9

    So it's equivalent to the concept of pure function?

  • @josecarlostoscano5837
    @josecarlostoscano5837 9 หลายเดือนก่อน +2

    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 9 หลายเดือนก่อน +3

      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  9 หลายเดือนก่อน +2

      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.

  • @softwarewitchtmp
    @softwarewitchtmp 9 หลายเดือนก่อน +2

    Should idempotency keys be generated when a user clicks on an order button or when the web page dom content is loaded? I'm asking because you generated it outside of the scope of your request function (which appears to be the second approach).

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  9 หลายเดือนก่อน +1

      Great question! I would say it's debatable, but I'd suggest to generate it when the user clicks an order button, as it then aligns with the user intent. Meaning we won't be generating anything if the user leaves the page without actually ordering anything. And my bad, I didn't depict it clearly in the video ;)

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

      @@SoftwareDeveloperDiaries Should not it be created by backend. Client makes one request to get the key and backend response the key. Again Client use that key on header make request for payment then Backend check key is exist and make payment and delete the key. Client request again with same key then Backend response payment is already created since there is no idempotency key to check.

  • @kazuar87
    @kazuar87 9 หลายเดือนก่อน +1

    6:37 what kind of cache? The automatic subtitle does not get it either... :)

  • @developerfoe
    @developerfoe 9 หลายเดือนก่อน +1

    amazing video

  • @AhmedAli-jx9ie
    @AhmedAli-jx9ie 9 หลายเดือนก่อน +2

    how exactly the request will be retried with the same idempotency key?

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  9 หลายเดือนก่อน +3

      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.

  • @abdrnasr
    @abdrnasr 9 หลายเดือนก่อน +2

    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  9 หลายเดือนก่อน +2

      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 :)

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

    Hey! nice explanation.. Which software you are using to demonstrate this..

  • @viraj_singh
    @viraj_singh 9 หลายเดือนก่อน

    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.

  • @verb0ze
    @verb0ze 7 หลายเดือนก่อน

    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 หลายเดือนก่อน

      Exactly! HTTP methods are just conventions: devs are free to implement them however they like.

  • @M0HCT3R
    @M0HCT3R 9 หลายเดือนก่อน

    It would be interesting to see the solution for backend

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  9 หลายเดือนก่อน +3

      Hope this is somewhat of a help :)
      medium.com/dsc-hit/creating-an-idempotent-api-using-node-js-bdfd7e52a947

  • @EmmanuelOdii80
    @EmmanuelOdii80 9 หลายเดือนก่อน

    Hey, Great video.
    Meanwhile, I'd love to know if tou use Nest js :)

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  9 หลายเดือนก่อน +1

      Thanks mate! No I haven’t used it yet, do you? 🙂

    • @EmmanuelOdii80
      @EmmanuelOdii80 9 หลายเดือนก่อน

      @@SoftwareDeveloperDiaries It's been the go-to for my SaaS products :)