DevEX - reference for building teams, processes, and platforms
Tips & tricks for Firebase storage and Firebase functions
1. Tips & tricks for Firebase
Storage & Functions
David Vávra, Android GDE
2.
3.
4. Firebase Storage
● For saving large binary files (images, video, audio etc.)
● Not for structured data (use Realtime DB or Firestore for that)
● Built on top of Google Cloud Storage
● Serverless: clients access it directly, servers are another clients
● Indefinite scalability
● SDKs for Android, iOS, Web + REST
● Security rules similar to Database rules
○ can contain validation rules (“must be PNG & <5 MB”)
5. Firebase Storage pricing
● $0.026/GB stored (vs $5/GB for RTDB)
● $0.12/GB downloaded (vs $1/GB for RTDB)
Free tier:
● 5 GB stored
● 1GB downloaded / day
Settle Up April 2018:
● free
6. How we use it at Settle Up
● Pictures of users
● Receipts for expenses
● Images for campaigns
● Archive of old groups from Database
7. Tips
● Save Storage URLs to Database
● Make sure it works offline
○ save local path first to Database
○ schedule task for uploading later (WorkManager on Android)
○ change URL in Database
● You can use Storage for archiving data from Realtime DB
● .NET?
○ https://github.com/step-up-labs/firebase-storage-dotnet
8. Cloud Functions
● Javascript/Typescript code triggered by events
● No server management, infinite scalability
● So simple that frontend developers can write it :)
● Useful when:
○ you can’t trust the client
○ reusing logic for clients
○ saving resources for clients
○ data consistency
10. Functions pricing
● $0.40/million invocations
● $0.0025/thousand GB-seconds, $0.01/thousand CPU-seconds
● $0.12/GB of outbound networking
Free tier:
● 125K invocations/month, networking Google only
Settle Up April 2018:
● 543K CPU seconds, 2.3M invocations = $3.5
11. How we use it at Settle Up
● verifying purchases & subscriptions
● moving some HTTP logic to server side
○ adding permissions
○ archiving/restoring groups
○ delete all expenses
○ shortening Dynamic Links
● periodically update exchange rates
● generating history of changes
● cleanup (removing invalid URLs)
● Google Assistant fulfilment
12. Tips
● Use Typescript and VS Code as editor
● We tried Kotlin and it’s possible, but cumbersome
● Cron functionality is missing, we use Google AppEngine which does HTTP
trigger
● Test functions locally, libraries mocha, sinon and chai are useful
● Deploy functions via CI