SlideShare a Scribd company logo
1 of 41
Firebase
Aneeq Anwar
Software Engineer (iOS)
What is Firebase?
 Firebase is a scalable, real-time back for
your application.
It allows developers to build rich,
collaborative applications without the hassle
of managing servers or writing server-side
code
Firebase is Platform
Independent!
 Firebase has support for the web, iOS, OS X,
and Android clients.
 In addition, it has a Node.js and a Java library
designed for server-side use.
 The Firebase web client supports all mainstream
browsers (IE 7+, Firefox 3+, Chrome, Safari,
Opera, and major mobile web browsers), and it
works on any network connection.
How does it work?
 Developers install firebase by including a
library in their applications.
 This library provides a data structure that is
automatically synchronised between all of
your clients and with our servers.
 If one client changes a piece of data,
every other client observing the same
piece of data will be updated as well
within milliseconds.
Is Firebase just for “real-time” apps?
 Not at all!
 Firebase is for anybody that wants to write apps
without having to run backend servers or write
server code.
 Many developers prefer focusing on frontend
HTML and JavaScript rather than building,
deploying, and maintaining server-side backend
code.
 Even if real-time isn’t critical to your application,
Firebase can help you build your application
faster and scale seamlessly.
Firebase features
 Custom server code
Firebase fully support access from your backend
servers.
When used in this configuration, you still get all of
the benefits of using Firebase as your data store
(way less code, easier scaling, real-time updates,
etc.), while gaining the flexibility to run whatever
custom backend logic you need.
Firebase features
 Custom server code (Contd.)
It has a Node.JS client, a Java Client and a REST
API specifically for this purpose.
This allows you to do your own data processing,
custom validation, etc. on your own servers while
still relying on Firebase for data storage and real-
time propagation of updates.
Firebase features
 First class security
Firebase is intended for business-critical
applications, and it take the safety of your
data very seriously.
All of your data is stored redundantly and
off-site backups are made nightly.
Firebase features
 Offline support
Firebase transparently reconnects to the
Firebase servers as soon as you regain
connectivity.
Firebase features
 Offline support (Contd.)
In the meantime, all Firebase operations done
locally by your app will immediately fire events,
regardless of network state, so your app will
continue functioning correctly.
Firebase features
 Offline support (Contd.)
Once connectivity is reestablished, you’ll receive
the appropriate set of events so that your client
“catches up” with the current server state,
without you having to write any custom code.
Firebase features
 Real-time Synchronisation
Data updating speed of firebase is very fast.
Firebase is designed to be fast enough for high
performance real-time applications like network
games.
Firebase features
 Real-time Synchronisation (Contd.)
It maintain persistent connections between
clients and its servers so that data can be
pushed in both directions without delay, and it’s
servers are optimised for extremely low latencies.
As such, you can expect typical network
latencies (generally less than 100ms) for data
updates between clients.
Firebase features
 Data to store
At a high-level you can store any type of data in
Firebase, from game state to chat messages to
images or other media files.
Firebase features
 Data to store (Contd.)
At a low-level, it support basically the same data
types as JSON: Strings, Numbers, Booleans, and
Objects (which in turn contain Strings, Numbers,
Booleans, and more Objects).
Who uses Firebase
 Atlassian (JIRA)
 Codecademy
 Twitch
 And many more…
Firebase Data Structure
 When a new Firebase is created, it is
assigned its own unique hostname.
For example, if you were to create a
Firebase for your SampleChat application, it
could live at:
http://SampleChat.firebaseIOdemo.com/
Firebase Data Structure
Firebase Data Structure
 We refer to these URLs that point to data as
locations.
 Firebase locations can store strings, numbers,
booleans, or nested children.
Firebase Data Structure
 Nested children allow you to structure your
data hierarchically.
 For instance, SampleChat has a list of users,
which are located at:
https://SampleChat.firebaseIO-demo.com/users
Firebase Data Structure
 The data for users 'fred' and 'jack' is stored at these
nested locations:
https://SampleChat.firebaseIO-demo.com/users/fred
https://SampleChat.firebaseIO-demo.com/users/jack
 In this example, 'fred' and 'jack' are said to be children of
'users', and 'users' is said to be the parent of 'fred' and
‘jack'.
Firebase Data Structure
 Note that Firebase locations can contain either data (a
string, number, or boolean) or children, but not both.
 Locations for data can nest as deeply as you like. For
example, the last name for user 'fred' is located at:
https://SampleChat.firebaseIO-
demo.com/users/fred/name/last
Firebase integration in iOS
Firebase Integration
1. Download latest Firebase.framework from
firebase.com
2. Unzip the above file and drag the .framework
folder to your XCode project under Frameworks
Firebase Integration
3. Firebase depends on these other frameworks. Add
them to your project:
 libicucore.dylib
 libc++.dylib
 CFNetwork.framework
 Security.framework
 SystemConfiguration.framework
Firebase Integration
4. Firebase makes use of Objective-C classes and
categories, so you'll need to add this under "other linker
flags" in build settings:
 -ObjC
Creating Firebase References
 Firebase* sampleChatRef = [[Firebase alloc] initWithUrl:@“https://SampleChat.firebaseIO-demo.com"];
 Firebase* childRef = [sampleChatRef childByAppendingPath:@“users"];
This is equivalent to:
 Firebase* childRef = [[Firebase alloc] initWithUrl:@“https://SampleChat.firebaseIO-demo.com/users"];
 Firebase* parentRef = [childRef parent];
parentRef and sampleChatRef now point to the same location.
Creating Firebase References
 Firebase* usersRef = [sampleChatRef childByAppendingPath:@"users"];
 Firebase* fredRef = [usersRef childByAppendingPath:@“fred"];
is equivalent to:
 Firebase* fredRef = [sampleChatRef childByAppendingPath:@"users/fred"];
Writing Data to Firebase
First we get a reference to the location of the user’s name data:
 Firebase* nameRef = [[Firebase alloc] initWithUrl:@"https://SampleChat.firebaseIO-
demo.com/users/fred/name"];
And then we write data to his first and last name locations:
 [[nameRef childByAppendingPath:@"first"] setValue:@"Fred"];
 [[nameRef childByAppendingPath:@"last"] setValue:@“Swanson"];
Alternatively, we can do:
 [nameRef setValue:@{@"first": @"Fred", @"last": @"Swanson"}];
Writing Data to Firebase
If you want to write multiple children of a Firebase location at the same time without overwriting other existing data,
you can perform an "update" operation as shown:
 [nameRef updateChildValues:@{@"first": @"Fred", @"last": @“Swanson"}];
 Adding a Completion Callback
[dataRef setValue:@"text" withCompletionBlock:^(NSError *error, Firebase* ref)
{
if(error)
{
NSLog(@"Data could not be saved: %@", error);
}
else
{
NSLog(@"Data saved successfully.");
}
}];
Reading Data from Firebase
Firebase is a real-time database, so data is never read synchronously. Instead, you read data by attaching a
callback to a Firebase reference as shown:
NSString* url = @"https://SampleChat.firebaseIO-demo.com/users/fred/name/first";
Firebase* dataRef = [[Firebase alloc] initWithUrl:url];
[dataRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)
{
NSLog(@"fred's first name is: %@", snapshot.value);
}];
Reading Data from Firebase
We can observe different types of events:
 Value
 Child Added
 Child Changed
 Child Removed
 Child Moved
Reading Data from Firebase
All reads are done through asynchronous callbacks
If the referenced data is already cached, your callback will be
called immediately, but if this is the first time the data was
accessed by this client, Firebase will need to request the data
from the Firebase servers first.
Reading Data from Firebase
Callbacks are triggered both for the initial state of your data and
again any time data changes
In the above example, our callback will be called again if Fred's
first name ever changes.
Reading Data from Firebase
Callbacks receive snapshots of data
A snapshot is a picture of the data at a particular Firebase
location at a single point in time.
It contains all of the data at that location, including any child
data. If you want to convert this data to a native format (such as
a JavaScript object on the web or a Dictionary in Objective-C),
you must do so explicitly.
Reading Data from Firebase
Firebase is intelligent about aggregating callbacks
Firebase ensures that only the minimum required dataset is
loaded from the server, and the calling of callbacks and
generation of snapshots is extremely efficient.
As a result, you should feel comfortable attaching many
callbacks and having multiple callbacks of different types
attached to the same location.
Reading Data from Firebase
Events that are triggered on your client do not always correspond
exactly with the write operations that were performed on other
clients
For example, if two other clients were to set the same piece of
data at approximately the same time, there is no guarantee that
two events will be triggered on your local client. Depending on
the timing, those two changes could be aggregated into a single
local event. Regardless, eventually all clients will have a consistent
view of the data, even if the events triggered in the process may
differ from client-to-client.
Reading Data from Firebase
Reading data once:
[dataRef observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)
{
// do some stuff once
}];
This is equivalent to:
__block FirebaseHandle handle = [dataRef observeEventType:FEventTypeValue
withBlock:^(FDataSnapshot *snapshot)
{
// do some stuff
...
// Remove the callback
[dataRef removeObserverWithHandle:handle];
}];
Reading Data from Firebase
Using a Cancel Callback:
Firebase* fredRef = [[Firebase alloc] initWithUrl:@"https://SampleChat.firebaseIO-
demo.com/users/fred/name/first"];
[fredRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)
{
// Read succeeds.
NSLog(@"We have permission.");
} withCancelBlock:^(FDataSnapshot *snapshot)
{
// Read fails.
NSLog(@"We do not have permission.");
}];
Reading Data from Firebase
Detaching Callbacks:
 [dataRef removeObserverWithHandle:someCallbackHandle];
If you would like to remove all callbacks at a location, you can do so as shown:
 [dataRef removeAllObservers];
References:
 https://www.firebase.com/docs/ios-quickstart.html
 https://www.firebase.com/docs/data-structure.html
 https://www.firebase.com/docs/creating-
references.html
 https://www.firebase.com/docs/writing-data.html
 https://www.firebase.com/docs/reading-data.html
 https://www.firebase.com/docs/faq.html

More Related Content

What's hot

Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Amazon Web Services
 
Murach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMurach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMahmoudOHassouna
 
Firebase in a Nutshell
Firebase in a NutshellFirebase in a Nutshell
Firebase in a NutshellSumit Sahoo
 
Nonrelational Databases
Nonrelational DatabasesNonrelational Databases
Nonrelational DatabasesUdi Bauman
 
Day 5 - AWS Autoscaling Master Class - The New Capacity Plan
Day 5 - AWS Autoscaling Master Class - The New Capacity PlanDay 5 - AWS Autoscaling Master Class - The New Capacity Plan
Day 5 - AWS Autoscaling Master Class - The New Capacity PlanAmazon Web Services
 
Intoduction of FIrebase Realtime Database
Intoduction of FIrebase Realtime DatabaseIntoduction of FIrebase Realtime Database
Intoduction of FIrebase Realtime DatabaseSahil Maiyani
 
Azure Active Directory - An Introduction
Azure Active Directory  - An IntroductionAzure Active Directory  - An Introduction
Azure Active Directory - An IntroductionVenkatesh Narayanan
 
Lightning web components
Lightning web componentsLightning web components
Lightning web componentsAmit Chaudhary
 
Azure Database Services for MySQL PostgreSQL and MariaDB
Azure Database Services for MySQL PostgreSQL and MariaDBAzure Database Services for MySQL PostgreSQL and MariaDB
Azure Database Services for MySQL PostgreSQL and MariaDBNicholas Vossburg
 
AWS CloudFormation Session
AWS CloudFormation SessionAWS CloudFormation Session
AWS CloudFormation SessionKamal Maiti
 
Simplify & Standardise Your Migration to AWS with a Migration Landing Zone
Simplify & Standardise Your Migration to AWS with a Migration Landing ZoneSimplify & Standardise Your Migration to AWS with a Migration Landing Zone
Simplify & Standardise Your Migration to AWS with a Migration Landing ZoneAmazon Web Services
 
Lightning web components
Lightning web components Lightning web components
Lightning web components Cloud Analogy
 

What's hot (20)

Firebase
Firebase Firebase
Firebase
 
Introduction to AWS Amplify CLI
Introduction to AWS Amplify CLIIntroduction to AWS Amplify CLI
Introduction to AWS Amplify CLI
 
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
 
Caching
CachingCaching
Caching
 
Salesforce REST API
Salesforce  REST API Salesforce  REST API
Salesforce REST API
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
 
Murach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMurach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVC
 
Firebase in a Nutshell
Firebase in a NutshellFirebase in a Nutshell
Firebase in a Nutshell
 
Nonrelational Databases
Nonrelational DatabasesNonrelational Databases
Nonrelational Databases
 
Day 5 - AWS Autoscaling Master Class - The New Capacity Plan
Day 5 - AWS Autoscaling Master Class - The New Capacity PlanDay 5 - AWS Autoscaling Master Class - The New Capacity Plan
Day 5 - AWS Autoscaling Master Class - The New Capacity Plan
 
Intoduction of FIrebase Realtime Database
Intoduction of FIrebase Realtime DatabaseIntoduction of FIrebase Realtime Database
Intoduction of FIrebase Realtime Database
 
Azure Active Directory - An Introduction
Azure Active Directory  - An IntroductionAzure Active Directory  - An Introduction
Azure Active Directory - An Introduction
 
Deep Dive: Amazon RDS
Deep Dive: Amazon RDSDeep Dive: Amazon RDS
Deep Dive: Amazon RDS
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
Lightning web components
Lightning web componentsLightning web components
Lightning web components
 
Azure Database Services for MySQL PostgreSQL and MariaDB
Azure Database Services for MySQL PostgreSQL and MariaDBAzure Database Services for MySQL PostgreSQL and MariaDB
Azure Database Services for MySQL PostgreSQL and MariaDB
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 
AWS CloudFormation Session
AWS CloudFormation SessionAWS CloudFormation Session
AWS CloudFormation Session
 
Simplify & Standardise Your Migration to AWS with a Migration Landing Zone
Simplify & Standardise Your Migration to AWS with a Migration Landing ZoneSimplify & Standardise Your Migration to AWS with a Migration Landing Zone
Simplify & Standardise Your Migration to AWS with a Migration Landing Zone
 
Lightning web components
Lightning web components Lightning web components
Lightning web components
 

Similar to Firebase - A real-time server

ThreeBase: Firebase in 3 minutes or less
ThreeBase: Firebase in 3 minutes or lessThreeBase: Firebase in 3 minutes or less
ThreeBase: Firebase in 3 minutes or lessMayank Mohan Upadhyay
 
Introduction, Examples - Firebase
Introduction, Examples - Firebase Introduction, Examples - Firebase
Introduction, Examples - Firebase Eueung Mulyana
 
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Chris Adamson
 
Android writing and reading from firebase
Android writing and reading from firebaseAndroid writing and reading from firebase
Android writing and reading from firebaseOsahon Gino Ediagbonya
 
Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Chris Adamson
 
Firebase Adventures - Real time platform for your apps
Firebase Adventures - Real time platform for your appsFirebase Adventures - Real time platform for your apps
Firebase Adventures - Real time platform for your appsJuarez Filho
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationWebStackAcademy
 
Devfest SouthWest, Nigeria - Firebase
Devfest SouthWest, Nigeria - FirebaseDevfest SouthWest, Nigeria - Firebase
Devfest SouthWest, Nigeria - FirebaseMoyinoluwa Adeyemi
 
Real Time and Offline Applications with GraphQL
Real Time and Offline Applications with GraphQLReal Time and Offline Applications with GraphQL
Real Time and Offline Applications with GraphQLAmazon Web Services
 
Introduction to Firebase on Android
Introduction to Firebase on AndroidIntroduction to Firebase on Android
Introduction to Firebase on Androidamsanjeev
 
Firebase integration with Flutter
Firebase integration with FlutterFirebase integration with Flutter
Firebase integration with Flutterpmgdscunsri
 
Firebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteFirebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteSittiphol Phanvilai
 
Firebase in action 2021
Firebase in action 2021Firebase in action 2021
Firebase in action 2021NhanNguyen534
 

Similar to Firebase - A real-time server (20)

ThreeBase: Firebase in 3 minutes or less
ThreeBase: Firebase in 3 minutes or lessThreeBase: Firebase in 3 minutes or less
ThreeBase: Firebase in 3 minutes or less
 
Real timechat firebase
Real timechat firebaseReal timechat firebase
Real timechat firebase
 
Firebase
FirebaseFirebase
Firebase
 
Introduction, Examples - Firebase
Introduction, Examples - Firebase Introduction, Examples - Firebase
Introduction, Examples - Firebase
 
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
 
Firebase Tech Talk By Atlogys
Firebase Tech Talk By AtlogysFirebase Tech Talk By Atlogys
Firebase Tech Talk By Atlogys
 
Android writing and reading from firebase
Android writing and reading from firebaseAndroid writing and reading from firebase
Android writing and reading from firebase
 
Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)
 
Firebase Adventures - Real time platform for your apps
Firebase Adventures - Real time platform for your appsFirebase Adventures - Real time platform for your apps
Firebase Adventures - Real time platform for your apps
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
 
Devfest SouthWest, Nigeria - Firebase
Devfest SouthWest, Nigeria - FirebaseDevfest SouthWest, Nigeria - Firebase
Devfest SouthWest, Nigeria - Firebase
 
Real Time and Offline Applications with GraphQL
Real Time and Offline Applications with GraphQLReal Time and Offline Applications with GraphQL
Real Time and Offline Applications with GraphQL
 
Introduction to Firebase on Android
Introduction to Firebase on AndroidIntroduction to Firebase on Android
Introduction to Firebase on Android
 
Firebase.pptx
Firebase.pptxFirebase.pptx
Firebase.pptx
 
Firebase.pptx
Firebase.pptxFirebase.pptx
Firebase.pptx
 
Firebase.pptx
Firebase.pptxFirebase.pptx
Firebase.pptx
 
Firebase.pptx
Firebase.pptxFirebase.pptx
Firebase.pptx
 
Firebase integration with Flutter
Firebase integration with FlutterFirebase integration with Flutter
Firebase integration with Flutter
 
Firebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteFirebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: Keynote
 
Firebase in action 2021
Firebase in action 2021Firebase in action 2021
Firebase in action 2021
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Firebase - A real-time server

  • 2. What is Firebase?  Firebase is a scalable, real-time back for your application. It allows developers to build rich, collaborative applications without the hassle of managing servers or writing server-side code
  • 3. Firebase is Platform Independent!  Firebase has support for the web, iOS, OS X, and Android clients.  In addition, it has a Node.js and a Java library designed for server-side use.  The Firebase web client supports all mainstream browsers (IE 7+, Firefox 3+, Chrome, Safari, Opera, and major mobile web browsers), and it works on any network connection.
  • 4. How does it work?  Developers install firebase by including a library in their applications.  This library provides a data structure that is automatically synchronised between all of your clients and with our servers.  If one client changes a piece of data, every other client observing the same piece of data will be updated as well within milliseconds.
  • 5. Is Firebase just for “real-time” apps?  Not at all!  Firebase is for anybody that wants to write apps without having to run backend servers or write server code.  Many developers prefer focusing on frontend HTML and JavaScript rather than building, deploying, and maintaining server-side backend code.  Even if real-time isn’t critical to your application, Firebase can help you build your application faster and scale seamlessly.
  • 6. Firebase features  Custom server code Firebase fully support access from your backend servers. When used in this configuration, you still get all of the benefits of using Firebase as your data store (way less code, easier scaling, real-time updates, etc.), while gaining the flexibility to run whatever custom backend logic you need.
  • 7. Firebase features  Custom server code (Contd.) It has a Node.JS client, a Java Client and a REST API specifically for this purpose. This allows you to do your own data processing, custom validation, etc. on your own servers while still relying on Firebase for data storage and real- time propagation of updates.
  • 8. Firebase features  First class security Firebase is intended for business-critical applications, and it take the safety of your data very seriously. All of your data is stored redundantly and off-site backups are made nightly.
  • 9. Firebase features  Offline support Firebase transparently reconnects to the Firebase servers as soon as you regain connectivity.
  • 10. Firebase features  Offline support (Contd.) In the meantime, all Firebase operations done locally by your app will immediately fire events, regardless of network state, so your app will continue functioning correctly.
  • 11. Firebase features  Offline support (Contd.) Once connectivity is reestablished, you’ll receive the appropriate set of events so that your client “catches up” with the current server state, without you having to write any custom code.
  • 12. Firebase features  Real-time Synchronisation Data updating speed of firebase is very fast. Firebase is designed to be fast enough for high performance real-time applications like network games.
  • 13. Firebase features  Real-time Synchronisation (Contd.) It maintain persistent connections between clients and its servers so that data can be pushed in both directions without delay, and it’s servers are optimised for extremely low latencies. As such, you can expect typical network latencies (generally less than 100ms) for data updates between clients.
  • 14. Firebase features  Data to store At a high-level you can store any type of data in Firebase, from game state to chat messages to images or other media files.
  • 15. Firebase features  Data to store (Contd.) At a low-level, it support basically the same data types as JSON: Strings, Numbers, Booleans, and Objects (which in turn contain Strings, Numbers, Booleans, and more Objects).
  • 16. Who uses Firebase  Atlassian (JIRA)  Codecademy  Twitch  And many more…
  • 17. Firebase Data Structure  When a new Firebase is created, it is assigned its own unique hostname. For example, if you were to create a Firebase for your SampleChat application, it could live at: http://SampleChat.firebaseIOdemo.com/
  • 19. Firebase Data Structure  We refer to these URLs that point to data as locations.  Firebase locations can store strings, numbers, booleans, or nested children.
  • 20. Firebase Data Structure  Nested children allow you to structure your data hierarchically.  For instance, SampleChat has a list of users, which are located at: https://SampleChat.firebaseIO-demo.com/users
  • 21. Firebase Data Structure  The data for users 'fred' and 'jack' is stored at these nested locations: https://SampleChat.firebaseIO-demo.com/users/fred https://SampleChat.firebaseIO-demo.com/users/jack  In this example, 'fred' and 'jack' are said to be children of 'users', and 'users' is said to be the parent of 'fred' and ‘jack'.
  • 22. Firebase Data Structure  Note that Firebase locations can contain either data (a string, number, or boolean) or children, but not both.  Locations for data can nest as deeply as you like. For example, the last name for user 'fred' is located at: https://SampleChat.firebaseIO- demo.com/users/fred/name/last
  • 24. Firebase Integration 1. Download latest Firebase.framework from firebase.com 2. Unzip the above file and drag the .framework folder to your XCode project under Frameworks
  • 25. Firebase Integration 3. Firebase depends on these other frameworks. Add them to your project:  libicucore.dylib  libc++.dylib  CFNetwork.framework  Security.framework  SystemConfiguration.framework
  • 26. Firebase Integration 4. Firebase makes use of Objective-C classes and categories, so you'll need to add this under "other linker flags" in build settings:  -ObjC
  • 27. Creating Firebase References  Firebase* sampleChatRef = [[Firebase alloc] initWithUrl:@“https://SampleChat.firebaseIO-demo.com"];  Firebase* childRef = [sampleChatRef childByAppendingPath:@“users"]; This is equivalent to:  Firebase* childRef = [[Firebase alloc] initWithUrl:@“https://SampleChat.firebaseIO-demo.com/users"];  Firebase* parentRef = [childRef parent]; parentRef and sampleChatRef now point to the same location.
  • 28. Creating Firebase References  Firebase* usersRef = [sampleChatRef childByAppendingPath:@"users"];  Firebase* fredRef = [usersRef childByAppendingPath:@“fred"]; is equivalent to:  Firebase* fredRef = [sampleChatRef childByAppendingPath:@"users/fred"];
  • 29. Writing Data to Firebase First we get a reference to the location of the user’s name data:  Firebase* nameRef = [[Firebase alloc] initWithUrl:@"https://SampleChat.firebaseIO- demo.com/users/fred/name"]; And then we write data to his first and last name locations:  [[nameRef childByAppendingPath:@"first"] setValue:@"Fred"];  [[nameRef childByAppendingPath:@"last"] setValue:@“Swanson"]; Alternatively, we can do:  [nameRef setValue:@{@"first": @"Fred", @"last": @"Swanson"}];
  • 30. Writing Data to Firebase If you want to write multiple children of a Firebase location at the same time without overwriting other existing data, you can perform an "update" operation as shown:  [nameRef updateChildValues:@{@"first": @"Fred", @"last": @“Swanson"}];  Adding a Completion Callback [dataRef setValue:@"text" withCompletionBlock:^(NSError *error, Firebase* ref) { if(error) { NSLog(@"Data could not be saved: %@", error); } else { NSLog(@"Data saved successfully."); } }];
  • 31. Reading Data from Firebase Firebase is a real-time database, so data is never read synchronously. Instead, you read data by attaching a callback to a Firebase reference as shown: NSString* url = @"https://SampleChat.firebaseIO-demo.com/users/fred/name/first"; Firebase* dataRef = [[Firebase alloc] initWithUrl:url]; [dataRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { NSLog(@"fred's first name is: %@", snapshot.value); }];
  • 32. Reading Data from Firebase We can observe different types of events:  Value  Child Added  Child Changed  Child Removed  Child Moved
  • 33. Reading Data from Firebase All reads are done through asynchronous callbacks If the referenced data is already cached, your callback will be called immediately, but if this is the first time the data was accessed by this client, Firebase will need to request the data from the Firebase servers first.
  • 34. Reading Data from Firebase Callbacks are triggered both for the initial state of your data and again any time data changes In the above example, our callback will be called again if Fred's first name ever changes.
  • 35. Reading Data from Firebase Callbacks receive snapshots of data A snapshot is a picture of the data at a particular Firebase location at a single point in time. It contains all of the data at that location, including any child data. If you want to convert this data to a native format (such as a JavaScript object on the web or a Dictionary in Objective-C), you must do so explicitly.
  • 36. Reading Data from Firebase Firebase is intelligent about aggregating callbacks Firebase ensures that only the minimum required dataset is loaded from the server, and the calling of callbacks and generation of snapshots is extremely efficient. As a result, you should feel comfortable attaching many callbacks and having multiple callbacks of different types attached to the same location.
  • 37. Reading Data from Firebase Events that are triggered on your client do not always correspond exactly with the write operations that were performed on other clients For example, if two other clients were to set the same piece of data at approximately the same time, there is no guarantee that two events will be triggered on your local client. Depending on the timing, those two changes could be aggregated into a single local event. Regardless, eventually all clients will have a consistent view of the data, even if the events triggered in the process may differ from client-to-client.
  • 38. Reading Data from Firebase Reading data once: [dataRef observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { // do some stuff once }]; This is equivalent to: __block FirebaseHandle handle = [dataRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { // do some stuff ... // Remove the callback [dataRef removeObserverWithHandle:handle]; }];
  • 39. Reading Data from Firebase Using a Cancel Callback: Firebase* fredRef = [[Firebase alloc] initWithUrl:@"https://SampleChat.firebaseIO- demo.com/users/fred/name/first"]; [fredRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { // Read succeeds. NSLog(@"We have permission."); } withCancelBlock:^(FDataSnapshot *snapshot) { // Read fails. NSLog(@"We do not have permission."); }];
  • 40. Reading Data from Firebase Detaching Callbacks:  [dataRef removeObserverWithHandle:someCallbackHandle]; If you would like to remove all callbacks at a location, you can do so as shown:  [dataRef removeAllObservers];
  • 41. References:  https://www.firebase.com/docs/ios-quickstart.html  https://www.firebase.com/docs/data-structure.html  https://www.firebase.com/docs/creating- references.html  https://www.firebase.com/docs/writing-data.html  https://www.firebase.com/docs/reading-data.html  https://www.firebase.com/docs/faq.html