#MDBlocal
Ian Ward, Solutions Architect
REST-less Mobile Apps:
Why offline-first and sync matters
for your App and Business
CHICAGO
Great expectations
Users expect seamless app experiences
#MDBLocal
#MDBLocal
#MDBLocal
Expectations are high for mobile apps
ALWAYS-ON EXPERIENCE
ANYWHERE
UX RESPONSIVENESS
ZERO-LATENCY FEEL
REALTIME
& COLLABORATIVE
#MDBLocal
Expectations are high for mobile apps
ALWAYS-ON EXPERIENCE
ANYWHERE
UX RESPONSIVENESS
ZERO-LATENCY FEEL
REALTIME
& COLLABORATIVE
#MDBLocal
Expectations are high for mobile apps
ALWAYS-ON EXPERIENCE
ANYWHERE
UX RESPONSIVENESS
ZERO-LATENCY FEEL
REALTIME
& COLLABORATIVE
#MDBLocal
Expectations are high for mobile apps
ALWAYS-ON EXPERIENCE
ANYWHERE
UX RESPONSIVENESS
ZERO-LATENCY FEEL
REALTIME &
COLLABORATIVE
#MDBLocal
This is not easy
Beyond "Hello, World"
#MDBLocal
Data exchange must be...
Reliable & resilient
Asynchronous
Fast & adaptive
Dev friendly
#MDBLocal
Effort in the wrong places
Networking code
ORMs & sqlite
Mobile/server dev handoffs
Specialized tech
#MDBLocal
A hostile environment...?
Mobile networks have variable latency
Connectivity can be lost at any moment
Apps can be shut down spontaneously
#MDBLocal
Every stack is different
#MDBLocal
#MDBLocal
#MDBLocal
#MDBLocal
Modern app development
#MDBLocal
REST APIs
#MDBLocal
REST APIs
Great for passive data sources
Not so great as backends for complex apps
#MDBLocal
REST APIs
You are responsible for:
• Conflict resolution
• Recovery from network failure
• Type/schema validation
• Encoding and decoding objects
#MDBLocal
#MDBLocal
#MDBLocal
Let Realm handle this
What is Realm?
A database and a company?
Sounds familiar.
#MDBLocal
#MDBLocal
#MDBLocal
Open source, loved by devs
Realm's open-source on-device database:
100k+ developers using it
65% of Fortune 1000 using it
2B+ app installs
50k+ GitHub stars
18k+ Twitter followers
Active community involvement
#MDBLocal
Open source, loved by devs
Designed and built for mobile
Just objects using idiomatic code
Live objects update automatically
The database is the data model
#MDBLocal
3 components of Realm
#MDBLocal
Realm Server
Real-time sync
Automatic conflict resolution
Flexible schema change support
Event handling
#MDBLocal
Realm Mobile Database
Offline-first API
Object interface with
native relationship support
Change notifications
to keep UI up-to-date
Abstracts network handling
#MDBLocal
Realm Sync
Implicit sync on write
Deterministic, strong eventually-consistent
conflict resolution
Efficient data exchange:
compressed, field-level diffs
Two modes: full and subset (query) sync
#MDBLocal
A quick protocol comparison
#MDBLocal
A new paradigm
#MDBLocal
Realm replaces...
Custom code
REST offload
App-specific distributed systems development
Per-platform network stacks
#MDBLocal
...with
Productivity: always-on for frontline workers
Efficiency: cross-platform and multi-language support
Revenue & retention: responsive, satisfying UX
Flexibility: any device, any time, anywhere
#MDBLocal
Your classes are the models
import RealmSwift
// Define your models like regular Swift classes
class Dog: Object {
@objc dynamic var name = ""
@objc dynamic var age = 0
}
class Person: Object {
@objc dynamic var name = ""
@objc dynamic var picture: Data? = nil // optionals ok
let dogs = List<Dog>() // references to other objects ok
}
#MDBLocal
Your classes are the models
// Use them like regular Swift objects
let myDog = Dog()
myDog.name = "Rex"
myDog.age = 1
print("name of dog: (myDog.name)")
#MDBLocal
Objects are live
// Get the default Realm
let realm = try! Realm()
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
// Live objects reflect the actual state
puppies.count // => 1
#MDBLocal
Objects are live
// Get the default Realm
let realm = try! Realm()
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
// Live objects reflect the actual state
puppies.count // => 1
#MDBLocal
Objects are live
// Get the default Realm
let realm = try! Realm()
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
// Live objects reflect the actual state
puppies.count // => 1
#MDBLocal
Objects are live
// Get the default Realm
let realm = try! Realm()
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
// Live objects reflect the actual state
puppies.count // => 1
#MDBLocal
Objects are live
// Get the default Realm
let realm = try! Realm()
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
// Live objects reflect the actual state
puppies.count // => 1
#MDBLocal
Objects are live
// Get the default Realm
let realm = try! Realm()
// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
// Live objects reflect the actual state
puppies.count // => 1
#MDBLocal
Future architecture
Use cases
REST-less mobile apps
#MDBLocal
Digital transformation:
food services
#MDBLocal
Digital transformation:
a major cruise vacation operator
#MDBLocal
Digital transformation:
Cathay Pacific airline
#MDBLocal
Digital transformation:
Health care provider with legacy APIs
#MDBLocal
Digital transformation:
RapidFunnel sales app
Something in common
Avoid the communication breakdown
#MDBLocal
#MDBLocal
Users expect seamless experiences
#MDBLocal
Meeting these expectations is not easy
#MDBLocal
Let Realm handle this
#MDBLocal
THANK YOU
#MDBLocal
Thank you!
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync Matters for Your App & Business

MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync Matters for Your App & Business