Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Realm Object Server

Realm Object Server

DroidDevs CPH on 2016/11/09

Emanuele Zattin

November 09, 2016
Tweet

More Decks by Emanuele Zattin

Other Decks in Technology

Transcript

  1. About Realm • Headquartered in San Francisco, with engineering office

    in Copenhagen • ~50 employees • Series B startup, $29M raised
  2. Realm Mobile Database • On-device cross-platform object database • Launched

    July 2014 • Developed in the open, fully open source • 16K+ GitHub stars, 100K+ active developers
  3. Developers Love Realm for Power, Simplicity, Ease of Use Marco

    Sero @marcosero Me using @realm for the first time: “this CAN’T be that easy. Pretty sure I’m missing something.” 7:32 AM - 29 Apr 2015
  4. Developers Love Realm for Power, Simplicity, Ease of Use Vijaya

    P. Kandel @kandelvijaya I boosted my database of 200,000 rows search from 7 seconds to 0.5 seconds with @realm . Practically under 30 mins of using it 1st time. 10:09 PM - 10 Sep 2015
  5. Developers Love Realm for Power, Simplicity, Ease of Use David

    McGraw @xmcgraw I continue to be a massive fan of @realm. If you’re not using this… go home, you’re drunk. 8:47 AM - 12 Mar 2016
  6. Developers Love Realm for Power, Simplicity, Ease of Use ¯\_(ツ)_/¯

    @coletzLp @realm is THE thing for mobile app development now. #android #ios #backend 3:05 PM - 27 Sep 2016
  7. Users Expect More of Apps Today • Offline first: They

    need apps that work well offline and when network connections are intermittent • Reactive: They expect apps that are highly responsive, with all changes immediately reflected in the UI • Real-time: They expect every user and device to stay in sync with each other in real-time • Collaborative: They want highly collaborative features and experiences within their apps • Seamless: They expect to be able to move seamlessly from device to device
  8. Developer priorities • Time-to-market: Your team need to be able

    to deliver quality apps quickly and on time • Ability: With high user expectations, the team need the ability to easily add advanced features like data sync, messaging and collaboration. • Cross-platform: To reach the full audience, you need to be able to deliver apps for both iOS and Android • Standardize: To manage all the apps and reduce complexity, you want to standardize on a single platform
  9. Realm Mobile Database Real-time Sync Realm Object Server SDK SDK

    SDK Sync
 Engine Dashboard Auth System Encryption Layer What is it? Access Control Full DB access Data connectors Object Store SD SDK SDK Enterprise Feature Event Framework
  10. Delivers Key Mobile Solutions • Eliminates network challenges • Simplifies

    data architecture • Unlocks existing infrastructure
  11. REST is brittle and cumbersome in a mobile world •

    What happens when there is no connectivity? • Queueing? • Persistence? • What about connectivity being lost during requests? • Tokens? Do they have to be persisted in app? • State-full services? • Resource intensive • Need for multiple REST calls. High latency cost • Often incurs duplication of data • JSON parsing is expensive
  12. SDK 1 2 • Offline-first • Full database on the

    device • Queries run locally • Writes apply immediately • Reactive architecture keeps UI up-to-date • Automatic sync happens in the background • Resilient to any network conditions Eliminate Network Challenges
  13. Objects as API’s Mobile Server Realtime data sync BuyObject ShoppingCart:

    → Status: nil OrderInfo: nil BuyObject ShoppingCart: → Status: nil OrderInfo: nil
  14. Objects as API’s Mobile Server Realtime data sync BuyObject ShoppingCart:

    → Status: nil OrderInfo: nil BuyObject ShoppingCart: → Status: nil OrderInfo: nil
  15. Objects as API’s Mobile Server Realtime data sync BuyObject ShoppingCart:

    → Status: nil OrderInfo: nil BuyObject ShoppingCart: → Status: nil OrderInfo: nil
  16. Objects as API’s Mobile Server Realtime data sync BuyObject ShoppingCart:

    → Status: “processing” OrderInfo: nil BuyObject ShoppingCart: → Status: “processing” OrderInfo: nil
  17. Objects as API’s Mobile Server Realtime data sync BuyObject ShoppingCart:

    → Status: “processing” OrderInfo: nil BuyObject ShoppingCart: → Status: “processing” OrderInfo: nil
  18. Objects as API’s Mobile Server Realtime data sync BuyObject ShoppingCart:

    → Status: “done” OrderInfo: → BuyObject ShoppingCart: → Status: “done” OrderInfo: →
  19. Delivers Key Mobile Solutions • Eliminates network challenges • Simplifies

    data architecture • Unlocks existing infrastructure
  20. Delivers Key Mobile Solutions • Eliminates network challenges • Simplifies

    data architecture • Unlocks existing infrastructure
  21. Typical Application Data Flow Native object JSON Native object SQL

    Native object JSON Native object SQLite SQLite
  22. • It’s just objects
 on the device and on the

    server • Objects are live,
 they update—automatically and immediately—in response to changes • Not an ORM,
 the database is the data model • Easier for developers 
 to build, change, maintain • Reduce code complexity
 via unified data format; cross-platform • Encrypted at rest & transit Objects all the way down Simplify Data Architecture
  23. Delivers Key Mobile Solutions • Eliminates network challenges • Simplifies

    data architecture • Unlocks existing infrastructure
  24. Delivers Key Mobile Solutions • Eliminates network challenges • Simplifies

    data architecture • Unlocks existing infrastructure
  25. Legacy Systems Hold Back Mobile XML JSON REST SOAP /facilities

    /departments {"facility": "west-1A", "departments": [ {"type": "manufacturing"}, {"type": "operations"}] } <?xml version="1.0" encoding="UTF-8" ?> <root> <department>manufacturing</department> <facilities>west-1A</facilities> </root>
  26. Unlock Existing Infrastructure DC9WP Coupon: Coupon: DC9WP coupon.code = DC9WP

    coupon.isValid = true 1 2 3 • Bridge legacy APIs • Shift complexity to backend • Node.js SDK • Identical object interface • Full database capabilities • Apply changes to push data • Event framework • Listen and respond to changes from clients • Pass along data to other systems or databases • Supports custom authentication
  27. Hard features made easy Realtime Collaboration Real-time 2-Way Data Sync

    Messaging / Chat Endpoint Computing Presence + API Mobilization Event Processing Pub/Sub & Push Notifications In-App & Cross-App Search IoT Sensor Sync Offline First Experiences
  28. Create native objects that map directly to the database. //

    Define you model class by extending RealmObject public class Dog extends RealmObject { public String name; // fields can also be private of course public int age = 1; // default values } public class Person extends RealmObject { @PrimaryKey public long id; public String name; // support for custom logic in accessors public RealmList<Dog> dogs; // declare one-to-many relationships }
  29. Perform complex queries across your object graph RealmResults<User> result2 =

    realm.where(User.class) .equalTo("name", "John") .or() .equalTo("name", "Peter") .findAll(); RealmResults<User> result = realm.where(User.class).findAll(); result = result.sort("age"); // Sort ascending result = result.sort("age", Sort.DESCENDING);
  30. All changes occur in transactions offering ACID compliance // Obtain

    a Realm instance Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); Book cheeseBook = realm.createObject(Book.class); cheeseBook.title = "Gouda Recipes"; cheeseBook.id = 1; realm.commitTransaction();
  31. Realm objects live-update in response to changes RealmResults<Dog> puppies =

    realm.where(Dog.class).lessThan("age", 2); puppies.length(); // => 0 realm.beginTransaction(); Dog myDog = realm.createObject(Dog.class); myDog.name = "Rex"; myDog.age = 1; realm.commitTransaction(); puppies.length(); // => 1
  32. public class MyActivity extends Activity { private Realm realm; private

    RealmChangeListener realmListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); realm = Realm.getDefaultInstance(); realmListener = new RealmChangeListener() { @Override public void onChange(Realm realm) { // ... do something with the updates (UI, etc.) ... }}; realm.addChangeListener(realmListener); } @Override protected void onDestroy() { super.onDestroy(); Listen for live object changes to simplify your architecture
  33. public class MyActivity extends Activity { private Realm realm; private

    RealmChangeListener realmListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); realm = Realm.getDefaultInstance(); realmListener = new RealmChangeListener() { @Override public void onChange(Realm realm) { // ... do something with the updates (UI, etc.) ... }}; realm.addChangeListener(realmListener); } @Override protected void onDestroy() { super.onDestroy(); // Remove the listener. realm.removeChangeListener(realmListener); // Close the Realm instance. realm.close(); } } Listen for live object changes to simplify your architecture
  34. Realm Object Server synchronizes object changes in real-time. Server-side Realms

    Device-side Realms Realm Object Server Real-time Sync
  35. Authenticating a user SyncCredentials me = SyncCredentials.usernamePassword(username, password, true); String

    authURL = "http://my.realm-auth-server.com:9080/auth"; SyncUser user = SyncUser.login(me, authURL);
  36. Open a Realm instance and get ready for synchronization String

    serverURL = "realm://my.realm-server.com/~/default"; SyncConfiguration conf = new SyncConfiguration.Builder(user, serverURL).build(); Realm realm = Realm.getInstance(conf); // Any changes made to this Realm will be synced across all devices!
  37. Benefits for developers • Networking abstracted away. No need to

    worry about connectivity, JSON parsing, object mapping… • Unified Data Model. Same data format and reactivity on Client and Backend. • Straight line from Server to UI. Data can be bound directly to UI on Client.
  38. The Realm Mobile Platform Realm Mobile Database: local object database

    Open Source Software (Apache 2 license) Realm Object Server: synchronize the database with server and multiple devices Realm Dashboard: shows you statistics, execute triggers, …