What is API Idempotency and Why Is It Important?

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ค. 2024
  • Idempotency in APIs is a critical requirement in APIs that create or modify data. In this video, learn what an Idempotent API is, why its important, and how you can create an API that conforms to idempotency. This video is based on an excellent article Malcolm Featonby on 'Making Retries Safe with Idempotency' - aws.amazon.com/builders-libra...
    Looking to get hands on experience building on AWS with a REAL project? Check out my course - The AWS Learning Accelerator! courses.beabetterdev.com/cour...
    🎉SUPPORT BE A BETTER DEV🎉
    Become a Patron: / beabetterdev
    📚 MY RECOMMENDED READING LIST FOR SOFTWARE DEVELOPERS📚
    Clean Code - amzn.to/37T7xdP
    Clean Architecture - amzn.to/3sCEGCe
    Head First Design Patterns - amzn.to/37WXAMy
    Domain Driven Design - amzn.to/3aWSW2W
    Code Complete - amzn.to/3ksQDrB
    The Pragmatic Programmer - amzn.to/3uH4kaQ
    Algorithms - amzn.to/3syvyP5
    Working Effectively with Legacy Code - amzn.to/3kvMza7
    Refactoring - amzn.to/3r6FQ8U
    🎙 MY RECORDING EQUIPMENT 🎙
    Shure SM58 Microphone - amzn.to/3r5Hrf9
    Behringer UM2 Audio Interface - amzn.to/2MuEllM
    XLR Cable - amzn.to/3uGyZFx
    Acoustic Sound Absorbing Foam Panels - amzn.to/3ktIrY6
    Desk Microphone Mount - amzn.to/3qXMVIO
    Logitech C920s Webcam - amzn.to/303zGu9
    Fujilm XS10 Camera - amzn.to/3uGa30E
    Fujifilm XF 35mm F2 Lens - amzn.to/3rentPe
    Neewer 2 Piece Studio Lights - amzn.to/3uyoa8p
    💻 MY DESKTOP EQUIPMENT 💻
    Dell 34 inch Ultrawide Monitor - amzn.to/2NJwph6
    Autonomous ErgoChair 2 - bit.ly/2YzomEm
    Autonomous SmartDesk 2 Standing Desk - bit.ly/2YzomEm
    MX Master 3 Productivity Mouse - amzn.to/3aYwKVZ
    Das Keyboard Prime 13 MX Brown Mechanical- amzn.to/3uH6VBF
    Veikk A15 Drawing Tablet - amzn.to/3uBRWsN
    🌎 Find me here:
    Twitter - / beabetterdevv
    Instagram - / beabetterdevv
    Patreon - Donations help fund additional content - / beabetterdev
    #SoftwareEngineer
    #API
    #Idempotency

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

  • @pro_mode14
    @pro_mode14 ปีที่แล้ว +6

    The Simplicity with which you explain things is just awesome!, also thanks for sharing the reference article.

  • @taylormonacelli
    @taylormonacelli 2 ปีที่แล้ว +8

    So clear and concise. Thank you!

  • @jeromearenas8028
    @jeromearenas8028 ปีที่แล้ว +1

    They never teach this in schools. Saves me alot of time and headaches. Im trying to work out Payment channel apis to my app and I don't know what the hell is the x-idempotency-key in request header stated in the documentation. You earned a subscriber.

  • @user-fn4mx3ur5k
    @user-fn4mx3ur5k 8 หลายเดือนก่อน

    Just such a simple and great explanation. Thanks!

  • @abusamer9
    @abusamer9 ปีที่แล้ว

    Thanks for this video !simple and clean explanation

  • @jamesforster2720
    @jamesforster2720 ปีที่แล้ว

    Super clear explanation, thank you!

  • @malcolmfeatonby3812
    @malcolmfeatonby3812 2 ปีที่แล้ว +2

    Awesome walk through! Thanks for the great content.

    • @BeABetterDev
      @BeABetterDev  2 ปีที่แล้ว +1

      Glad you enjoyed it Malcolm and thank you!

  • @qasimarthuna9254
    @qasimarthuna9254 2 ปีที่แล้ว +13

    I have already implemented this thing but I don't know it is actually a concept in programming.
    Thank you Daniel.
    Now I can show to my boss that I have used something unusual. And which is called idempotent.
    😃😃

  • @maximilianworner1288
    @maximilianworner1288 ปีที่แล้ว +2

    Great video 👍 Perfect explanation right to the point!

    • @BeABetterDev
      @BeABetterDev  ปีที่แล้ว

      Thanks Max! Glad you enjoyed !

  • @christianibiri
    @christianibiri 2 ปีที่แล้ว +1

    Great video!!!! thanks Daniel... this channel is one of the best!!!

    • @BeABetterDev
      @BeABetterDev  2 ปีที่แล้ว

      Thanks Christian! Glad you enjoyed :)

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

    Your videos are so good I can feel my brain consuming and enjoying the information.

  • @farzadb
    @farzadb 2 ปีที่แล้ว

    Great video as usual 👍

  • @jamesmcintyre
    @jamesmcintyre ปีที่แล้ว +3

    Awesome explanation AND presentation! I’ve built countless rest endpoints and consumed countless more clientside but always felt there’s too much room for these edge cases and furthermore wondered how could clients compensate for the edge cases. Thanks! Subscribed!🎉

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

      Glad it was helpful!

  • @pupfriend
    @pupfriend 2 ปีที่แล้ว +2

    Great explanation!

  • @Vinod_Kumar827
    @Vinod_Kumar827 2 ปีที่แล้ว +1

    Amazing video, thanks

  • @VenkataswamiMadala33
    @VenkataswamiMadala33 2 ปีที่แล้ว +1

    Really nice 👍 simply explained

  • @santhoshn3766
    @santhoshn3766 2 ปีที่แล้ว

    Thanks for sharing!!

  • @herbievanbeveren1314
    @herbievanbeveren1314 ปีที่แล้ว

    Very nice!

  • @mrrishiraj88
    @mrrishiraj88 2 ปีที่แล้ว +1

    Thanks

  • @sagarajayathilaka
    @sagarajayathilaka 2 ปีที่แล้ว +1

    Nice explanation

  • @Ace-kt8ry
    @Ace-kt8ry 2 ปีที่แล้ว +1

    thank you

  • @markelca
    @markelca ปีที่แล้ว +2

    How the client in the second call it's supposed to generate the same token id as the first one? Won't just generate a brand new one? Didn't get that part

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

      I didn't get that part either...

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

    without proper rate limit that can lead to DOS by creating infinite requests with new tokens, overwhelming the database. you can intercept the request and change the token!

  • @256JD
    @256JD 2 ปีที่แล้ว +2

    Thank you, it was a very clear explanation. I have a doubt, about the case the retry is made before the first request has been processed by the server. I only think of returning an response stating the request is in process. What should the server return in that case?

    • @rngouveia
      @rngouveia 2 ปีที่แล้ว

      Client-side retries only make sense in very fast operations, and in this case, the retry time should be configured to be long enough. If the client's request is stimulating a long-running process, then you would need to design the solution differently. One common way is making the client's call be asynchronous and the server be the one responsible for doing everything that needs to be done (and retrying if it needs to). The server would also offer API's that inform in which stage the processing of the request is.

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

    Keep in mind if you did use a cache, it would need to be distributed . A cache on a web server in a load balanced and distributed environment would lead to a miss. Without a distributed cache, the database would need to be the source of record (a uniqueness constraint would do it).

  • @shintaii84
    @shintaii84 2 ปีที่แล้ว

    Can you make a similar video on the same thing but now with external api’s that you not control? For me that is an issue. Where the external api is not idempotent and I need to handle this myself. Currently when i need to retry i first do a get request to see if it is there, if yes mark completed. If no send request again.

  • @RayanMADAO
    @RayanMADAO ปีที่แล้ว +1

    I don't understsand the logic behind when the client creates a new token/uuid? If the client wanted to create 2 accounts they'd create a different token on the 2nd request, but if the client wanted to create 1 account and didn't receive a response on the first try and they clicked again wouldn't that create a different token and the server wouldn't know it's the same request?

  • @MrYamrajji
    @MrYamrajji 2 ปีที่แล้ว

    Hello I am really learning from you aws videos but I don't know how to reach you. I am facing a cuncurrency limit issue after running glue job. I am new to my project but I don't know what can help. can you suggest me something.

  • @yacovskiv4369
    @yacovskiv4369 2 ปีที่แล้ว +4

    I am assuming the tokens maintained in the stale store need to outlive the user session? Because if the user remains logged in and retries after the stored tokens are deleted, we'd run into the same issue all over again.

    • @little-by-little-one-trave1770
      @little-by-little-one-trave1770 2 ปีที่แล้ว +3

      Or we can also have a acknowledgement from client indicating that request is successfully handled and discard the token, along with your solution. Acknowledgement solution on itself may not work as acknowledgement itself can get lost.

    • @AlvinC-sz3li
      @AlvinC-sz3li 2 ปีที่แล้ว +1

      User session shouldn't have anything to do with the token here. Token should be stored with your DB record.

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

    How does this work when there is a load balancer. Meaning, the first time token is saved in a different server but the 2nd request goes to a different server because of a load balancer?

  • @marimbanation4118
    @marimbanation4118 2 ปีที่แล้ว +1

    really nice explanation

  • @lizedine
    @lizedine 2 ปีที่แล้ว +2

    how exactly is the client supposed to generate the request token, is it the same idea as before (i.e. using some specific hash function)? if so, how would multiple clients know what function to use if this were a publicly exposed API? sorry if this is a basic question, but that was the only part confusing me. thanks in advance, awesome video.

    • @RAJU9622
      @RAJU9622 2 ปีที่แล้ว +1

      Actually client won’t call the hash function, api gateway have the function (assume like lambda function) so any client calls the Api that function will execute . The hash will be generated based on payload basically all this hash function code will be in backend. If payload is same it know the request came before as stale store have this hash.

    • @kaypakaipa8559
      @kaypakaipa8559 2 ปีที่แล้ว

      @@RAJU9622 are u saying im terms of flow,
      1. Client call api
      2. Lambda hash func executes
      3. Lambda calls or fowards request to the actual api
      Is this the flow? Seems expensive

    • @RAJU9622
      @RAJU9622 2 ปีที่แล้ว

      @@kaypakaipa8559 yes it’s expensive but need to do

  • @nahuelleiva8460
    @nahuelleiva8460 2 ปีที่แล้ว +1

    This can be developed too with some kind of "cache" approach, right? Let's say I don't want to store my tokens in the DB because they refresh after certain periods of time, and instead, I use a temporal cache to store them and as long as the token hasn't refreshed, whenever the client makes an API request I check my cache and if the token already exists I can return a { "success": true } response to the client. Is that correct?

    • @santhoshn3766
      @santhoshn3766 2 ปีที่แล้ว

      +1

    • @BeABetterDev
      @BeABetterDev  2 ปีที่แล้ว +4

      Hi Nahuel, good question. A cache is certainly a viable solution to store the tokens. I would just make sure you use a distributed cache so that any host will be able to assess if it has seen a similar request in the past (even if it was processed on a different host). A TTL feature on the cache is also a good idea!

    • @nahuelleiva8460
      @nahuelleiva8460 2 ปีที่แล้ว

      @@BeABetterDev nice! Thanks for the insight :) and thanks for the quick response and the content! I hope you are having a nice day.

    • @AlvinC-sz3li
      @AlvinC-sz3li 2 ปีที่แล้ว +1

      But do you still want to make the API idempotency after cache expires?

  • @ijanijigar
    @ijanijigar 2 ปีที่แล้ว +2

    Thank you for sharing this.
    A small doubt.. let's say my response is huge with many json fields which are the result of many operations at service layer. If any retry happens, my server can check for the token in store but how can I generate the identical response in this case? I think I shouldn't store each response in any kind of store and map it with token otherwise these big blobs may take significant space.
    Can you please suggest any way around this?
    Thank you once again sir.

    • @AlvinC-sz3li
      @AlvinC-sz3li 2 ปีที่แล้ว

      Your response should be generated by your DB record.

  • @serggie3
    @serggie3 2 ปีที่แล้ว +1

    I like my entity-creation APIs to return the created entity. I don't want them to just return { "success": true }. Is that possible with these tokens?

    • @BeABetterDev
      @BeABetterDev  2 ปีที่แล้ว

      Hi serggie, yes thats a much more standard pattern and what I do in my usual API implementations.

    • @victorliendo2010
      @victorliendo2010 2 ปีที่แล้ว

      Maybe you can link or attach the resource that has been created (or the response as it is supposed to be sent to the client) , then when the token comes in again, you could retrieve the complete response ...

    • @kaypakaipa8559
      @kaypakaipa8559 2 ปีที่แล้ว

      Return id of resource, and success true

  • @liuleo4073
    @liuleo4073 2 ปีที่แล้ว

    Could you tell me what software is used to draw the picture?

    • @BeABetterDev
      @BeABetterDev  2 ปีที่แล้ว

      Hi this is done with Google slides.

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

    OIDC!

  • @GozeLove
    @GozeLove 2 ปีที่แล้ว

    Is there a code example of this concept?

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

    #wan

  • @timothyanderson2166
    @timothyanderson2166 2 ปีที่แล้ว

    Apparently, I've been pronouncing idempotency COMPLETELY wrong for a long time.

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

    witn another word, you are NOT making it 100% idempotent by simply using PUT, you are just saying your api consumer that "this is a put request, so you should expect the same result as long as you do the same request" but actual idempotency is depent on your logic. If your API method has a logic which creates a record in database every single time its requested, then having a PUT method does NOT provide any idempotency automagically. Again its just a convention, like a documentation of your API. You actual implementation of the API method is the one if it is actually idempotent or not.

  • @laxmisuresh
    @laxmisuresh 2 ปีที่แล้ว

  • @Ace-kt8ry
    @Ace-kt8ry 2 ปีที่แล้ว +1

    thank you