Introduction to Firebase
-
Upload
mustafa-senel -
Category
Software
-
view
526 -
download
65
Transcript of Introduction to Firebase
INTRODUCTION TO FIREBASE
Mustafa Ş[email protected] Developer @ SONY GSI
2
AGENDA What is Firebase ? Use Case Realtime Database Data Modeling Security Rules Pricing Conclusion
3
WHAT IS FIREBASE?
«Firebase is a mobile and web application platform with tools and infrastructure designed to help developers build high-quality
apps»*
*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
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
6
WHAT IS FIREBASE?
*https://firebase.google.com/
7
USE CASE – MOBILE APPUsually our architecture
DatabaseServer / REST APIDevices
*Icons made by Madebyoliver from www.flaticon.com
8
USE CASE – MOBILE APP
*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
10
FIREBASE REST
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
11
FIREBASE SDK
12
SDK - READ DATA (ON – METHOD)
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
13
SDK - READ EXAMPLES
14
SDK - READ DATA (OTHER METHODS)
’’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)
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)
’’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
17
SDK - WRITE EXAMPLES
18
SDK - WORKING OFFLINE
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
20
DATA MODELING - NESTED NODES
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
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
* 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
24
SECURITY RULES - EXAMPLE
25
PRICING
*https://firebase.google.com/pricing/ December, 2016
26
SOME FIREBASE CUSTOMERS
* https://firebase.google.com/customers
27
ALTERNATIVES
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
29
LINKS
https://gist.github.com/msenel/8b01bfca1490a490e2cc06a3bcb865ee#file-senel-bbs-firebase-read-js
https://gist.github.com/msenel/5e4179b2e78c20968b7102b2bc95f645#file-senel-bbs-firebase-write-js
https://firebase.google.com/docs/ https://firebase.google.com/docs/database/web/structure-data https://www.youtube.com/user/Firebase
THANK YOU!