How do Transactions Work? | Get to know Cloud Firestore #8

Поделиться
HTML-код
  • Опубликовано: 16 апр 2019
  • Transactions can help you avoid race conditions and strange inconsistencies in your database application. But what is a transaction, and how do they work? What is the difference between a client-side and server-side transaction in Cloud Firestore, and how are they different from batched writes? Find out the answers to all of these questions and more in this episode of Get to Know Cloud Firestore!
    More episodes on Cloud Firestore → goo.gle/Cloud-Firestore
    Subscribe to Firebase → goo.gle/Firebase
  • НаукаНаука

Комментарии • 92

  • @Lindauson
    @Lindauson 5 лет назад +160

    I love Todd's style. His tutorials are excellent!

    • @MatthewChenIsAwesome
      @MatthewChenIsAwesome 4 года назад +5

      Literally the most fun I've ever had watching any programming tutorial. Seriously, his sense of humor is top-notch.

    • @vijayshinde85
      @vijayshinde85 2 года назад +1

      Me to

    • @DodaGarcia
      @DodaGarcia 8 месяцев назад

      He's so entertaining!! His videos have been a huge factor in making me want to look more into Firebase, and now I use it for almost every project.

  • @itwasmattgregg
    @itwasmattgregg 5 лет назад +36

    I once made a game where a hundred people all started button mashing arrow keys all at the same time which were supposed to update a single shared location amongst everyone through transactions (basically twitch plays pokemon). I ran out of my free tier reads in under 30 seconds because nobody's transactions went through... :) I learned a lot that day...

    • @LightDragooon
      @LightDragooon 3 года назад +8

      And I learned from this comment, thanks!

    • @fswirecard5595
      @fswirecard5595 Год назад +1

      @@LightDragooon what exactly is the learning from this comment? i am trying to learn

  • @abdullahkarimi2106
    @abdullahkarimi2106 5 лет назад +72

    I love firebase please be more active in RUclips

    • @JonathonBroughtonUK
      @JonathonBroughtonUK 5 лет назад +3

      are you kidding? firebase team's youtube content is second to none!

  • @Imban3z
    @Imban3z 2 месяца назад

    Protect Todd at all costs! Best teaching flow I've seen in my life

  • @Joekay1956
    @Joekay1956 5 лет назад +13

    You saved me a lot of time with this video. It's like you know about my needs :D thanks a lot for this video.

  • @adilbasharat
    @adilbasharat 2 года назад +8

    I wish my teachers had your skills. This was a perfect explanation about Transactions. Thank you, Todd. Also, that you make a good attempt to be funny :)

    • @Firebase
      @Firebase  2 года назад +1

      Glad it was helpful!

  • @rara737
    @rara737 5 лет назад +3

    I`ve been waiting for this cloud firestore videos keep going Firebase

  • @100babaj
    @100babaj 3 года назад

    You do a great job explaining these concepts. Loving the firebase products

  • @ppotter10
    @ppotter10 4 года назад +1

    These videos are well made. Very insightful, thanks!

  • @danich46
    @danich46 4 года назад +1

    Literally amazing tutorials!

  • @1002CK
    @1002CK 5 лет назад +1

    Finally another video from this series

  • @SmashHighlights
    @SmashHighlights 5 лет назад +3

    Exactly what I needed, thanks!

  • @donathmm3881
    @donathmm3881 5 лет назад +1

    Thank you! Excellent video !

  • @davidhernandez9275
    @davidhernandez9275 Год назад +1

    Thank you so much for explaining this so easily and beautifully. Thanks again

  • @DenisTRUFFAUT
    @DenisTRUFFAUT 5 лет назад

    Very good and practical use cases !

  • @_sr
    @_sr 5 лет назад

    Very well explained. Thanks.

  • @0mane0
    @0mane0 4 года назад

    this guy is literally the best, damn theese tutorials are greate

  • @eddiejaoude
    @eddiejaoude 5 лет назад +3

    This is great 👍. Thank you 🤓

  • @tomascarignano5002
    @tomascarignano5002 2 года назад +1

    Love this course!

  • @CalvinNL
    @CalvinNL 2 года назад +1

    Perfect explanation, thanks!

    • @Firebase
      @Firebase  2 года назад

      Glad you enjoyed it!

  • @mohammedmusthafa8394
    @mohammedmusthafa8394 4 года назад +2

    Well, that was an awesome explanation :)

  • @planetmall2
    @planetmall2 5 лет назад

    Thank you for this video.

  • @connorflewitt8377
    @connorflewitt8377 2 года назад

    Great video! Thank you!

  • @anirudhganesh
    @anirudhganesh 4 года назад

    I just thought about this only after implementing the logic for my app (not a lot but had to do a significant amount of work) and then remembered this problem when I wanted to update the same document from multiple users. Here we go again!

  • @PaulFidika
    @PaulFidika 9 месяцев назад

    Firestore is amazing. I love it

  • @mahbubhasan5905
    @mahbubhasan5905 5 лет назад

    Nice one... help a lot...

  • @vishalgaware3432
    @vishalgaware3432 5 лет назад

    Excellent work! (The PubG one) 😉

  • @DodaGarcia
    @DodaGarcia 2 года назад

    This was so fun to watch

    • @DodaGarcia
      @DodaGarcia 2 года назад

      And I wrote this before I even saw the part with the puns with the word “fun”

  • @rabiahamouda8747
    @rabiahamouda8747 5 лет назад

    Awesome!

  • @kewaldangal8750
    @kewaldangal8750 3 года назад

    Thank you so much

  • @rebeloper
    @rebeloper 5 лет назад +1

    Counters Documentation:
    firebase.google.com/docs/firestore/manage-data/add-data#update-data
    Distributed Counters Documentation:
    firebase.google.com/docs/firestore/solutions/counters
    Increment operations are useful for implementing counters, but keep in mind that you can update a single document only once per second. If you need to update your counter above this rate, see the Distributed counters page.

  • @sethgraham8645
    @sethgraham8645 5 лет назад +11

    At 10:43, He talks about a new feature that allows you to increment data with the most recent version of the data. Does anyone know if he is referring to the increment function that is a part of FieldValue, distributed counters, or something else that I did not mention?

  • @logemann74
    @logemann74 4 года назад +1

    awesome tutorial and funny

  • @AshishYadav-eh8bl
    @AshishYadav-eh8bl 3 года назад

    Oh man. You make life easy.

  • @tomascarignano5002
    @tomascarignano5002 2 года назад +1

    In Firebase V9, the special function that increments a value without needing to write a transaction is called 'increment'.

  • @TrisnoadiWikantoro
    @TrisnoadiWikantoro 4 года назад

    I wasn't aware of these potential bugs to my app. Fortunately this video showed up in recommendation

  • @dneimke
    @dneimke 5 лет назад

    Fantastic! How did you create this video?

  • @adarsh_hatwar
    @adarsh_hatwar 5 лет назад +1

    Nice video.... Could you point me to documentation regarding the new add functions to increment/decrement a counter... Thanks

    • @adarsh_hatwar
      @adarsh_hatwar 5 лет назад

      @@ToddKerpelmanCorp Nice one Todd. I really like where this is going. superb work on the video

  • @AndrewLoiacono
    @AndrewLoiacono 5 лет назад +1

    Would it be a bad idea to create a matchmaking system with transactions? I feel like it would fail more often then it would succeed and that might be a problem cost wise, i'm not really sure. For example if you had a ton of users matchmaking all at once. Some users would get lucky and find a game immediately. While most other users would need to keep retrying until a spot that was open was not stolen before the data was committed.

  • @rickloyd8208
    @rickloyd8208 5 лет назад +2

    As always awesome video! However, transactions would not help in situation when, I checked that opponent has enough gold, I still have a pan but what if opponent have not updated database yet? What if he is playing offline and spent all gold on some upgrade? I will successfully trade with him and when he will get online/sync with database, he will get my pan for free... correct me if I am wrong

    • @moomoomamoo
      @moomoomamoo 5 лет назад +2

      If you limit spending to only transactions, you should be able to avoid this issue all together since upgrading requires spending gold. If this isn't good enough, you could enforce an offline system for currency where when it's time to sync backup to an online state, you could run some logic on whether or not it is fair to allow the upgrade to be synced to the database.

  • @d4lep0ro
    @d4lep0ro 4 года назад

    Even though I hate firebase, gotta say this is very well presented. Good job

  • @hieptran5553
    @hieptran5553 5 лет назад

    @
    Todd Kerpelman
    do you have any suggestion when I caculate some math like total money of invoice in few years then I compare each year growing rate( 36 500 document invoice / year). => should I download all (36500 document * years) then do sum math on client or do it on firebase function sir? please help me, I really need your suggestion.

  • @FikirLyrics
    @FikirLyrics 4 года назад

    sanFrancisco to funfrasisco , that was in deed a greate idea

  • @ianjaspersantos8915
    @ianjaspersantos8915 5 лет назад +6

    Does it affect the pricing for transaction if it fails and start to read again?

    • @ianjaspersantos8915
      @ianjaspersantos8915 5 лет назад

      @@ToddKerpelmanCorp Thank you :)

    • @ianjaspersantos8915
      @ianjaspersantos8915 5 лет назад +2

      @@ToddKerpelmanCorp maybe you should try to make videos related to firestore together with storage :)

  • @dave1675
    @dave1675 5 лет назад

    I have a transaction setup that is calculating an average (similar to the average review example used). Since transactions don't wonk in offline mode, the average is not updated with any new data input while the app is offline. Is there a way to queue up a transaction to run when the app comes back online?
    Or how can I best keep calculating the average online and offline?

    • @dave1675
      @dave1675 5 лет назад

      @@ToddKerpelmanCorp Thanks I'll give it a try!

  • @lenzpaul2205
    @lenzpaul2205 4 года назад +2

    9:38 what does he mean by “individual document reads, not queries”?

    • @khaledx1000
      @khaledx1000 3 года назад

      @CharletteGHz But then later @ 13:52 he says he can create a transaction where he can perform a query. Now I am confused, can a transaction perform a query inside or not?!
      Maybe it is allowed on the server, but that is not mentioned explicity.

  • @soumitripattnaik
    @soumitripattnaik 3 года назад

    For the last example, can't we use a batch update to update the city name of all restaurants?

  • @TheMikkelet
    @TheMikkelet 4 года назад

    hey so is it suggested to use transaction at all times? What if you app has a lot of users, is it necessary to use transactions for even trivial stuff?

    • @ccgarciab
      @ccgarciab 3 года назад

      Uh, no, clearly no. Almost explicitly said so around the 10:20 mark.

  • @anikTheOrange
    @anikTheOrange 4 месяца назад

    Just to clarify, "Batch write does not work or available for realtime database at least with the client sdk" - is this statement right???. Please clarify. By the way, great informative content.👍👍👍

  • @franamu
    @franamu 10 месяцев назад

    Hello, good day. How could I create a hotel reservation system where users can book a room, pay with Stripe or PayPal, and assign them the corresponding room? The challenge is to prevent another user from trying to book the same room at the same time while one user is making a payment. Is this possible with transactions? What happens if I charge the user, and the transaction detects a change and doesn't commit the changes, then it retries and charges again? Or how can I work in a scenario where it's very likely that users want the same product at the same time?

  • @lukecross5439
    @lukecross5439 4 года назад

    so are impressive, the unique problem with firestore is the price for the big apps

  • @Rajukumar-nl2ok
    @Rajukumar-nl2ok 4 года назад

    Hi, Could you please help me out. How can i get the total number of documents without getting documents data, i just want total counter. I have googled a lot but no luck. For, small collection i can get total number but if large collection then it might cause problem of memory issue & documents read coast.
    Language : PHP

  • @teamsalvation
    @teamsalvation 3 года назад

    You mention that transactions **assume** (6:19) the documents will not change. So there is no built-in locks on the documents? Will two transactions ran at the same time against the same documents changing the same fields cause inconsistencies? How is this any better than a batch write?
    Ah, 12:34, documents are locked - OK, so then why the "assume"? What detail are we missing? If documents are locked as a part of the transaction process, why is it only assumed that the documents don't change?

    • @TheSparkart
      @TheSparkart 3 года назад

      I believe the layout that the video assumes involves three parties: client, server, and database. He speaks about locking as a typical method to solve race issues and states that the server actually does this. It's a little bit confusing the way he words it because he prefaces it with transactions being a solution to a problem with unreliable clients locking and then keeping the resource locked. Resource locking is generally an ideal solution, but you cannot resource lock when you cannot guarantee the editor's availability to unlock it. So the client should never be allowed to lock because you can't guarantee it will be around to unlock. That's the only reason for the first method, because it's not a good idea to let the client lock your data and disappear.

  • @seriouslee4119
    @seriouslee4119 3 года назад

    How does transactions and batches affect pricing?

  • @MrBibipkins
    @MrBibipkins 4 года назад

    Had to check my slack xD

  • @bartl9798
    @bartl9798 3 года назад

    If the logic is only implemented client-side, how does that protect against exploits?

  • @itssidhere
    @itssidhere 2 года назад

    Can anyone tell me if the transaction or batch write fails due to 1write per second does it throws any error

  • @code-to-design
    @code-to-design 5 лет назад

    I dont get firebase recommended anywhere in the forum for large scale app to profitable at all

  • @user-ym8jh2tz6y
    @user-ym8jh2tz6y 11 месяцев назад

    optimistic concurrency seems the same concept of eventual consistency

  • @dharmarajr24
    @dharmarajr24 4 года назад

    Trust me!! You should a professor in a top University..

  • @mjonausk
    @mjonausk 4 года назад

    Funfetti. Lolz :)

  • @markusgattol
    @markusgattol 5 лет назад +3

    lol, the FED doesn't seem to have transactions... they create money like that ;)

  • @gabrielapena8278
    @gabrielapena8278 Год назад

    What is the diference between this and promise.all?

  • @brianlarsen3209
    @brianlarsen3209 4 года назад

    Is this Transaction the same as using Facebook's dev dataloader?

  • @bryan333333333333333
    @bryan333333333333333 5 лет назад

    Diablo 1 had a dupe bug and it was still a great game

  • @ricko13
    @ricko13 3 года назад

    Every video I watch from this channel makes me wanna go back to SQL
    MySQL ♥

  • @ashishtrivedi6426
    @ashishtrivedi6426 4 года назад

    How you create those little cartoons . i like them ?? name pls ..

  • @mikami5799
    @mikami5799 4 года назад

    How much is +3 Todd?

  • @robertshawnmitchell
    @robertshawnmitchell 5 лет назад

    Champing* at the bit

  • @kewaldangal8750
    @kewaldangal8750 3 года назад

    Ido not like bisuness group date and online payment system. Thank you

  • @thedevguild7525
    @thedevguild7525 2 года назад

    Lol! what is a plus-3 pen

  • @trihargianto
    @trihargianto 4 года назад

    The explanation is good but it’s too fast. For someone that is not good in English like me, it’s quite confusing 😅 but, thanks for making this video 😁

  • @SamuelHauptmannvanDam
    @SamuelHauptmannvanDam 4 года назад

    Pretty sure Diablo 2 Duping was exactly exploiting this.

  • @thainguyen4808
    @thainguyen4808 5 лет назад

    it's not necessary to explain like this way!