couchbase mobile ideathon in tokyo 2014.08.29: developing with couchbase lite

33
Couchbase Mobile Ideathon Traun Leyden Lead Android Developer [email protected] 10/29/13

Upload: keiko-ogura

Post on 02-Jul-2015

500 views

Category:

Technology


0 download

DESCRIPTION

This slides was talked at Couchbase Mobile Ideathon in Tokyo on Aug 29th, 2014. Please contact us ([email protected]) if you have any questions.

TRANSCRIPT

Page 1: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Couchbase Mobile Ideathon

Traun Leyden

Lead Android Developer

[email protected]

10/29/13

Page 2: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

About me

• I was previously at a startup company doing a mobile CRM app — we converted our app to Couchbase Lite to solve networking performance issues

• Now I work full time as the lead developer on Couchbase Lite Android

• I also work on demo apps on both iOS and Android• I have blog at http://tleyden.github.io

Page 3: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

About Couchbase

• Was the merger of two companies• CouchOne (commercial support for CouchDB)• Membase (a commercially supported / distributed

version of memcached)• Our flagship product is Couchbase Server, a fault

tolerant distributed database.• We recently released Couchbase Mobile, targeted

towards mobile and embedded devices/sensors.• All of our products are released as Open Source

software under the Apache2 license.• We now have an office in Japan

Page 4: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Why would you want to use Couchbase Mobile?

Will your app work when the network isslow or only sometimes connected?

?

Page 5: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

We think our network is fast, but ..

• On trains or underground• Large crowds• Out of the city center• Deployed on sites which have unreliable

Wifi• Sometimes you are completely offline• Etc ..

Page 6: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

The simplest use case — sending a tweet on the subway

Users expect better than this!

Page 7: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Our solution - Sync

Page 8: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Your app reads/writes to a local database

This will be fast even if the network is slow or offline

Page 9: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Couchbase Lite sync’s the data to the cloud (can run in background)

Page 10: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

TodoLite Demo

• TodoLite is a todo list app• Users can login via Facebook• Users can share todo lists with each

other• Different users can both view and

update the same list• Photo attachments can be added to

Todo items• Supports conflict resolution• Source code available on github (see

resources slide)• Available in iTunes app store and

Google Play

Page 11: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Understanding sync gateway

• Sync Gateway can control which users can see which documents.

• In effect, it can partition the database so that users only see a subset of the database

Page 12: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Partitioning a database by company and region

Page 13: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Using Sync Gateway to partition a database

• Sync Gateway can do this efficiently• The main reason it was created

• Sync Gateway uses “channels” to do this

• Let’s walk through an example

Page 14: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Using Channels in OfficeRadar Example

OfficeRadar uses iBeacons to detect who is in the office

Page 15: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Users should only see activity for other users in their organization

Page 16: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Sync Function

• The sync function partitions the database by putting documents into channels

• To understand the sync function, we must look at the OfficeRadar documents

Page 17: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

OfficeRadar GeofenceEvent Document

{ "_id":"!QJoBU7cRa~m2E2tYloSHHN","_rev":"1-8e8f3cebf357a2546c0d40e497227115","action":"entry","beacon":"4a83813db6ce76e9618793cf483cfa10","created_at":"2014-08-28T23:43:19.119Z","userprofile":"10152586863333982","type":"geofence_event","organization":"couchbase"

}

Each Geofence Event is associated with an organization

Page 18: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

OfficeRadar UserProfile Document

{ "_id":"10152586863333982","_rev":"1-2b6a6e182ef77cd15db7171023931e8d","type":"profile","authSystem":"facebook","name":"Traun Leyden","organization":"couchbase"

}

Each User Profile is associated with an organization

Page 19: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

OfficeRadar Sync Function

function(doc, oldDoc) {

if (doc.type == "geofence_event") {

channel(doc.organization);

} else if (doc.type == "profile") {

access(doc.userid, doc.organization);

}}

Page 20: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Adding a geofence event to a channel

if (doc.type == "geofence_event") {

channel(doc.organization);

}

Page 21: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Allowing a user to access an organization’s channel

else if (doc.type == "profile") {

access(doc.userid, doc.organization);

}

Page 22: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Views

• Map/Reduce mechanism

- A standard method of indexing in NoSQL

- A view is similar to index in relational database.

• App-defined map function

- Called on every document

- Can emit arbitrary key/value pairs into the index

• Optional reduce function

- Data aggregation / grouping

• Functions are registered as native callbacks

- Native callbacks make sense for performance and to match the rest of the app codebase

Putting the “No” in NoSQL

Page 23: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Queries

• Basic feature set

- Key ranges, offset/limit, reverse, group by key…

- No joins or fancy sorting

- but compound keys (and clever emits) allow for some tricks

• LiveQuery subclass

- Monitors a view for changes

- Can think of it as a “pub-sub” approach

- Register a callback that is triggered when the query changes

Page 24: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Use Cases

Page 25: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Embedded

Image capture of roller coaster riders to local database in multiple theme park locations

Machine to machine communication example

Unreliable network connectivity required offline capture / later sync to centralized management system

Picsolve

Page 26: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Infinite Campus

Education / Social Interaction

Selectively push out learning modules / multimedia lessons to individual students

Teachers and students use custom mobile chat apps for real-time Q&A during lectures

Homework assignments can be completed offline anywhere

Page 27: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Offline Sensor Data

A weather balloon could collect sensor data while offline and sync it whenever it is online

Page 28: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Travel Expense Tracker

• I am in Tokyo, but my iPhone 5 is locked so I cannot use a local SIM card.

• But I need an app to track my expenses, so I must be able to enter expenses while offline.

• When I get back to the US, I want to sync these expenses to the Cloud so I can download a spreadsheet.

Page 29: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Resources

• These slides will be made available on SlideShare

• Sample code links

• https://github.com/couchbaselabs/ToDoLite-Android

• https://github.com/couchbaselabs/ToDoLite-iOS

• https://github.com/tleyden/office-radar

• Documentation

• http://developer.couchbase.com/mobile

• Download

- http://mobile.couchbase.com

• Contact: [email protected]

Page 30: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Resources 2

• Couchbase Mobile Google Group (community): groups.google.com/group/mobile-couchbase/

• Couchbase Mobile Twitter: https://twitter.com/CouchbaseMobile

• Run Sync Gateway (and Couchbase Server!) under Docker: http://tleyden.github.io/blog/2014/06/22/running-couchbase-sync-gateway-on-gce/

Page 31: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Upcoming Event: Hackathon

• http://couchbasejpcommunity.doorkeeper.jp/events/13988

Page 32: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Upcoming Event: Couchbase Server

• Couchbase Server http://couchbasejpcommunity.doorkeeper.jp/events/14785

Page 33: Couchbase Mobile Ideathon in Tokyo 2014.08.29: Developing with couchbase lite

Thanks for watching!

Contact: [email protected]

Questions?