Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to RethinkDB : Hack Reactor
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Jorge Silva
June 05, 2015
Programming
430
4
Share
Introduction to RethinkDB : Hack Reactor
Jorge Silva
June 05, 2015
More Decks by Jorge Silva
See All by Jorge Silva
Introduction to RethinkDB : Move fast and break things
thejsj
2
290
ForwardJS - RethinkDB - Getting Started
thejsj
0
230
ForwardJS - RethinkDB - Advanced Queries
thejsj
1
230
Automatic Failover in RethinkDB
thejsj
0
260
Workshop: Introduction to RethinkDB : Santa Cruz JS
thejsj
1
150
Push databases: A better way to build realtime apps
thejsj
0
150
Data Modeling in RethinkDB
thejsj
4
290
RethinkDB+Angular.js: Building realtime web applications
thejsj
10
30k
Introduction to RethinkDB: 1KE Meetup
thejsj
0
75
Other Decks in Programming
See All in Programming
第3木曜LT会 #28
tinykitten
PRO
0
100
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
3
310
JAWS-UG横浜 #100 祝・第100回スペシャルAWS は VPC レスの時代へ
maroon1st
0
130
Running Swift without an OS
kishikawakatsumi
0
830
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
170
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
450
Radical Imagining - LIFT 2025-2027 Policy Agenda
lift1998
0
310
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
130
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
210
Google Nest CamとApple Vision frameworkと猫🐈🐈⬛ / onishi50
yutailang0119
0
110
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.5k
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
260
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
520
Building AI with AI
inesmontani
PRO
1
900
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
890
30 Presentation Tips
portentint
PRO
1
270
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
320
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
520
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.9k
KATA
mclloyd
PRO
35
15k
Code Review Best Practice
trishagee
74
20k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
110
Transcript
RethinkDB The database for the realtime web Hack Reactor San
Francisco, CA June 4, 2015
Jorge Silva @thejsj Developer Evangelist @ RethinkDB
Introduction What is RethinkDB?
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
Built for Realtime Apps • Subscribe to change notifications from
database queries • No more polling — the database pushes changes to your app • Reduce the amount of plumbing needed to stream live updates
RethinkDB Structure Database → Table → Document MySQL: Database →
Table → Row MongoDB: Database → Collection → Document
Sample Document { "name": "Will Riker", "position": "Commander", "height": 193,
"birthdate": Mon Aug 19 2335, "ships": [ { "name": "USS Pegasus" }, { "name": "USS Potemkin" }, { "name": "USS Enterprise" }, ], ... }
Differences with Firebase • Firebase is a cloud service, not
an open-source database • Because Firebase is not a database, it has limited querying abilities • Firebase is made to be queried from the browser
Differences with MongoDB • RethinkDB supports joins and subqueries •
MongoDB has a traditional query- response model. You can't subscribe to queries.
Introduction to ReQL RethinkDB Query Language
Introduction to ReQL • ReQL embeds natively into your programming
language • Compose ReQL queries by chaining commands
Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Number of
unique last names
Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Access a
database table
Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Isolate a
document property
Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Consolidate duplicate
values
Anatomy of a ReQL Query r.table("users") .pluck("last_name") .distinct().count() Display the
number of items
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"})
ReQL Commands • 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
Running Queries http://github.com/thejsj/rethinkdb-quickstart
http://rethinkdb-chat.thejsj.com:10001/ Running Queries
Understanding ReQL • Client driver translates ReQL queries into wire
protocol • Anonymous function must return a valid ReQL expression • In JS use e.g. the mul and gt commands instead of the normal operators
Additional ReQL Features • Geospatial indexing for location- based queries
• Date and time functions for time data • Support for storing binary objects • Execute http requests using r.http
Realtime Updates Working with Changefeeds
Subscribe to change notifications on database queries Changefeeds
r.table("users").changes() Track changes on the users table Changefeeds
Changefeeds • The changes command returns a cursor that receives
updates • Each update includes the new and old value of the modified record
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 }
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', ... } }
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' } }
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:
Changefeeds r.table("table").get(ID).changes() r.table("table").getAll(ID).changes() r.table("table").between(X, Y).changes() r.table("table").filter(CONDITION).changes() r.table("table").union(ID).changes() r.table("table").map(FUNCTION).changes() r.table("table").min(INDEX).changes() r.table("table").max(INDEX).changes()
r.table("table").orderBy(INDEX) .limit(N).changes() Commands that currently work with changefeeds:
Using Changefeeds http://github.com/thejsj/rethinkdb-quickstart
http://realtime-photo.thejsj.com/ Sample Application
Cluster Configuration Sharding and replication
Sharding and Replication • RethinkDB is designed for clustering and
easy scalability • To add a new server to the cluster, just launch it with the join option • Configure sharding and replication per table • Any feature that works with a single database will work in a sharded cluster
Add a Server to a Cluster $ rethinkdb --join server:29015
>
Clustering
Additional Resources • RethinkDB website: http://rethinkdb.com • RethinkDB cookbook: http://rethinkdb.com/docs/cookbook
• RethinkDB installation: http://rethinkdb.com/docs/install/
Questions?