Learn how to manage costs in Firebase with both clientside and serverside optimizations. angularfirebase.com/lessons/m... Source Article hackernoon.com/how-we-spent-3... Firebase Pricing firebase.google.com/pricing/
Пікірлер: 241
@MrJaminbrad5 жыл бұрын
Your content is great as always. Mini case-studies like this are a fantastic way to implement several little features of angular, rxjs, & firestore into the bigger picture of a more thoughtful app architecture. For angular newbies like me, this is gold. You've outdone yourself on this one.
@Fireship5 жыл бұрын
Thank you! This is actually the first "case study" style video I've done. Appreciate the feedback :)
@rick_from_yr Жыл бұрын
Right now it has already been implemented. Now you can set a maximum amount, and an amount to send you an alert
@Fireship5 жыл бұрын
Have you experienced sticker shock in the cloud? If so, would love to hear about your story with comment :)
@steffennilsen21325 жыл бұрын
I watched a presentation kzbin.info/www/bejne/h2PKapdobrp8sM0 where the presenter had decided to 'solve' pokemon blue, with a regex statement... yeah. He ran it on aws and was billed ~9500 USD
@bstrnx5 жыл бұрын
This video is pure gold! Thank you for making it. I think it would also be useful to learn what other operations you can use as triggers for cloud functions (other than DB writes/reads) and with which other Firebase technologies you can integrate those cloud functions (like FCM).
@danilofuchs12345 жыл бұрын
Instead of using "get" and "set" inside your cloud function, you should use transactions, to allow multiple users to upload at the same time
@cristianscript56493 жыл бұрын
wow
@Rhidayah10 ай бұрын
The question is why Firebase not have features to stop project while get maximum bills
@AgentMassiveWizard8 ай бұрын
@@Rhidayahdo you want to completely stop your app just because you can't pay a single more dollar
@TheCollectiveYoutube2 ай бұрын
It would be nice too be able to set a limit. Id day free jumping to $5k is good reason to shut it down @AgentMassiveWizard
@carltongordon5 жыл бұрын
This is amazing man! thank you for the heads up
@narcodico5 жыл бұрын
I'm pretty sure Firebase team should have tools in place to detect this kind of behavior and notify the user. Would be fair to say the least.
@Fireship5 жыл бұрын
I agree. It's possible to create an infinite loop with cloud functions and have no idea. The good news is that Google is usually forgiving on pricing in these situations.
@roytouw1525 жыл бұрын
In this case as well?
@videoguy6405 жыл бұрын
You can stop all requests to db after a certain monetary amount iirc
@zdream7205 жыл бұрын
Why is it their job to design your code? I disagree. Understand what you're doing if it could cost money. Simple as that.
@narcodico5 жыл бұрын
Considering they are offering a paid platform for people to use, their focus should be on helping out their customers and making their development life easier. After all, customers are bringing in the money. I'm pretty sure firebase has a lot of users/customers who don't fully understand how this product really works. I'm sure you weren't an expert in firebase just out of the box, it takes time to develop the skills. Also, anyone could make a mistake, no matter how good you are. I'm sure paying a large bill for a mistake is not something people would find helpful in becoming better developers or encouraging to stick with a certain product. Understanding what you are doing is one thing, making a mistake is completely different story.
@AnimeProfilePictureShitposter Жыл бұрын
Someone send this to Jason Goldstriker QUICK!!1
@esstetico Жыл бұрын
Fishtank should've watch it before!!
@rushnerd Жыл бұрын
How have we come to this lol. Josie must be saved...
@toolavish Жыл бұрын
Reminds me of days when cellphone mobile minute plans got people paying 1k mobile bills
@user-vy8ej1cg8x Жыл бұрын
Josie...
@thelastshartbender758 Жыл бұрын
Sam Hydesisters what is this.......
@SteveDaBartender Жыл бұрын
i miss them
@SquishySquid88 Жыл бұрын
you have to help out our man jason goldshriker
@aerivera5 жыл бұрын
From a point of view of someone that has the "intention" to learn Angular, this video is pure gold!. Practical analysis and resolution to a REAL issue. I always say to myself that I will buy your Angular course, but I've been so lazy lately and putting excuses like "My JavaScript still not good enough"... time to do some real decision and commiment hehehehe.
@Fireship5 жыл бұрын
Thanks Angel! I really try to keep things as practical as possible because it's the best way to learn IMO.
@DylanHart8 Жыл бұрын
@wigger
@mrsneed420 Жыл бұрын
the show must go on #fishtanklive
@ilhamefendy98685 жыл бұрын
thank's for your great video, as a very newbie in learning firestore, it's a scary fact if I face the same problem. thanks for the solution you shared before I make the same mistake
@diznyland6214 Жыл бұрын
It's just not the same without them.
@kiontupper5 жыл бұрын
This is actually why I went full REST (I chose *not* to use any SDKs for Firestore/cloud storage). I scanned the entire documentation and realized that by using the SDK, I'd have no idea what it would cache or refresh or how it would handle offline persistence (vital for mobile). Therefore my app doesn't even load the SDK, and all authentication, cloud functions, firestore requests, etc are handled directly through REST and cached on my own.
@beneditomauroo5 жыл бұрын
Kion Tupper could you expand a little?
@worldwide66264 ай бұрын
@@beneditomauroo he isn’t going to I think
@ribbonmushaАй бұрын
@@beneditomauroo yeah, he wouldn't
@Rassy_4 жыл бұрын
Recently firebase removed the Flame Plan, paying 25$ per month, now developers only have 2 options: free version or pay as you go which sounds very intimidating.
@BrandonBaunach3 жыл бұрын
Why is pay as you go intimidating?
@Rassy_3 жыл бұрын
@@BrandonBaunach because you might end up getting a 30k bill if you're not careful or experienced enough with it
@BrandonBaunach3 жыл бұрын
@@Rassy_ but wasn’t this video made during a time when it wasn’t pay as you go? And they still got a 30k bill?
@Rassy_3 жыл бұрын
@@BrandonBaunach no pay as you go was always there from the start and that's what they chose, if they used any other billing plan, it's only their services that would be limited but they wouldn't incur such a bill
@RickyNoelDiancin5 жыл бұрын
Thank you, this is very helpful!
@Fireship5 жыл бұрын
Glad to hear that. Optimizing for the cloud's cost structure can be very important.
@TheDerpyWhaleYT4 жыл бұрын
is there a cap on how much you can pay? not just a threshold alerting you X amount?
@harpymaslow5 жыл бұрын
Great. As usual
@andenetalexander52443 жыл бұрын
You always make a great contents in such short amount of time. You're the best! Can you pleas make same video for this use case using flutter b/c i don't really know much about angular to get most out of it. Thanks in advance.
@TheDerpyWhaleYT5 жыл бұрын
For the free plan, it just shuts down your app right? no bills?
@punyaslokdutta43624 жыл бұрын
1. Make another document where every time a document added,It updates both the documents . You make two writes.
@rlaracue4 жыл бұрын
Great video. I could use your help on this topic because my firm is building a social chat app with Flutter front end. We are debating on using Firebase or go with a traditional database model (MariaDB) on a bare metal server. Is there way to manage costs effectively with FIrebase for a user base of 500K users with 10-15K DAUs to start? This app could grow to 5 mm users with 1 mm DAUs. We would be using SMS authentication as part of the design. Thanks!
@alishibli47205 жыл бұрын
Can you please share details about this startup or the articles you read?
@sleeplessdev72045 жыл бұрын
Awesome tip, thanks!
@pdela725 жыл бұрын
Amazing content as always. Just made myself an aggregation in firestore for my project, and, I'm sure you know better than me, but be sure to use transaction instead of get/set pattern not to have mistakes in calculation if multiple donations happen concurrently.
@wacalu5 жыл бұрын
I would do a transaction in that case to avoid race conditions
@mahathirmohammad86353 жыл бұрын
I always try to write cost-efficient code. Sometimes it takes more time in comparison to writing expensive code.
@couchman-sw6jy6 ай бұрын
But it saves your ass in the long run. I’m doing the same right now
@electrolyteorbАй бұрын
Miss these types of videos
@dr.z79585 жыл бұрын
Are you considering some contents about Flutter? it seems the current trend since it also very compatible with Firebase?
@OM-bs7of3 жыл бұрын
Flutter is for babies, jk
@PacifiqueStormz4 жыл бұрын
those animations tho ,AMAZING!!!
@marvinbuth93103 жыл бұрын
I know this video is kind of old but what about implementing serverside rendering with for example NodeJS and just updating the value only once maybe every 10 seconds and then caching it. Maybe I'm missing something but shouldn't that also reduce the amount of calls to the database significantly? Because the server only needs to do one call to the database every 10 seconds and render the front end view with this information for the user.
@Nek2083 жыл бұрын
Hey @fireship do you have any video for „like a post/tweet“ with cloud functions?
@shripadashtekar74 жыл бұрын
Hi Could you please help me with the firestore storage billing for images? I am new to it and I want to know how it is charged. If I upload a 10 MB image and 10 users are downloading it, Will I be charged for 10MB upload and 10*10 MBs of download (which is GB Transferred)? Or will I be charged, just for upload and download operations?
@raulchavan0074 жыл бұрын
This was really helpful. I had one question though. If I have a startup that is similar to Uber type of business? And I run my backend on firebase? How much do you think will be my yearly cost for running the app on firebase?
@taniasiregar6534 жыл бұрын
rahul chavan Build your own server or rent dedicated server for a year. Its safe for this type of business because we don’t know if our app will growing fast or slowly.
@brianevans43 жыл бұрын
Amazing how much has changed in just two years
@dankoller2462 жыл бұрын
@Vivek Sharma The intro lol
@Dance3run2 жыл бұрын
What do you mean? Is this video still relevant?
@Theyssen5 жыл бұрын
Very interesting and great as always! Could you expand on this topic with transactions?
@Fireship5 жыл бұрын
Transactions and batches would make a good mini-video for the future.
@Theyssen5 жыл бұрын
Sounds good. I will be watching.
@DeroInvisible2 жыл бұрын
I am wondering how to implement a "aggregation" (like in 5:50) in production. If I do it like in the video I have to set the security rules to allow all users to update the "donations" document. Then someone can use firestore rest api and update it to a random values and potentially breaking my app. Is there a way to still track it like in the video and set good security rules?
@TheRanguna3 жыл бұрын
You are decoupling the code that adds a donation with the code that updates the aggregation. This is bad because your database will be in an inconsistent state until the cloud function runs. Probably, the best way to go about this would be to run the donation function in a transaction that both inserts a new donation and updates the aggregation document. This way, your database will always be in a consistent state.
@MercyFromOverwatch22 жыл бұрын
Jeff is my favourite tech youtuber!
@andremariano33474 жыл бұрын
You have to create a flutter version of this!!!!
@kim157423 жыл бұрын
Here is something I don't get: with traditional relational databases the consensus was to never ever access the DB from the frontend. But it seems like this is exactly what we are doing here. Isn't this a major security hole that allows users to write arbitrary data to the DB?
@DeroInvisible2 жыл бұрын
I am asking myself the same thing, because the only thing i found for preventing access to all users is setting the firestore security rules. But if I do it the way like in the video at 5:30, I just have to allow all users to modify that "donations" document but doing so, someone can use Cloud firestore REST API and update it to some random values.. which would break the app
@Kareszrk2 жыл бұрын
Isn't there any auto block for new requests to FireBase when my app reaches what's included in the free plan?
4 жыл бұрын
can you make a flutter version of this video mr fireship sir? :D I have multiple users that can add items to their own list (items from that list are identified by userID, not an actualList. i read all and filter the ones for that user with .where(). is there a better away?)
@jayanayana4 жыл бұрын
I got a doubt If they would have used the Realtime database instead of firestore will that fix issues. As it's just based on storage
@RyanHaydenMattoon5 жыл бұрын
Maybe an odd question, but I’ve built a firestore based template website solution that I haven’t launched yet. These videos have me pretty scared that I’m going to be hit with a huge unexpected bill once these things start scaling. I was considering making a static site generator that runs on a firestore function and pushes to a CDN whenever there is a write. That way each site can have a bunch of reads that happen only once and the sites can scale like crazy without extra reads. Is this a bad idea? Any other solutions you can think of?
@Fireship5 жыл бұрын
That is actually a cool idea and I've seen it done before called "event-driven prerendering". But keep in mind, it takes hundreds of millions of reads before you start seeing a significant firebase bill. It's often a mistake to focus too much on optimization in the early stages. Most apps aren't viral like this, so there is time to optimize as you grow.
@jopadjr5 жыл бұрын
Great Video mate....Amazing...
@md.mehrabhaque22234 жыл бұрын
There's more efficient and easy solution, there's no need of firebase-functions, you can achieve this on client side, on firestore, at first create a doc having the total donated amount and number of donors, on client side, set a listener to that doc and also while writing new donation entry, just increment that doc using FieldValue.increment. As a result, it avoids extra reads by firebase function and also the changes in total and avg donation become almost simultaneous. And for the last 5 entries just use realtime db.
@mathijswy5 жыл бұрын
Is your course heavily focussed on firebase or more Angular focussed?
@Fireship5 жыл бұрын
The pro membership has a variety of topics, some 100% firebase, some 100% angular, and others a mix of both. Later this week I am releasing a new course focused on cloud functions that is framework agnostic.
@3nscherzl3 жыл бұрын
isn't possible to store a posgresql database with apache server on a common host server and synchronize it with flutter ?
@tonestrada20005 жыл бұрын
hi is it good to store images on firebase? any cheap alternative for it?
@libertyIsAll1325 жыл бұрын
why was this ? the client was downloading on every update all the collection to calculate the average , instead of adding new value to average ?
@ameerattaa22505 жыл бұрын
can i download a collection and filter it in the client side according to the user request ?
@Fireship5 жыл бұрын
Yes, you'll be billed for the full collection query, but that is definitely possible
@FarryEntertainment4 жыл бұрын
So how does a chatting work through Firebase?
@briantep4585 жыл бұрын
is there something else i should use besides firebaes?
@KochharAmandeep5 жыл бұрын
I like your channel but I want to know why you named it Angular Firebase? Doesn't React work with Firebase too?
@Fireship5 жыл бұрын
I did not expect this channel to be more than a few videos. I might rename it in the next few months.
@KochharAmandeep5 жыл бұрын
Angular Firebase keep uploading content mate. You are really helpful
@jehanmuse3305 жыл бұрын
Hi sir , may i know why you use firebase cloud function to update database ? just wondering what is the advantage .
@IshanKBG3 жыл бұрын
Cloud functions lets you run backend code for the website
@toolavish Жыл бұрын
Sam hyde should have watched this @perfectguylife
@usamajamil7385 жыл бұрын
Recommend a channel for react firebase.
@itssidhere4 жыл бұрын
Dear sir , Please help me I cant disable persistance in cloud firestore for flutter
@xylvnking Жыл бұрын
Anybody know if there's a way to set a spending limit by now? New dev here, spooked tf out about a big bill. I don't understand how I can protect myself?
@KamelJabber15 жыл бұрын
awesome, thanks!
@jatinrewri31633 жыл бұрын
Plz a tutorial on arrays and map for flutter to save money on this topic!!!
@alytechnology Жыл бұрын
There is a big mistake here the max size for a doc is 1 mb so u cant put millions in that array but maybe a thousand or something like that
@vinayc4 жыл бұрын
Can you make a video on how to do in vuefire?
@tejedaAlex5 жыл бұрын
are the firebase aggregations charged per read and write? I mean, if X times the aggregation is triggered because there was X operations trigger it, would be an extra charge?
@Fireship5 жыл бұрын
You have 1 extra read and 1 extra write and 1 cloud function call per data change. If the data is read heavy, this is usually a very good tradeoff.
@keep5 жыл бұрын
@@Fireship when you choose a Firebase plan, once the cap is reached isn't the dB supposed to stop working? Or in this case it continued to work and charged extra for the usage after the cap.
@Unc33 жыл бұрын
Took me 2 hours to build a similar app and 4 days to troubleshoot firebase.
@carrillocarlosce5 жыл бұрын
I had a similar problem by writing the user locations coordenates to firestore, thank that i was in spark plan this didn't affect, do you know how can I update a user location for realtime track
@Fireship5 жыл бұрын
Generally, this is something you debounce in the client. So you might have a GPS update every 500ms, but you only actually write to the DB every 10 seconds. There are other strategies as well depending on how your UI needs to present the data.
@mateja1765 жыл бұрын
Exactly! Perhaps write to the DB only if the distance increases by more than 10 Km compared to the last Geo-point stored.
@carrillocarlosce5 жыл бұрын
Mmm right, this is something that i definetly gonna take care, thanks.
@Reddrik Жыл бұрын
A cautionary tale.
@levihalperin76492 жыл бұрын
Would it be possible for someone to make some bots that create users to request and send requests and thus run up your bill?
@J70istooshort6 ай бұрын
yup, and its still not fixed!
@Ragnarok5404 жыл бұрын
Technical debt, right?
@mahmoudnassif93393 жыл бұрын
I got 277k $ bill what should I do?
@VALOFLICKS3 жыл бұрын
This is not gonna work, if you have 5-10 concurrent request your data will be messed up. And if you wrap it inside transaction you will likely get "contention" error because of concurrent read/write request on a single document.
@wahabrehman68483 жыл бұрын
Does anyone else get random reads from the firestore?
@FrankLloydTeh5 жыл бұрын
Will this not run into race conditions? Where aggData.total is not updated and two create events fire so one overrides the other?
@Fireship5 жыл бұрын
That is an important consideration. A less efficient approach, but safer, is to read the entire collection on every update in the function. This will reconcile the true total value on every update, but requires more reads. If a race condition occurred on the last transaction, it will be fixed on the next one or could be verified with a regular cron job. Also puf has some thoughts about that as well stackoverflow.com/questions/49290380/how-do-you-avoid-a-possible-race-condition-with-firebase-cloud-functions
@cbro_5 жыл бұрын
yes, it will. try using Firestore with transactions.
@MatthiasWiemann13 жыл бұрын
Solution is wrong because it creates a incorrect sum if trigger onCreate is executed multiple times. See firebase.google.com/docs/functions/firestore-events?hl=en “Events are delivered at least once, but a single event may result in multiple function invocations. Avoid depending on exactly-once mechanics, and write idempotent functions.”
@piotrbukowski57035 жыл бұрын
Angular Fire's observables are hot so many subscriptions to the same collection shouldn't cause more than 1 read operation of entire collection. Am I wrong?
@Fireship5 жыл бұрын
Yes, but it depends on how you create them. Because I was creating a new reference for each obs, it would be a unique read. A benefit of shareReplay is that it allows late subscribers to get the last value, otherwise they would get nothing or have to initiate a new read.
@piotrbukowski57035 жыл бұрын
Recently I made some tests about this case. It turned out that if you subscribe collection with the same path (even creating new reference to it) many times and while at least one subscription is active you don't make additional requests.
@narcodico5 жыл бұрын
True, shareReplay is basically a behaviorSubject which doesn't take an initial value since it will start emitting last value to it's late subscribers only after the first call to next has been made. This will ensure latest value consumption in different components without extra reads, as long as there is at least one active subscriber...when last subscriber unsubscribes it will tear down the whole chain. After this point, a new subscribe will result in reading from firestore again...am I getting this right ?
@piotrbukowski57035 жыл бұрын
Rolly Peres Yes, but I related to case without using shareReplay, just plain valueChanges observable.
@narcodico5 жыл бұрын
That's not gonna cache the values, but read them every time you subscribe to it.
@GwidazMan5 жыл бұрын
Use firebase database which is not charging you by read/write but by the space used..
@Radial9Gaming4 жыл бұрын
Also charging you bandwidth. Both of these are more expensive than the charges made from Firestore.
@KyoKurosagi5 жыл бұрын
isn't there is a limit of document size? we can't just store all thing into a document. it will blow once over the document size limit.
@Fireship5 жыл бұрын
Yes, 1MB. That's why I only aggregate the last 5 records so it will always stay super small.
@SolidousMdz3 жыл бұрын
Hey do you have an example of some auto backup solution for firestore?
@silentkiller40912 жыл бұрын
So google with all its power of AI can't detect this unusually high requests and alert the user?
@PutraSurya-785 жыл бұрын
don't do this if you have large of data, document in firestore maximum size is only 1MB
@JohnDoe-zc4mu5 жыл бұрын
I don't see any drawback here... the aggregated document has 3 fields: the total of money, the number of donations and the last 5 donations. As you can see, you'll still have 3 fields with max 5 donations object no matter on how your application scales, so you'll have a full control on that and never break the 1MB size limit.
@MuhammadAmir-mf9xt4 жыл бұрын
This is amazing ❤👍👍👍
@joeldaros5 жыл бұрын
That’s a great topic. It’s like some when you start learning and make a cloud function update yourself and the function enter in infinite loop. That’s funny.
@Fireship5 жыл бұрын
I almost included that infinite loops in this video, that's another common source of surprise costs.
@Max-cr3dz5 жыл бұрын
Somebody needs to create plugin/package that will console log number of all read/writes requests to firestore... (in dev mode)
@JustinLawrence734 жыл бұрын
Agreed!
@tsortanidischristos4125 жыл бұрын
Is firebase charging even the reads from persisted data that's coming from the local cache?
@Fireship5 жыл бұрын
No, this video is actually a bit over-optimized. Firebase does not charge for the cached results on a listener firebase.google.com/docs/firestore/pricing
@tsortanidischristos4125 жыл бұрын
@@Fireship you said 'does'?
@Fireship5 жыл бұрын
@@tsortanidischristos412 Oops, that was a mistake. I meant 'does not'
@tsortanidischristos4125 жыл бұрын
Oh haha still thanks :)
@yourasa12133 жыл бұрын
Can you do this example in Flutter? I will buy you a coffee. Three coffees, at least.
@justinkim72025 жыл бұрын
Is this method thread safe? Is there any possibility that another callback would be executed before the aggRef.set(...) is called or is the node's single threaded model maintained?
@poimsm5 жыл бұрын
What is a tab operator?
@eus95 жыл бұрын
poimsm It's the *tap* (with a 'p') operator from rxjs, it allows you to carry out side effects while having access to the observable data without modifying it. Example shown in the video is perfect: you want to log out what was piped through, but not change it.
@testg4andmmm1294 жыл бұрын
Yea thats the problem of reactive subscribe thing. Its hard to understand. Easy way is to not use reactive . Do normal way...
@LoganDark43575 жыл бұрын
Atom is the slowest text editor I've ever used, much slower as a code editor too.
@blizzard1825 жыл бұрын
LoganDark visual code ftw. And it is based in atom which is amazing
@LoganDark43575 жыл бұрын
LOL VS sucks
@Erraticfox5 жыл бұрын
@@LoganDark4357 VSCode is easily the fastest feature full IDE, kid.
@LoganDark43575 жыл бұрын
VSCode isn't an IDE. It's a text editor, like Atom or Sublime. The plugins make it what it is.
@Erraticfox5 жыл бұрын
It's not a text editor, it's a source code editor, if you wanna split hairs.
@osquigene4 ай бұрын
That all look very complex for such a simple thing, why not just have a cache in your backend endpoint? You don't even need to optimize and can have 3 separate endpoints (sum/average/list). If you have non-stop users for the whole day and set an expiration of 1s, you would only get 86 400 requests a day for these 3 pieces of data. The good part is its independant from the number of users and people would just hit the cache (your RAM most likely in a case like this). I mean, that data is independant from the user's watching it so it shouldn't require anything too fancy. I had no idea Firebase could be used as a real database, I though this was only made for (mobile) app settings (tokens/urls/passwords/etc.). What is the idea behind using Firebase as a database instead of a classical managed PostgreSQL database (like the one your favorite cloud provider offers)?
@YousefSh5 жыл бұрын
Can you share the heckernoon article?
@YousefSh5 жыл бұрын
Nevermind I found it: hackernoon.com/how-we-spent-30k-usd-in-firebase-in-less-than-72-hours-307490bd24d
@Fireship5 жыл бұрын
Yes, it's in the description
@Fireship5 жыл бұрын
I pasted the wrong link in the description, thanks for catching that
@YousefSh5 жыл бұрын
Haha. Ok I was super confused. Thanks!
@dumptruckwagon3 жыл бұрын
Fml, I was making a prototype and I had 400 requests with 4gb of bandwidth in 1 minute...