5 uses for Cloud Functions | Get to know Cloud Firestore #12

Поделиться
HTML-код
  • Опубликовано: 11 июл 2024
  • On this episode of Get to know Cloud Firestore, we’ll dig into some common patterns for using Cloud Functions and think about how you might want to use them in your own apps. Make sure to subscribe and stay tuned for more content from Firebase!
    Chapters:
    0:00 Introduction
    0:46 Simplifying security rules
    4:50 Keeping denormalized data in sync
    7:26 Routine database maintenance
    9:38 Running Firestore on top of a legacy database
    13:56 Building a custom API
    17:57 Tradeoffs of using callable Cloud Functions
    19:08 Outro
    How do Cloud Functions work? goo.gle/32JYM3M
    SQL-like Joins in Cloud Firestore using Cloud Functions → goo.gle/3hhOBYr
    Cloud Functions and Firestore documentation → goo.gle/32ylpbA
    More episodes on Cloud Firestore → goo.gle/Cloud-Firestore
    Subscribe to Firebase → goo.gle/Firebase
    product_area: Firebase; product: Firebase - Cloud Firestore; fullname: Todd Kerpelman; re_ty: Premiere;
  • НаукаНаука

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

  • @zackarybrumfield2
    @zackarybrumfield2 2 года назад +5

    This man NEVER needs to be replaced.

  • @cindysi63
    @cindysi63 Год назад +21

    Todd’s a legend. Informative and entertaining.

    • @Firebase
      @Firebase  Год назад +6

      Thank you for the kind words, Cindy! We're happy to hear you enjoyed this 🙂

  • @jace1037
    @jace1037 4 года назад +51

    Cloud functions are also a great way to hide privileged API keys from clients. Your client makes a request to the cloud function, your cloud function then verifies the client and user and formats a request to a 3rd party service using credentials that you want to keep hidden from clients.

  • @_mono
    @_mono 4 года назад +63

    0:48 #1 Simplifying security rules‬
    4:55 #2 Syncing denormalized data‬
    7:30 #3 Routine maintenance‬
    9:40 #4 Running on top of a legacy database‬
    14:00 #5 Build a custom API‬

  • @averagehelper
    @averagehelper 4 года назад +8

    It’s a joy working with Cloud Functions. We use them all the time in my company’s projects, and it’s been great to keep our Firestore rules manageable. And when things go wrong 😅 it’s super easy to publish a fix so all of our clients can start using the new code almost immediately.

  • @overnightmares
    @overnightmares 3 года назад +1

    I wish I could work with this guy one day. He explains things so clearly. He seems like he can be a very good mentor.

  • @codinginflow
    @codinginflow 4 года назад +29

    Thank you Firebae

    • @AkhilKumar-ys3ph
      @AkhilKumar-ys3ph 4 года назад +1

      What are the big websites that are using cloud firestore as a backend?

    • @lukecross5439
      @lukecross5439 3 года назад +1

      @@AkhilKumar-ys3ph Big? None, the big websites are currently using AWS or Azure with other SaaS

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

    This video is awesome! Learned a lot, got some work flows confirmed, thanks!

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

    back with a Great video!! Thanks Todd 2020

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

    what an awesome session ! enjoyed it with Todd in live chat !

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

    thanks so much for this series

  • @lalalarara9209
    @lalalarara9209 4 года назад +4

    already exciting

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

    There are great patterns and ideas about Cloud Funtions in the video Todd, thanks!
    I'm also using Cloud Functions to:
    - populate my Firestore database (with some constants), and
    - to apply Firestore "schema" (or data) migrations consistently across multiple environments (development, staging, and production). That also allows me to easily have the migration documented, as the Cloud Function file is included in the project's git repository

    • @davidstackio
      @davidstackio 3 года назад +1

      How are you triggering the migration functions? I'm hoping to do the same for database "schema" updates

    • @cristianberroeta9866
      @cristianberroeta9866 3 года назад +1

      ​@@davidstackio , I'm glad that you've replied, because I'm just starting to use Cloud Functions for this Firestore migrations use case that I mentioned above, in an app that is not yet published. And in fact, I'm also wondering what would be the best triggering method. Here is the hacky technique that I'm using:
      This is how my migration Firebase Functions start:
      exports = module.exports = functions.firestore.document('thisCollectionShouldNotBeCreatedEver/{docId}')
      .onWrite(async (change, context) => {
      So it is a Cloud Function that can be triggered by a Firestore document write. However, I never write into that collection. Instead, I use the GCP console to manually trigger it. I go to the Cloud Functions section, press on my migration Cloud Function, then go to the Testing tab and press the "Test the function" button.
      Hopefully someone will recommend a better way

    • @davidstackio
      @davidstackio 3 года назад +1

      @@cristianberroeta9866 ah, so just using the console then. Simple, but effective.
      What about using a callable function that loops through all the documents that need to be changed?

    • @cristianberroeta9866
      @cristianberroeta9866 3 года назад +1

      @@davidstackio I think that a callable function could also be used. You would have to:
      - create the UI for calling the callable function
      - make sure that only authorized users are allowed to trigger the migration. Any user can call a callable function, so you would have to stop them (if they are not a person that you have given the permission to) before triggering the migration in your code. For instance, inside the callable function you could get the caller user's email, and compare it to the authorized user email. Only if they are the same, the code would continue to apply the migration

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

    So genuinely grateful

  • @user-le1fp1ww2f
    @user-le1fp1ww2f Год назад

    Great series! Thanks Todd

  • @sutikshnadubey
    @sutikshnadubey 3 года назад +2

    Keep those humor snippets coming. We developers are sad lot, we need them :)

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

    Great video! Hilarious, informative, and useful.

  • @kevinkumar3520
    @kevinkumar3520 3 года назад +2

    We need a video about caching. I as a beginner struggle a lot to figure out how you can save reads of data which is constantly queried. Thanks for the other tutorials tho, which helped a lot

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

    AWESOME! Thank you!!!

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

    He is back to form!!!

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

    just finished the whole series. love this guy.. 💌

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

    Awesome video, as usual xD

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

    That laptop skin is from Spirited Away!!
    You are awesome Todd Kerpelman

  • @EstebanCodes
    @EstebanCodes 3 года назад +3

    I've use cloud functions to setup an admin api to my dashboard app (the app that controls my real client app) that can query and write everything without worrying about security rules

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

    Would add that having multiple triggers available for a CF is very usefull to ensure Correctness. As it became very straightforward/easy to schedule/run Correctness check batches against same code used by our front-end

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

    His stickers on his laptop are fabulous

  • @Ondal1
    @Ondal1 4 года назад +6

    Still missing a good tutorial on testing cloud functions locally using the emulator. In former videos Google has suggested TypeScript as the preferred way of creating cloud functions, but all examples and semi-tutorials seem to be plain javascript. My direct problem is testing indirect changes, where a function updates another collection. For instance a user updating their name, and this has an effect on review names as in the restaurant on going domain.

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

      Yeah so many plain js examples, and the new extensions code is also plain js, doesn't make any sense

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

    Hi great videos, i've a question if i use the admin sdk inside cloud functions to create or update document, is cloud functions runs ?
    or in the same way as the rules the admin sdk ignore it

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

    You help more than compilers do

  • @rubenheymans1988
    @rubenheymans1988 4 года назад +3

    A video on multi tenancy would be nice too 😊

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

      is multi tenancy with hosting now possible? darn i just wish we can have dynamic subdomains.

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

      @@ValAllenSamonte yes it should be possible, I'm going to implement it for my app I'm working on soon. At this point I just have no idea how the auth flow will work

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

      @@ValAllenSamonte dynamic subdomains would be nice too

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

      @@rubenheymans1988 cool! was actually thinking of auth as well, but yeah re. auth, they offer custom JWT tokens anyway so it really is possible.

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

      I'm trying to set this up too. I've opted to go with creating one project per tenant. So more like "multi-single-tenant". Managing all the projects will be a pain, but I'm thinking of building out a management console (as another project) to orchestrate all of them

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

    Absolutely love firebase. Is there a way to efficiently detect if a user interacted with a document. e.g liked a post, watched a video etc. I know that there a 20k field limit in a document so storing the ids of the documents and checking them on the fly seems inefficient and created render issues when scrolling a feed for instance.

  • @Tettoffensive
    @Tettoffensive 3 года назад +1

    One issue that I've run into with using cloud functions for denormalized data is that I still end up having to make changes in my write function on the client to keep certain data in sync that is visible to the user. Otherwise, it can look like whatever the change the user made was not successful until the cloud function syncs all the data back up and the client fetches the new data. Are there any strategies for dealing with this in a clean way? I feel like I end up with a lot of spaghetti code keeping everything in sync.

  • @AkhilKumar-ys3ph
    @AkhilKumar-ys3ph 4 года назад +5

    What are the big websites that are using cloud firestore as a backend

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

    cool laptop skin from Spiritted away :D

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

    I live cloud functions but can not understand admin sdk or client sdk I used https request and call request I love it so much wish you can make a video how to use them I am new to firebase and love it

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

    I have a question regarding the scenario described at 4:55.
    Let's say that all I need from the review's author comes from the claims in the JWT issued by Firebase Auth.
    In that case, any update to the user's profile (i.e. the user's profile at the federated identity provider) would trigger firebase.auth().onAuthStateChange(), so any UI component would automatically update if it takes the review's author from firebase.auth().currentUser
    Would this be enough to avoid the whole cloud function de-normalization shebang?

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

    I'm using cloud functions to detect doc change to perform certain operations. But it seems the cloud functions miss some of the operation due to high numbers of invocations. I doubt the reliability of cloud functions... 🤔

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

    though unrelated to the above vdeo, i have a current challenge of counting a number of documents of about 300k No. in a single collection, good news is that all the suggestion i had seen suggest maintaining a counter field or using fieldValue is a separate collection that keep track of the each write (or maybe read) in the previous collection, bad news however, is that i had never implemented that. my question is there any work around to get the total of the documents(300k) using cloud functions?

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

    what is the best practice for the database structure, to have a calculated field in your database or do the calculation on the client side? e.g total sum of numbers.

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

      If it's something that you want to be accurate you can't trust the client to do it. Take for example gold in a game. If the client were to add up the gold a clever player could exploit it and give themselves endless in game gold.

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

    Hello everyone, I need to sort data stored in a collection by the frequency of the occurrence of the words from that data and then send it to my front-end in a form of an array of, let's say 20, most commonly used words. How can I force firebase to do that for me ;) ? Thank you in advance for any tip.

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

    Hello Everyone! how Can I format text that is stored on a firestore collection... I am rendering some posts which contains properties such as Title, description, content, etc via mapping them on my component but when I render content for example it just display the whole text with the same format... I would like to be able to insert some styling to some sections of that text... I'd appreciate your help.

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

    Hey! Great video. I saw a reply by someone mentioning hiding api keys by leveraging cloud functions. Which solves for that problem when communicating externally. 👍
    I do am very interested in your advice with pubsub. Would you rather have chains of functions communicate through the pubsub api by chaining them via push, a pubsub listener function or not at all and have the functions communicate directly with each other?
    I am also starting to wonder about the need for subcollections at all 🤔 based on your series I'm getting more and more into just redoing my whole setup to work with only a bunch of main collections, filtering it down with proper queries, security rules and have some functions to act on changes there. Instead of clients as master collection with the same sub sub sub collection structure.
    Last one, would you recommend building an external facing api with auth and all with/on firebase or rather leverage cloud run? I'd love to see a short series on this if you'd use firebase for it.

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

    I keep getting a DEADLINE_EXCEEDED error from my firebase function. What does this mean?

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

    Hello, so I've got a question.
    I have no experience with Databases and I want to run a sensor with a SIM module to communicate with the Realtime Database. With Cloud Functions I want to update the Firestore Database, for every entry on the Realtime Database. I have also an App that will read the information from the Firestore Database.
    As a starting point, I will only have one client sending data to the Realtime Database, but hopefully this will increase when we sell more of these systems. Will increasing the number of clients present any issue with Cloud Functions? Or will it be able to handle this without an issue.
    Also, if you guys have any pointers on where to start, I would really appreciate it. I'm fairly new with Firebase and DBs. so I'm watching all the videos and reading documentation to get a feel for it. Like I know I'll probably have to learn TS as well.

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

      I guess that would be okay, given that Cloud Functions, at least from what I understand, are made to be called very frequently and scale effortlessly with your userbase (and hence, database).
      As for getting started, start from whatever language/platform you'll be using on these devices (make sure it's one with a client-side API), and start with the official docs, to make some simple programs in your computer that contact the database and experiment with reads, writes, and more (in both Realtime and Firestore Databases). You can then try experimenting with Cloud Functions to apply some conversions, sync data between Realtime and Firestore Database, and make sure they work as intended, and don't go above your expectations when it comes to pricing.
      After this warm up, you can get started with building the actual code that'll live on these systems, testing it from your computer with dummy data, then wiring things up and putting it in the devices themselves. Assuming these are meant to be always connected, it would be great if they could self-update to accommodate any changes you might need to make later on.
      On the mobile end, you could do the same process as above. Test the APIs and listeners available in the client libraries, build your security rules, and then write and extensively test the actual production code for any security issues.
      This is a VERY broad "pointer" here, but I hope it can clear things up a bit! (although it's been 7 months now..)
      This is a really interesting use case, wish you luck!

  • @FrankMartinez-uo5yh
    @FrankMartinez-uo5yh Год назад

    6:35 🎉

  • @eric-ampire
    @eric-ampire 4 года назад

    Cloud Function it's very interesting 🎉🙏

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

    oof, half abandoned dreams hit hard :D

  • @Balamurugan-rr3is
    @Balamurugan-rr3is 4 года назад

    Sir, I have a one doubt please clear to me...
    We have create a Android Application backend database is firebase...how to buy a fribase hosting or any other hosting are using in firebase???
    Please help me sir we are upload a Android project to playstore but we dont have host and we dont know how to buy host...

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

    Need more practical sessions firebase team

  • @Squad2ND
    @Squad2ND 5 месяцев назад

    Is there a reason to "hide" all implementation details behind a Cloud Function? E.g. read from Firestore. But if I do this, I say Good Bye to any offline capabilities?

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

    I have created app with newsfeed and chat.I want to create user following and unfollow.how can i do this with firestore?

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

    that got dark 😂😂😂

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

    Some code for denormalizing data in functions would be most appreciated.

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

    2:28 I don't understand. I have to make a new database entry every time a player makes a move? Wouldn't I soon have a million documents with arbitrary player move data that will never be used again?

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

    How to get collection id for web ?

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

      I use createId to create a uid on the client, add a property uid to the object. Update the doc in the collection with that uid. Now everytime I fetch the collection, all my docs have the uid as a property

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

      @@rubenheymans1988 thank you. I'll try it.

    • @1teamrealtors
      @1teamrealtors 3 года назад

      @@rubenheymans1988 Bad idea.

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

    1 thing firebase sucks at: auto complete text search
    it really doesn't make sense to go for algolia a third party service becoz its such a basic feature we all expect to get it natively In firebase

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

    I really wish there was a feature resembling Firestore Security Rules, but filtering the data instead. Having three user groups with different privileges wishing to access the same document (with all the benefits of a real-time listener), currently there is no way to pass only the chosen fields of the document instead of the whole one. There are so many use cases I have for this feature and cloud functions aren't really a solution here - no real-time support + cold start latency negatively impacting the user experience. Security Rules with direct database querying filters would be an amazing and powerful combination.

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

    37 hours more -_+

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

    i have error in firebase cli login error in CMD

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

    Hello