SlideShare uma empresa Scribd logo
1 de 61
Baixar para ler offline
Offline-First Mobile Web Apps with
PouchDB, IBM Cloudant, and IBM Bluemix
OSCON
Wednesday, July 22, 2015
Bradley Holt, Cloudant Developer Advocate
@BradleyHolt
Image Credit: Joan Touzet (@wohali), ASF Member, CouchDB PMC Member
2
Image Credit: Device landscape by Jeremy Keith, on Flickr
3
Not just mobile first…!
4
Image Credit: Cloud Formation Over the Adirondacks by Bradley Holt
Offline First!
Because being offline shouldn't be an error condition.!
5
Doesn't ubiquitous
connectivity make offline-
enabled apps unnecessary?!
6
No.!
7
Quite the opposite, in fact.!
8
Ubiquitous connectivity is
driving the demand for 

offline capabilities.!
9
How?!
The Eight Fallacies of Distributed Computing
1.  The network is reliable
2.  Latency is zero
3.  Bandwidth is infinite
4.  The network is secure
5.  Topology doesn't change
6.  There is one administrator
7.  Transport cost is zero
8.  The network is homogeneous
10
Text Credit: The Eight Fallacies of Distributed Computing by Peter Deutsch | Image Credit: Pneumatic Central by Sleestak, on Flickr
11
Offline-first is the only way 

to achieve a true, 100% 

always-on user experience.*!
*assuming the device is reliable!
Benefits of Offline First
12
•  Better, faster user experience, both offline and online
•  Allow your users to work offline or with limited connectivity
•  Potentially saves battery life and bandwidth usage
Offline Patterns & Anti-Patterns
•  Don't return an error for no reason
•  Do let users view cached/saved data
•  Do synchronize data when connected
13
Offline Patterns & Anti-Patterns
•  Don't return an error for no reason
•  Do let users view cached/saved data
•  Do synchronize data when connected
13
Offline Patterns & Anti-Patterns
•  Don't return an error for no reason
•  Do let users view cached/saved data
•  Do synchronize data when connected
13
Offline Patterns & Anti-Patterns
•  Don't return an error for no reason
•  Do let users view cached/saved data
•  Do synchronize data when connected
13
Introducing PouchDB
PouchDB
•  A database in your web browser
•  Can synchronize with any
database that implements the
CouchDB Replication Protocol
•  Makes create, read, update and
delete operations extremely fast
15
JSON Documents
16
{

_id: "6EF9D2B0-13D3-1378-8D30-39E3CE0B36C2",

_rev: "1-0b457efcf82fb29492ef927ba5b6ee15",

type: "Feature",

geometry: {

type: "Point",

coordinates: [

-71.1028,

42.3691

]

},

properties: {

session_id: "3486b13f-7b8a-8a96-dfbf-9b82800e367f",

timestamp: 1422928591717

}

}
PouchDB Framework Adapters
17
Responsive Mobile Web Apps or
Hybrid Mobile Web Apps
Responsive Mobile Web Apps
•  HTML5, CSS and JavaScript mobile
web apps
•  Responsive design
•  Enhanced to enable offline usage
19
Hybrid Mobile Web Apps
•  Native mobile web apps built with
HTML5, CSS and JavaScript
•  Good for:
•  Fully-featured, cross-platform native apps
•  High-fidelity prototypes
20
Apache CouchDB
Apache CouchDB
•  JSON document database
•  HTTP API
•  Master-master replication
22
IBM Cloudant
•  Globally distributed data layer for
web and mobile applications
•  MongoDB-style queries
•  Advanced geospatial capabilities
•  Full text search indexing
23
PouchDB and Cloudant Replication
24
CouchDB Replication Protocol
•  One-off, one way operation
•  Peer-to-peer (masterless)
•  Incremental
•  Conflict detection
25
Apache Cordova, PhoneGap and Ionic
Apache Cordova and PhoneGap
27
Image Credit: build.phonegap by Andrés Álvarez Iglesias, on Flickr
Ionic
•  Mobile-optimized HTML, CSS
and JavaScript components
•  Builds on Apache Cordova
•  Utilizes AngularJS
•  CLI installable via npm
28
Using Cordova and Ionic
$ npm install -g cordova ionic"
$ ionic start energy-monitor tabs"
$ cd energy-monitor"
$ ionic platform add ios"
$ ionic build ios"
$ ionic emulate ios"
29
Image Credit: Getting Started with Ionic
HTML5 Offline Application Cache
HTML5 Offline Application Cache
•  Enables fully-functional offline
web apps
•  Stores files and assets for
offline browsing
•  Makes page loads very fast,
even when online
31
Cache Manifest File
32
<html manifest="example.appcache">

…

</html>

CACHE MANIFEST

# v1 - 2015-01-08

index.html

logo.png

app.css

app.js
Deploying a Web App to IBM Bluemix
About IBM Bluemix
•  Platform-as-a-Service (PaaS)
based on Cloud Foundry
•  Catalog of boilerplates, runtimes,
and services from which you can
compose your applications
•  Cloudant is one of the many
services available
•  Sign up at:
https://bluemix.net/
34
Bluemix Runtimes
•  IBM buildpacks
•  Java
•  Node.js
•  Community buildpacks
•  Go
•  PHP
•  Python
•  Ruby
•  More…
35
Data Management and Big Data Services
•  Cloudant
•  BigInsights for Apache Hadoop
•  IBM Analytics for Apache Hadoop
•  Swift Object Storage
•  More…
36
Location Tracker
•  Stores data locally in PouchDB
•  Front end built with AngularJS
•  Authentication logic built with Node.js
•  User interface built with Leaflet
•  Replicates location data to Cloudant
•  More info:
https://cloudant.com/location-tracker/
37
38
Location Tracker Part 3: https://cloudant.com/location-tracker/
PouchDB Code Examples
Installing PouchDB
40
<script src=

"https://cdn.jsdelivr.net/pouchdb/3.5.0/pouchdb.min.js"

></script>

CACHE MANIFEST

# v2 - 2015-01-08

index.html

logo.png

app.css

app.js

https://cdn.jsdelivr.net/pouchdb/3.5.0/pouchdb.min.js
PouchDB Code Examples
41
•  Creating a local PouchDB database
•  Creating a remote PouchDB database
•  Creating a new document
•  Updating a document
•  Querying a database
•  Replicating PouchDB
Creating a Local PouchDB Database
42
var db = new PouchDB("smart-meter");"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/01-create-local-database.js
Creating a Remote PouchDB Database
43
var remoteDb = new PouchDB("https://bradley-holt.cloudant.com/smart-meter");"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/02-create-remote-database.js
Cross-Origin Resource Sharing (CORS)
•  Enable Cross-Origin Resource
Sharing (CORS) on remote database
•  Browsers place security restrictions
on cross-site HTTP requests
•  If you run into a problem, remember
this warning!
44
Image Credit: Grunge Warning Sign - Do Not Read This Sign by Nicolas Raymond, on Flickr
Creating a New Document
45
var db = new PouchDB("smart-meter");"
db.put({"
_id: "2014-11-12T23:27:03.794Z","
kilowatt_hours: 14"
}).then(function() {"
console.log("Document created");"
}).catch(function(error) {"
console.log(error);"
});"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/04-create-document-put.js
Updating a Document
46
db.put({"
_id: "2014-11-12T23:27:03.794Z","
kilowatt_hours: 14"
}).then(function() {"
return db.get("2014-11-12T23:27:03.794Z");"
}).then(function(doc) {"
// Update the value for kilowatt hours"
doc.kilowatt_hours = 15;"
// Put the document back to the database"
return db.put(doc);"
}).catch(function(error) {"
console.log(error);"
});"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/05-update-document.js
Querying a Database with allDocs"
47
db.bulkDocs(["
{_id: "2014-11-12T23:27:03.794Z", kilowatt_hours: 14},"
{_id: "2014-11-13T00:52:01.471Z", kilowatt_hours: 15},"
{_id: "2014-11-13T01:39:28.911Z", kilowatt_hours: 16},"
{_id: "2014-11-13T02:52:01.471Z", kilowatt_hours: 17}"
]).then(function(result) {"
// Get all documents"
return db.allDocs({include_docs: true});"
}).then(function(response) {"
console.log(response);"
}).catch(function(error) {"
console.log(error);"
});"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/07-query-database-all-docs.js
allDocs Options
•  include_docs"
•  conflicts"
•  attachments"
•  startkey"
•  endkey"
•  inclusive_end
(true by default)
•  limit"
•  skip"
•  descending"
•  key"
•  keys"
48
Querying a Database with Map/Reduce
49
•  Most queries can be done with allDocs (in PouchDB)
•  Map functions transform documents into indexes
•  Reduce functions aggregate results of Map functions
•  _sum"
•  _count"
•  _stats"
Querying a Database with PouchDB Find
•  Based on Cloudant Query (Mango)
•  MongoDB-style query language
•  Define fields to index
50
Image Credit: Mango with section on a white background by bangdoll, on Flickr
Bidirectionally Replicating a PouchDB Database
51
var db = new PouchDB("smart-meter");"
var remoteDb = new PouchDB("
"https://bradley-holt.cloudant.com/smart-meter""
);"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/08-replicate-database.js
Bidirectionally Replicating a PouchDB Database
52
Promise.all(["
db.bulkDocs(["
{_id: "2014-11-12T23:27:03.794Z", kilowatt_hours: 14},"
{_id: "2014-11-13T00:52:01.471Z", kilowatt_hours: 15}"
]),"
remoteDb.bulkDocs(["
{_id: "2014-11-11T22:35:01.433Z", kilowatt_hours: 11},"
{_id: "2014-11-12T00:43:01.633Z", kilowatt_hours: 13}"
])"
]).then(function() {"
…"
});"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/09-replicate-database-bidirectional.js
Bidirectionally Replicating a PouchDB Database
53
db.sync(remoteDb, {"
live: false,"
retry: false"
}).on("change", function(info) {"
// Replication has written a new document"
console.log(info);"
}).on("complete", function(info) {"
// Replication has complete or been cancelled"
console.log(info);"
}).on("error", function(error) {"
// Replication has stopped due to an unrecoverable failure"
console.log(error);"
});"
https://github.com/bradley-holt/offline-first/blob/master/pouchdb/09-replicate-database-bidirectional.js
54
A Deep Dive into Offline-First with PouchDB
and IBM Cloudant
Date: Thursday, August 27, 2015
Time: 1:00 PM - 2:00 PM EDT
Register at:
https://cloudant.com/resources/webinars/
55
Visit IBM at booth #501
to talk to an IBM
Recruiter @ OSCON
Image Credits
57
•  Joan Touzet (@wohali), ASF Member, CouchDB PMC Member
<https://twitter.com/wohali/status/595689720933445632>
•  Device landscape by Jeremy Keith, on Flickr
<https://www.flickr.com/photos/adactio/6153481666>
•  Cloud Formation Over the Adirondacks by Bradley Holt
<https://twitter.com/BradleyHolt/status/623030107679002624>
•  Pneumatic Central by Sleestak, on Flickr
<https://www.flickr.com/photos/dlanod/235990854>
•  build.phonegap by Andrés Álvarez Iglesias, on Flickr
<https://www.flickr.com/photos/doctorserone/5682929553>
•  Getting Started with Ionic
<http://ionicframework.com/getting-started/>
•  Grunge Warning Sign - Do Not Read This Sign by Nicolas Raymond, on Flickr
<https://www.flickr.com/photos/80497449@N04/7417352980>
•  Mango with section on a white background by bangdoll, on Flickr
<https://www.flickr.com/photos/bangdoll/5665235102>
Bradley Holt
Cloudant Developer Advocate
bradley.holt@us.ibm.com
@BradleyHolt
github.com/bradley-holt

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

How to contribute to cloud native computing foundation (CNCF)
How to contribute to cloud native computing foundation (CNCF)How to contribute to cloud native computing foundation (CNCF)
How to contribute to cloud native computing foundation (CNCF)
 
OpenWhisk: Event-driven Design
OpenWhisk: Event-driven DesignOpenWhisk: Event-driven Design
OpenWhisk: Event-driven Design
 
India Serverless Summit 2017 - Sponsorship Deck
India Serverless Summit 2017 - Sponsorship DeckIndia Serverless Summit 2017 - Sponsorship Deck
India Serverless Summit 2017 - Sponsorship Deck
 
Going Cloud Native with Cloud Foundry
Going Cloud Native with Cloud FoundryGoing Cloud Native with Cloud Foundry
Going Cloud Native with Cloud Foundry
 
Cloud Native Architectures with an Open Source, Event Driven, Serverless Plat...
Cloud Native Architectures with an Open Source, Event Driven, Serverless Plat...Cloud Native Architectures with an Open Source, Event Driven, Serverless Plat...
Cloud Native Architectures with an Open Source, Event Driven, Serverless Plat...
 
CNCF Introduction - Feb 2018
CNCF Introduction - Feb 2018CNCF Introduction - Feb 2018
CNCF Introduction - Feb 2018
 
OpenWhisk Deep Dive: the action container model
OpenWhisk Deep Dive: the action container modelOpenWhisk Deep Dive: the action container model
OpenWhisk Deep Dive: the action container model
 
Containers & Cloud Native Ops Cloud Foundry Approach
Containers & Cloud Native Ops Cloud Foundry ApproachContainers & Cloud Native Ops Cloud Foundry Approach
Containers & Cloud Native Ops Cloud Foundry Approach
 
Intro - Cloud Native
Intro - Cloud NativeIntro - Cloud Native
Intro - Cloud Native
 
Openshift Container Platform
Openshift Container PlatformOpenshift Container Platform
Openshift Container Platform
 
IPaaS 2.0: Fuse Integration Services (Robert Davies & Keith Babo)
IPaaS 2.0: Fuse Integration Services (Robert Davies & Keith Babo)IPaaS 2.0: Fuse Integration Services (Robert Davies & Keith Babo)
IPaaS 2.0: Fuse Integration Services (Robert Davies & Keith Babo)
 
Cloud foundry: The Platform for Forging Cloud Native Applications
Cloud foundry: The Platform for Forging Cloud Native ApplicationsCloud foundry: The Platform for Forging Cloud Native Applications
Cloud foundry: The Platform for Forging Cloud Native Applications
 
All roads lead to the cloud
All roads lead to the cloudAll roads lead to the cloud
All roads lead to the cloud
 
Distributed Storage in the Cloud
Distributed Storage in the CloudDistributed Storage in the Cloud
Distributed Storage in the Cloud
 
Open stack + Cloud Foundry: Palo Alto Meetup February 2015
Open stack + Cloud Foundry: Palo Alto Meetup February 2015Open stack + Cloud Foundry: Palo Alto Meetup February 2015
Open stack + Cloud Foundry: Palo Alto Meetup February 2015
 
Containers vs serverless - Navigating application deployment options
Containers vs serverless - Navigating application deployment optionsContainers vs serverless - Navigating application deployment options
Containers vs serverless - Navigating application deployment options
 
Dipping Your Toes Into Cloud Native Application Development
Dipping Your Toes Into Cloud Native Application DevelopmentDipping Your Toes Into Cloud Native Application Development
Dipping Your Toes Into Cloud Native Application Development
 
Cloud Foundry: Infrastructure Options
Cloud Foundry: Infrastructure OptionsCloud Foundry: Infrastructure Options
Cloud Foundry: Infrastructure Options
 
Why kubernetes for Serverless (FaaS)
Why kubernetes for Serverless (FaaS)Why kubernetes for Serverless (FaaS)
Why kubernetes for Serverless (FaaS)
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and Microservice
 

Destaque

Destaque (16)

Scalability 09262012
Scalability 09262012Scalability 09262012
Scalability 09262012
 
SQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsSQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 Questions
 
Birmingham Meetup
Birmingham MeetupBirmingham Meetup
Birmingham Meetup
 
Mobile App Development With IBM Cloudant
Mobile App Development With IBM CloudantMobile App Development With IBM Cloudant
Mobile App Development With IBM Cloudant
 
Collaborative Line of Business Applications on IBM Bluemix
Collaborative Line of Business Applications on IBM BluemixCollaborative Line of Business Applications on IBM Bluemix
Collaborative Line of Business Applications on IBM Bluemix
 
I See NoSQL Document Stores in Geospatial Applications
I See NoSQL Document Stores in Geospatial ApplicationsI See NoSQL Document Stores in Geospatial Applications
I See NoSQL Document Stores in Geospatial Applications
 
Practical Use of a NoSQL
Practical Use of a NoSQLPractical Use of a NoSQL
Practical Use of a NoSQL
 
Cloud Data Services: A Brand New Ballgame for Business
Cloud Data Services: A  Brand New Ballgame for BusinessCloud Data Services: A  Brand New Ballgame for Business
Cloud Data Services: A Brand New Ballgame for Business
 
IBM Relay 2015: Open for Data
IBM Relay 2015: Open for Data IBM Relay 2015: Open for Data
IBM Relay 2015: Open for Data
 
IBM Relay 2015: Cloud is All About the Customer
IBM Relay 2015: Cloud is All About the Customer IBM Relay 2015: Cloud is All About the Customer
IBM Relay 2015: Cloud is All About the Customer
 
Socket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time ApplicationSocket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time Application
 
IBM Relay 2015: Opening Keynote
IBM Relay 2015: Opening Keynote IBM Relay 2015: Opening Keynote
IBM Relay 2015: Opening Keynote
 
IBM Relay 2015: Securing the Future
IBM Relay 2015: Securing the Future IBM Relay 2015: Securing the Future
IBM Relay 2015: Securing the Future
 
Using Service Discovery and Service Proxy
Using Service Discovery and Service ProxyUsing Service Discovery and Service Proxy
Using Service Discovery and Service Proxy
 
IBM RTP Dojo Launch
IBM RTP Dojo LaunchIBM RTP Dojo Launch
IBM RTP Dojo Launch
 
IBM - Introduction to Cloudant
IBM - Introduction to CloudantIBM - Introduction to Cloudant
IBM - Introduction to Cloudant
 

Semelhante a Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix

Semelhante a Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix (20)

Offline first solutions highland web group - december 2015
Offline first solutions   highland web group - december 2015Offline first solutions   highland web group - december 2015
Offline first solutions highland web group - december 2015
 
NoSQL on the move
NoSQL on the moveNoSQL on the move
NoSQL on the move
 
Offline-First Apps with PouchDB
Offline-First Apps with PouchDB Offline-First Apps with PouchDB
Offline-First Apps with PouchDB
 
Cloud computing: highlights
Cloud computing: highlightsCloud computing: highlights
Cloud computing: highlights
 
Offline first development - Glasgow PHP - January 2016
Offline first development - Glasgow PHP - January 2016Offline first development - Glasgow PHP - January 2016
Offline first development - Glasgow PHP - January 2016
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
 
Glynn Bird – Cloudant – Building applications for success.- NoSQL matters Bar...
Glynn Bird – Cloudant – Building applications for success.- NoSQL matters Bar...Glynn Bird – Cloudant – Building applications for success.- NoSQL matters Bar...
Glynn Bird – Cloudant – Building applications for success.- NoSQL matters Bar...
 
Plone FSR
Plone FSRPlone FSR
Plone FSR
 
Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...
Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...
Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applications
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 
Day 13 - Creating Data Processing Services | Train the Trainers Program
Day 13 - Creating Data Processing Services | Train the Trainers ProgramDay 13 - Creating Data Processing Services | Train the Trainers Program
Day 13 - Creating Data Processing Services | Train the Trainers Program
 
Introduction to Apache Mesos and DC/OS
Introduction to Apache Mesos and DC/OSIntroduction to Apache Mesos and DC/OS
Introduction to Apache Mesos and DC/OS
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
Simplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring CloudSimplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring Cloud
 
Integrating Google Cloud Dataproc with Alluxio for faster performance in the ...
Integrating Google Cloud Dataproc with Alluxio for faster performance in the ...Integrating Google Cloud Dataproc with Alluxio for faster performance in the ...
Integrating Google Cloud Dataproc with Alluxio for faster performance in the ...
 
.NET Cloud-Native Bootcamp- Los Angeles
.NET Cloud-Native Bootcamp- Los Angeles.NET Cloud-Native Bootcamp- Los Angeles
.NET Cloud-Native Bootcamp- Los Angeles
 
ITB2017 - Keynote
ITB2017 - KeynoteITB2017 - Keynote
ITB2017 - Keynote
 
Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...
Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...
Lightning Talk: Why and How to Integrate MongoDB and NoSQL into Hadoop Big Da...
 
Custom Runtimes for the Cloud
Custom Runtimes for the CloudCustom Runtimes for the Cloud
Custom Runtimes for the Cloud
 

Mais de IBM

Meetupslides 150409100501-conversion-gate01
Meetupslides 150409100501-conversion-gate01Meetupslides 150409100501-conversion-gate01
Meetupslides 150409100501-conversion-gate01
IBM
 
Watson on Bluemix
Watson on BluemixWatson on Bluemix
Watson on Bluemix
IBM
 

Mais de IBM (20)

Microservices - Choosing the Right Cloud Services and Tools
Microservices - Choosing the Right Cloud Services and ToolsMicroservices - Choosing the Right Cloud Services and Tools
Microservices - Choosing the Right Cloud Services and Tools
 
Digital Innovation in the Cognitive Era
Digital Innovation in the Cognitive EraDigital Innovation in the Cognitive Era
Digital Innovation in the Cognitive Era
 
How Bluemix Helps NASA Innovate
How Bluemix Helps NASA InnovateHow Bluemix Helps NASA Innovate
How Bluemix Helps NASA Innovate
 
IBM Relay 2015: New Data Sources, New Value. Watson, Weather and Beyond
IBM Relay 2015: New Data Sources, New Value. Watson, Weather and Beyond IBM Relay 2015: New Data Sources, New Value. Watson, Weather and Beyond
IBM Relay 2015: New Data Sources, New Value. Watson, Weather and Beyond
 
IBM Relay 2015: Expect More From Private Cloud
IBM Relay 2015: Expect More From Private CloudIBM Relay 2015: Expect More From Private Cloud
IBM Relay 2015: Expect More From Private Cloud
 
Node on Guard
Node on GuardNode on Guard
Node on Guard
 
Discover the Linux on z Systems Effect
Discover the Linux on z Systems EffectDiscover the Linux on z Systems Effect
Discover the Linux on z Systems Effect
 
Exploring the Open Source Linux Ecosystem
Exploring the Open Source Linux EcosystemExploring the Open Source Linux Ecosystem
Exploring the Open Source Linux Ecosystem
 
Open Source Centers of Gravity
Open Source Centers of GravityOpen Source Centers of Gravity
Open Source Centers of Gravity
 
Meetupslides 150409100501-conversion-gate01
Meetupslides 150409100501-conversion-gate01Meetupslides 150409100501-conversion-gate01
Meetupslides 150409100501-conversion-gate01
 
Integrating MongoDB into Cloud Foundry App
Integrating MongoDB into Cloud Foundry AppIntegrating MongoDB into Cloud Foundry App
Integrating MongoDB into Cloud Foundry App
 
Building Your Own Watson Powered Application on Bluemix
Building Your Own Watson Powered Application on BluemixBuilding Your Own Watson Powered Application on Bluemix
Building Your Own Watson Powered Application on Bluemix
 
Bluemix Girls Night Out
Bluemix Girls Night Out Bluemix Girls Night Out
Bluemix Girls Night Out
 
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & CloudantBuild Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
 
Using Watson to build Cognitive IoT Apps on Bluemix
Using Watson to build Cognitive IoT Apps on BluemixUsing Watson to build Cognitive IoT Apps on Bluemix
Using Watson to build Cognitive IoT Apps on Bluemix
 
Watson on Bluemix
Watson on BluemixWatson on Bluemix
Watson on Bluemix
 
PHP Buildpacks in the Cloud on Bluemix
PHP Buildpacks in the Cloud on BluemixPHP Buildpacks in the Cloud on Bluemix
PHP Buildpacks in the Cloud on Bluemix
 
Introduction: Watson Services on IBM Bluemix Webcast
Introduction: Watson Services on IBM Bluemix Webcast Introduction: Watson Services on IBM Bluemix Webcast
Introduction: Watson Services on IBM Bluemix Webcast
 
Connecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixConnecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
Automate the Application Deployment Process
Automate the Application Deployment ProcessAutomate the Application Deployment Process
Automate the Application Deployment Process
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix

  • 1. Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix OSCON Wednesday, July 22, 2015 Bradley Holt, Cloudant Developer Advocate @BradleyHolt
  • 2. Image Credit: Joan Touzet (@wohali), ASF Member, CouchDB PMC Member 2
  • 3. Image Credit: Device landscape by Jeremy Keith, on Flickr 3 Not just mobile first…!
  • 4. 4 Image Credit: Cloud Formation Over the Adirondacks by Bradley Holt Offline First! Because being offline shouldn't be an error condition.!
  • 5. 5 Doesn't ubiquitous connectivity make offline- enabled apps unnecessary?!
  • 8. 8 Ubiquitous connectivity is driving the demand for 
 offline capabilities.!
  • 10. The Eight Fallacies of Distributed Computing 1.  The network is reliable 2.  Latency is zero 3.  Bandwidth is infinite 4.  The network is secure 5.  Topology doesn't change 6.  There is one administrator 7.  Transport cost is zero 8.  The network is homogeneous 10 Text Credit: The Eight Fallacies of Distributed Computing by Peter Deutsch | Image Credit: Pneumatic Central by Sleestak, on Flickr
  • 11. 11 Offline-first is the only way 
 to achieve a true, 100% 
 always-on user experience.*! *assuming the device is reliable!
  • 12. Benefits of Offline First 12 •  Better, faster user experience, both offline and online •  Allow your users to work offline or with limited connectivity •  Potentially saves battery life and bandwidth usage
  • 13. Offline Patterns & Anti-Patterns •  Don't return an error for no reason •  Do let users view cached/saved data •  Do synchronize data when connected 13
  • 14. Offline Patterns & Anti-Patterns •  Don't return an error for no reason •  Do let users view cached/saved data •  Do synchronize data when connected 13
  • 15. Offline Patterns & Anti-Patterns •  Don't return an error for no reason •  Do let users view cached/saved data •  Do synchronize data when connected 13
  • 16. Offline Patterns & Anti-Patterns •  Don't return an error for no reason •  Do let users view cached/saved data •  Do synchronize data when connected 13
  • 18. PouchDB •  A database in your web browser •  Can synchronize with any database that implements the CouchDB Replication Protocol •  Makes create, read, update and delete operations extremely fast 15
  • 19. JSON Documents 16 {
 _id: "6EF9D2B0-13D3-1378-8D30-39E3CE0B36C2",
 _rev: "1-0b457efcf82fb29492ef927ba5b6ee15",
 type: "Feature",
 geometry: {
 type: "Point",
 coordinates: [
 -71.1028,
 42.3691
 ]
 },
 properties: {
 session_id: "3486b13f-7b8a-8a96-dfbf-9b82800e367f",
 timestamp: 1422928591717
 }
 }
  • 21. Responsive Mobile Web Apps or Hybrid Mobile Web Apps
  • 22. Responsive Mobile Web Apps •  HTML5, CSS and JavaScript mobile web apps •  Responsive design •  Enhanced to enable offline usage 19
  • 23. Hybrid Mobile Web Apps •  Native mobile web apps built with HTML5, CSS and JavaScript •  Good for: •  Fully-featured, cross-platform native apps •  High-fidelity prototypes 20
  • 25. Apache CouchDB •  JSON document database •  HTTP API •  Master-master replication 22
  • 26. IBM Cloudant •  Globally distributed data layer for web and mobile applications •  MongoDB-style queries •  Advanced geospatial capabilities •  Full text search indexing 23
  • 27. PouchDB and Cloudant Replication 24
  • 28. CouchDB Replication Protocol •  One-off, one way operation •  Peer-to-peer (masterless) •  Incremental •  Conflict detection 25
  • 30. Apache Cordova and PhoneGap 27 Image Credit: build.phonegap by Andrés Álvarez Iglesias, on Flickr
  • 31. Ionic •  Mobile-optimized HTML, CSS and JavaScript components •  Builds on Apache Cordova •  Utilizes AngularJS •  CLI installable via npm 28
  • 32. Using Cordova and Ionic $ npm install -g cordova ionic" $ ionic start energy-monitor tabs" $ cd energy-monitor" $ ionic platform add ios" $ ionic build ios" $ ionic emulate ios" 29 Image Credit: Getting Started with Ionic
  • 34. HTML5 Offline Application Cache •  Enables fully-functional offline web apps •  Stores files and assets for offline browsing •  Makes page loads very fast, even when online 31
  • 35. Cache Manifest File 32 <html manifest="example.appcache">
 …
 </html>
 CACHE MANIFEST
 # v1 - 2015-01-08
 index.html
 logo.png
 app.css
 app.js
  • 36. Deploying a Web App to IBM Bluemix
  • 37. About IBM Bluemix •  Platform-as-a-Service (PaaS) based on Cloud Foundry •  Catalog of boilerplates, runtimes, and services from which you can compose your applications •  Cloudant is one of the many services available •  Sign up at: https://bluemix.net/ 34
  • 38. Bluemix Runtimes •  IBM buildpacks •  Java •  Node.js •  Community buildpacks •  Go •  PHP •  Python •  Ruby •  More… 35
  • 39. Data Management and Big Data Services •  Cloudant •  BigInsights for Apache Hadoop •  IBM Analytics for Apache Hadoop •  Swift Object Storage •  More… 36
  • 40. Location Tracker •  Stores data locally in PouchDB •  Front end built with AngularJS •  Authentication logic built with Node.js •  User interface built with Leaflet •  Replicates location data to Cloudant •  More info: https://cloudant.com/location-tracker/ 37
  • 41. 38 Location Tracker Part 3: https://cloudant.com/location-tracker/
  • 43. Installing PouchDB 40 <script src=
 "https://cdn.jsdelivr.net/pouchdb/3.5.0/pouchdb.min.js"
 ></script>
 CACHE MANIFEST
 # v2 - 2015-01-08
 index.html
 logo.png
 app.css
 app.js
 https://cdn.jsdelivr.net/pouchdb/3.5.0/pouchdb.min.js
  • 44. PouchDB Code Examples 41 •  Creating a local PouchDB database •  Creating a remote PouchDB database •  Creating a new document •  Updating a document •  Querying a database •  Replicating PouchDB
  • 45. Creating a Local PouchDB Database 42 var db = new PouchDB("smart-meter");" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/01-create-local-database.js
  • 46. Creating a Remote PouchDB Database 43 var remoteDb = new PouchDB("https://bradley-holt.cloudant.com/smart-meter");" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/02-create-remote-database.js
  • 47. Cross-Origin Resource Sharing (CORS) •  Enable Cross-Origin Resource Sharing (CORS) on remote database •  Browsers place security restrictions on cross-site HTTP requests •  If you run into a problem, remember this warning! 44 Image Credit: Grunge Warning Sign - Do Not Read This Sign by Nicolas Raymond, on Flickr
  • 48. Creating a New Document 45 var db = new PouchDB("smart-meter");" db.put({" _id: "2014-11-12T23:27:03.794Z"," kilowatt_hours: 14" }).then(function() {" console.log("Document created");" }).catch(function(error) {" console.log(error);" });" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/04-create-document-put.js
  • 49. Updating a Document 46 db.put({" _id: "2014-11-12T23:27:03.794Z"," kilowatt_hours: 14" }).then(function() {" return db.get("2014-11-12T23:27:03.794Z");" }).then(function(doc) {" // Update the value for kilowatt hours" doc.kilowatt_hours = 15;" // Put the document back to the database" return db.put(doc);" }).catch(function(error) {" console.log(error);" });" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/05-update-document.js
  • 50. Querying a Database with allDocs" 47 db.bulkDocs([" {_id: "2014-11-12T23:27:03.794Z", kilowatt_hours: 14}," {_id: "2014-11-13T00:52:01.471Z", kilowatt_hours: 15}," {_id: "2014-11-13T01:39:28.911Z", kilowatt_hours: 16}," {_id: "2014-11-13T02:52:01.471Z", kilowatt_hours: 17}" ]).then(function(result) {" // Get all documents" return db.allDocs({include_docs: true});" }).then(function(response) {" console.log(response);" }).catch(function(error) {" console.log(error);" });" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/07-query-database-all-docs.js
  • 51. allDocs Options •  include_docs" •  conflicts" •  attachments" •  startkey" •  endkey" •  inclusive_end (true by default) •  limit" •  skip" •  descending" •  key" •  keys" 48
  • 52. Querying a Database with Map/Reduce 49 •  Most queries can be done with allDocs (in PouchDB) •  Map functions transform documents into indexes •  Reduce functions aggregate results of Map functions •  _sum" •  _count" •  _stats"
  • 53. Querying a Database with PouchDB Find •  Based on Cloudant Query (Mango) •  MongoDB-style query language •  Define fields to index 50 Image Credit: Mango with section on a white background by bangdoll, on Flickr
  • 54. Bidirectionally Replicating a PouchDB Database 51 var db = new PouchDB("smart-meter");" var remoteDb = new PouchDB(" "https://bradley-holt.cloudant.com/smart-meter"" );" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/08-replicate-database.js
  • 55. Bidirectionally Replicating a PouchDB Database 52 Promise.all([" db.bulkDocs([" {_id: "2014-11-12T23:27:03.794Z", kilowatt_hours: 14}," {_id: "2014-11-13T00:52:01.471Z", kilowatt_hours: 15}" ])," remoteDb.bulkDocs([" {_id: "2014-11-11T22:35:01.433Z", kilowatt_hours: 11}," {_id: "2014-11-12T00:43:01.633Z", kilowatt_hours: 13}" ])" ]).then(function() {" …" });" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/09-replicate-database-bidirectional.js
  • 56. Bidirectionally Replicating a PouchDB Database 53 db.sync(remoteDb, {" live: false," retry: false" }).on("change", function(info) {" // Replication has written a new document" console.log(info);" }).on("complete", function(info) {" // Replication has complete or been cancelled" console.log(info);" }).on("error", function(error) {" // Replication has stopped due to an unrecoverable failure" console.log(error);" });" https://github.com/bradley-holt/offline-first/blob/master/pouchdb/09-replicate-database-bidirectional.js
  • 57. 54
  • 58. A Deep Dive into Offline-First with PouchDB and IBM Cloudant Date: Thursday, August 27, 2015 Time: 1:00 PM - 2:00 PM EDT Register at: https://cloudant.com/resources/webinars/ 55
  • 59. Visit IBM at booth #501 to talk to an IBM Recruiter @ OSCON
  • 60. Image Credits 57 •  Joan Touzet (@wohali), ASF Member, CouchDB PMC Member <https://twitter.com/wohali/status/595689720933445632> •  Device landscape by Jeremy Keith, on Flickr <https://www.flickr.com/photos/adactio/6153481666> •  Cloud Formation Over the Adirondacks by Bradley Holt <https://twitter.com/BradleyHolt/status/623030107679002624> •  Pneumatic Central by Sleestak, on Flickr <https://www.flickr.com/photos/dlanod/235990854> •  build.phonegap by Andrés Álvarez Iglesias, on Flickr <https://www.flickr.com/photos/doctorserone/5682929553> •  Getting Started with Ionic <http://ionicframework.com/getting-started/> •  Grunge Warning Sign - Do Not Read This Sign by Nicolas Raymond, on Flickr <https://www.flickr.com/photos/80497449@N04/7417352980> •  Mango with section on a white background by bangdoll, on Flickr <https://www.flickr.com/photos/bangdoll/5665235102>
  • 61. Bradley Holt Cloudant Developer Advocate bradley.holt@us.ibm.com @BradleyHolt github.com/bradley-holt