2. AGENDA
What is Firebase ?
Use Case
Realtime Database
Data Modeling
Security Rules
Pricing
Conclusion
2
3. WHAT IS FIREBASE?
«Firebase is a mobile and web application platform with tools and
infrastructure designed to help developers build high-quality
apps»*
3
*https://en.wikipedia.org/wiki/Firebase
4. WHAT IS FIREBASE?
A set of tools which provides a full suite for app development
Ability to create applications with no server-side programming
Backend as a Service
4
5. HISTORY
Founded in 2011 by Andrew Lee and James Tamplin
Initial product was a realtime database
Over time it becomes a full suite for app development
Acquired by Google in 2014
5
7. USE CASE – MOBILE APP
Usually our architecture
7
DatabaseServer / REST APIDevices
*Icons made by Madebyoliver from www.flaticon.com
8. USE CASE – MOBILE APP
8
*Icons made by Madebyoliver from www.flaticon.com
Access via REST or SDK
9. FIREBASE REALTIME DATABASE
Initial product and the heart of the Firebase platform
After a database update, new data is synchronized across all
clients within milliseconds
NoSQL Json Database
9
10. FIREBASE REST
10
Firebase can be used as REST endpoint (append .json to the
URL)
Usage of HTTP methods (GET, POST, PUT, PATCH, DELETE) as
usual
Provides a set of Query parameters
12. SDK - READ DATA (ON – METHOD)
12
Event based query system
Provides different event types
Listens for data changes at a particular location
Callback triggered for the initial data and whenever the data
changes
14. SDK - READ DATA (OTHER METHODS)
14
’’once’’ Method
Access like ’’on’’ method – but just one callback and not keep giving
updates
’’off’’ Method
Detaches a callback previously attached with ’’on’’ method
15. SDK – WRITE DATA (PUSH METHOD)
15
Most common pattern for adding data
Generates a new child location and returns its Reference
Uses a unique key based on current time
Because of the unique key, data is chronologically inserted
16. SDK - WRITE DATA (OTHER METHODS)
16
’’set’’ Method
Overwrites any data at given location and all child locations
’’update’’ Method
Used to selectively update only the referenced properties at the given
location
18. SDK - WORKING OFFLINE
18
Offline read and write data possible
There are two offline modes
Short term
Local in-memory cache
Long term
Disk persistence Works on Android and IOS
19. USE CASE
We are going to build a mobile application
We have entities like User, Channel, Follower, ...
One user can have many channels
Each channel only belongs to one user
One channel can have many followers
Each follower can follow many channels
19
20. DATA MODELING - NESTED NODES
20
Might be exactly what we need
When we need channels always with full
follower information
But
Firebase is always loading all json
There is no way to exclude properties
21. DATA MODELING - THE ELEGANT WAY
21
Add indexes to resolve two-way
relationships
Association properties of the
relationship could be saved as the
value of this node
22. DATA MODELING
Keep in mind – It’s a JSON tree
Avoid nesting data
Flatten data structures
Create data that scales
22
* https://firebase.google.com/docs/database/web/structure-data
23. SECURITY RULES
Default rules are too open
Access to everything even if signing in anonymously
Mindfully data modeling is essential for real life rules
Important rule types
.read
.write
.validate
.indexOn
23
28. IN CONCLUSION
Get fast in action
Easy to use
But sometimes we just need server-side code
It is hosted
Data needs to be well structured
28