26
The open-source database for the realtime web.

Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Embed Size (px)

Citation preview

Page 1: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

The open-source database for the realtime web.

Page 2: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Source: http://googledrive.blogspot.com/2014/06/newdocssheetsslides.html

Page 3: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB
Page 4: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Building realtime apps is hard

It’s hard to keep track of state in realtime architectures.

Realtime web app server

Realtime web app server Mobile app server

Message queue

Database cluster

Queues communicate state and messages between servers.

Page 5: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Building realtime apps is hard

Polling data to keep track of updates is cumbersome.

Adding new realtime functionality keeps getting harder.

Routing realtime messages vs. broadcasting messages.

It’s hard to keep track of state in realtime architectures.

Page 6: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

What is RethinkDB?

• Open source database for building realtime web apps

• NoSQL database that stores schemaless JSON documents

• Distributed database that is easy to scale

Page 7: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Built for realtime apps

RethinkDB lets you subscribe to change notifications on database queries.

r.table(‘users’).changes() # Opens a changefeed on a table

Subscribe to changes on the ‘users’ table:

No more polling: the database pushes changes to your app, with a live stream of updates.

Page 8: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Built for realtime apps

Changefeeds let you build scalable, realtime apps.

Realtime web app server

Realtime web app server Mobile app server

RethinkDB cluster

Each server subscribes to a RethinkDB changefeed.

Servers are stateless, and scale easily (just open a changefeed!)

Page 9: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Built for realtime apps

Changefeeds let you build scalable, realtime apps:

• Collaborative web and mobile apps • Multiplayer games • Streaming analytics apps • Realtime marketplaces • Connected devices

Page 10: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Querying RethinkDB

r.table(‘users’) .pluck(‘last_name’) .distinct().count()

Count unique last names with ReQL:

Page 11: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Querying RethinkDB

r.table(‘users’) .pluck(‘last_name’) .distinct().count()

Count unique last names with ReQL:

Access a database table

Page 12: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Querying RethinkDB

r.table(‘users’) .pluck(‘last_name’) .distinct().count()

Count unique last names with ReQL:

Isolate a document property

Page 13: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Querying RethinkDB

r.table(‘users’) .pluck(‘last_name’) .distinct().count()

Count unique last names with ReQL:

Consolidate duplicate values

Page 14: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Querying RethinkDB

r.table(‘users’) .pluck(‘last_name’) .distinct().count()

Count unique last names with ReQL:

Count the number of items

Page 15: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Understanding ReQL

RethinkDB’s query language embeds natively into your programming language.

• Compose queries by chaining • Queries are executed and

distributed on the server • Python, Ruby, JavaScript, and 20+

other languages supported

Page 16: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

What can you do with ReQL?• Transformations: map, orderBy, skip, limit,

slice

• Aggregations: group, reduce, count, sum, avg, min, max, distinct, contains

• Documents: row, pluck, without, merge, append, difference, keys, hasFields, spliceAt

• Writing: insert, update, replace, delete

• Control: forEach, range, branch, do, coerceTo, expr

Page 17: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Changefeeds work on queries

r.table(‘user_profiles’) .filter(r.row(‘likes’).gt(30)) .changes()

Get notified when a user profile gets over 30 likes:

Page 18: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Changefeeds work on queries

r.table(‘user_profiles’) .filter(r.row(‘likes’).gt(30)) .changes()

Get notified when a user profile gets over 30 likes:

Page 19: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Changefeeds work on queries

r.table(‘user_profiles’) .filter(r.row(‘likes’).gt(30)) .changes()

Get notified when a user profile gets over 30 likes:

Clients can subscribe to this realtime stream of updates.

Page 20: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Example: realtime questions

questions.rethinkdb.com

Let’s play with changefeeds:

Check out the code yourself: github.com/mglukhovsky/realtime-questions

Page 21: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Example: realtime questions

Questions server Questions server Dashboard server

RethinkDB cluster

Changes are pushed to each stateless app server.

Page 22: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Advancing the realtime web

The push access model simplifies realtime architecture.

One source of truth makes it easy to manage state.

RethinkDB is the first database for the realtime web.

Polling for data is slow, cumbersome, hard to maintain.

Page 23: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB
Page 24: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

A realtime, open-source backend for JavaScript apps

Page 25: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Horizon makes it easy to quickly prototype your web and mobile app, and then scale it to millions of users.

Page 26: Database Camp 2016 @ United Nations, NYC - Michael Glukhovsky, Co-Founder, RethinkDB

Learn more about RethinkDB

Get started: rethinkdb.com/install

Read the docs: rethinkdb.com/docs

Follow on Twitter: @rethinkdb