Slide 1

Slide 1 text

Push databases, RethinkDB, and building realtime apps Move Fast and Break Things San Francisco, CA August 5, 2015

Slide 2

Slide 2 text

Jorge Silva Developer Evangelist @ RethinkDB @thejsj

Slide 3

Slide 3 text

Preface The realtime web

Slide 4

Slide 4 text

Realtime apps

Slide 5

Slide 5 text

Realtime apps

Slide 6

Slide 6 text

Realtime apps • More and more apps are built to be realtime • Users have come to want and expect this behavior in their apps • Building realtime apps is hard

Slide 7

Slide 7 text

Building realtime apps is hard • You can keep everything in a single server • You can poll the database to keep track of updates • You can publish updates through 
 a message broker

Slide 8

Slide 8 text

Building realtime apps is hard • All solutions present a tradeoff between scalability and complexity • It’s hard to keep track of state in 
 realtime architectures

Slide 9

Slide 9 text

Introduction What is RethinkDB?

Slide 10

Slide 10 text

What is RethinkDB? • Open source database for building realtime web applications • NoSQL database that stores schemaless JSON documents • Distributed database that is easy to scale

Slide 11

Slide 11 text

Push Database • Subscribe to change notifications from database queries (changefeeds) • No more polling — the database pushes changes to your app • Reduce the amount of plumbing needed to stream live updates

Slide 12

Slide 12 text

Push Database • Having your database push changes keeps your database as the central source of truth • Having a central source of truth simplifies your architecture

Slide 13

Slide 13 text

Push Database RethinkDB is an excellent database for: • Collaborative web and mobile apps • Multiplayer games • Streaming analytics apps • Connected devices

Slide 14

Slide 14 text

Introduction to ReQL RethinkDB Query Language

Slide 15

Slide 15 text

Introduction to ReQL • ReQL embeds natively into your programming language • Compose ReQL queries by chaining commands

Slide 16

Slide 16 text

Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Number of unique last names

Slide 17

Slide 17 text

Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Access a database table

Slide 18

Slide 18 text

Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Isolate a document property

Slide 19

Slide 19 text

Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Consolidate duplicate values

Slide 20

Slide 20 text

Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Display the number of items

Slide 21

Slide 21 text

Sample ReQL Queries r.table("users") .filter(r.row("age").gt(30)) r.table(“post") .eqJoin(“uId”, r.table(“users”)) .zip() r.table("fellowship") .filter({species: "hobbit"}) .update({species: "halfling"})

Slide 22

Slide 22 text

Additional ReQL Features • Geospatial indexing for location- based queries • Date and time functions • Support for storing binary objects • Execute http requests using r.http

Slide 23

Slide 23 text

Realtime Updates Working with Changefeeds

Slide 24

Slide 24 text

Subscribe to change notifications on database queries Changefeeds

Slide 25

Slide 25 text

r.table("users").changes() Track changes on the users table Changefeeds

Slide 26

Slide 26 text

Changefeeds • The changes command returns a cursor that receives updates • Each update includes the new and old value of the modified record

Slide 27

Slide 27 text

Changefeeds r.table("users").changes() r.table("users") .insert({name: "Bob"}) Changefeed output: { new_val: { id: '362ae837-2e29-4695-adef-4fa415138f90', name: 'Bob', ... }, old_val: null }

Slide 28

Slide 28 text

Changefeeds r.table("users").changes() r.table("users") .filter({name: "Bob"}).delete() Changefeed output: { new_val: null, old_val: { id: '362ae837-2e29-4695-adef-4fa415138f90', name: 'Bob', ... } }

Slide 29

Slide 29 text

Changefeeds r.table("users").changes() r.table("users") .get("362ae837-2e29-4695-adef-4fa415138f90") .update({name: "Bobby"}) Changefeed output: { new_val: { id: '362ae837-2e29-4695-adef-4fa415138f90', name: 'Bobby' }, old_val: { id: '362ae837-2e29-4695-adef-4fa415138f90', name: 'Bob' } }

Slide 30

Slide 30 text

Changefeeds r.table("players") .orderBy({index: r.desc("score")}) .limit(3).changes() Track top three players by score Chain the changes command to an actual ReQL query:

Slide 31

Slide 31 text

Questions http://questions.rethinkdb.com

Slide 32

Slide 32 text

Summary • Keeping track of state in realtime apps is hard • RethinkDB solves this problem by pushing changes to your app • In the future, we'll see more database that use the push model

Slide 33

Slide 33 text

Questions • RethinkDB website:
 http://rethinkdb.com • Install RethinkDB:
 http://rethinkdb.com/install/ • Email me: [email protected] • Tweet: @thejsj, @rethinkdb