Slide 1

Slide 1 text

as the upcoming NoSQL Champion Shai Mishali me@freak4pc.com

Slide 2

Slide 2 text

Shai Mishali All-around geek. Mobile to Web to Backend. Constantly messing with new & weird technologies Winner of: BattleHack TLV 2014 BattleHack World Finals 2014 Ford TLV Developer Challenge 2015 freak4pc Shai Mishali

Slide 3

Slide 3 text

Introduction What is RethinkDB?

Slide 4

Slide 4 text

What is RethinkDB? • Open Source database for building realtime web-backed applications • NoSQL database that stores its data as Schemaless JSON documents • Distributed database that is super-easy to scale

Slide 5

Slide 5 text

Built for Realtime Apps • RethinkDB works on an exciting new access model based on pushing changes to the client instead of polling. • Subscribe to change notifications on most ReQL queries • Reduce the amount of overhead and maintenance needed to stream live updates to your app • Suitable for many realtime applications such as: Collaborative web and mobile apps, Streaming analytics apps, Multiplayer games, Realtime marketplaces, Connected devices and much more…

Slide 6

Slide 6 text

Difference from Realtime APIs RethinkDB is fundamentally different from realtime sync APIs such as Firebase, PubNub, or Pusher in the following important ways: Traditional Realtime APIs RethinkDB Service Type Managed Cloud Services Completely open source Realtime Synced Data Documents Only Results of most ReQL Queries Designed to be accessed from Mainly Browser Application Servers, as any traditional DB

Slide 7

Slide 7 text

Powerful and Modern • Highly expressive, modern and “familiar” query language (very javascript-y syntax) • Relational features such as table joins (even across cluster) • Powerful Admin UI to easily manage clusters, tables, data, indexes and more

Slide 8

Slide 8 text

What is RethinkDB?

Slide 9

Slide 9 text

Introduction to ReQL RethinkDB Query Language

Slide 10

Slide 10 text

Introduction to ReQL • ReQL has a great native-feel, especially for Javascript developers • ReQL queries are extremely Powerful and Chainable • ReQL queries are executed on the server only after being built on the client which make them extremely efficient • ReQL Queries are executed lazily based on the data you need to read • Automatically Parallelized across CPU cores, servers in the
 cluster and even multiple datacenters

Slide 11

Slide 11 text

Sample ReQL Queries Get all Users: r.table("users") Get all Users named Shai: r.table("users") .filter({firstName: "Shai"}) Get the count of all distinct last names: r.table("users") .pluck("lastName") .distinct() .count() Set underaged to true for all users under 18 r.table("users") .filter(r.row("age").lt(18)) .update({underaged: true})

Slide 12

Slide 12 text

Anatomy of a ReQL Query r.table("users") .filter(r.row("age").lt(18)) .update({underaged: true}) Update the field underaged to true for users younger than 18 years

Slide 13

Slide 13 text

Anatomy of a ReQL Query r.table("users") .filter(r.row("age").lt(18)) .update({underaged: true}) Access a database table

Slide 14

Slide 14 text

Anatomy of a ReQL Query r.table("users") .filter(r.row("age").lt(18)) .update({underaged: true}) Filter users who’s age is less than 18

Slide 15

Slide 15 text

Anatomy of a ReQL Query r.table("users") .filter(r.row("age").lt(18)) .update({underaged: true}) Update the field underaged to true for the selected results

Slide 16

Slide 16 text

Some ReQL Commands • Transformations: map, orderBy, skip, limit, slice, nth, union, sample • Aggregation: group, reduce, count, sum, avg, min, max, distinct,contains • Documents: get, getAll, between, filter, row, pluck, without, merge, difference, insertAt, spliceAt, deleteAt, changeAt, hasFields, keys • Writing: insert, update, replace, delete, sync • Tables/Indices: tableCreate, tableDrop, tableList, indexCreate, indexDrop, indexList • Math & Logic: add, sub, mul, div, mod, and, or, eq, ne, gt, ge, lt, le, not, random, round, ceil, floor

Slide 17

Slide 17 text

Demo Time Admin UI & Basic ReQL

Slide 18

Slide 18 text

Introduction to ReQL

Slide 19

Slide 19 text

Dive into ReQL More ReQL Goodies

Slide 20

Slide 20 text

Secondary Indexes Queries performed against indexes are much faster. In RethinkDB We can use the following index types: • Simple Indexes - Index a single property • Compound Indexes - Index multiple fields as an array • Multi Indexes - Index using more than one key for the same index. e.g. a blog post with multiple tags, of which each can refer to multiple blog posts

Slide 21

Slide 21 text

Simple Indexes Create a new index for gender: r.table("users") .indexCreate("gender") Find all male users: r.table("users") .getAll("m", {index: "gender"})

Slide 22

Slide 22 text

Compound Indexes Create a new index for full name joining first and last name: r.table("users") .indexCreate("fullName", [r.row("firstName"), r.row("lastName")]) Find user named Shai Mishali: r.table("users").getAll(["Shai", "Mishali"], {index: "fullName"})

Slide 23

Slide 23 text

r.row command r.row represents the current row being processed, and is sent as an argument to all ReQL anonymous functions. Sometimes, we could use r.row instead of an anonymous function. Let’s return all users under the age of 30: r.table("users") .filter(function(row){ return row("age").lt(30) }) Anonymous function: r.table("users") .filter(r.row("age").lt(30)) r.row only: Anonymous Functions Anonymous functions are a powerful tool that can be used with many ReQL Methods, such as filter, map and reduce.

Slide 24

Slide 24 text

Joins RethinkDB is one of the only NoSQL database that supports true server-side distributed table joins. RethinkDB Offers 3 types of joins : Inner Join, Outer Join, and Equal Join

Slide 25

Slide 25 text

Equal Join Equal join is the most efficient of all joins. It joins two tables using a field on the left table that matches the primary/secondary keys of the right table r.table("orders") .eqJoin(“productID",r.table("products")) Join order details with details of the product

Slide 26

Slide 26 text

More Cool ReQL Features • Geospatial Queries & Indexes • Support for storing Binary Objects • Date and Time functions for simple and complex handling of time and date queries • Inline conditioning using branch • Grouping and ungrouping query data

Slide 27

Slide 27 text

Dive into ReQL

Slide 28

Slide 28 text

Demo Time Advanced ReQL & Joins

Slide 29

Slide 29 text

Realtime Bliss with RethinkDB Changefeeds

Slide 30

Slide 30 text

Changefeeds So what do we do? r.table(“messages”).changes() That’s it! Just add changes() ! So - let’s say we have a user table, and we want to get live change updates from it. r.table("messages")

Slide 31

Slide 31 text

Changefeeds

Slide 32

Slide 32 text

Changefeeds • The changes command returns a cursor that receives record/query updates • Each update includes the new and old value of the modified record • Can be used to track changes on a Table, a Single Document or even ReQL Queries as they happen

Slide 33

Slide 33 text

Changefeeds r.table("users") .filter({firstName: "Shai"}) .delete() And then Deleting a user: Results in the following changefeed: { new_val: null, old_val: { id: "72de71e6-965a-477e-b115-64887725cca2", firstName: "Shai", ... } } Subscribing to users changes: r.table(“users”).changes()

Slide 34

Slide 34 text

Changefeeds We can actually chain changes() to a ton of ReQL commands / queries and get change updates for those expressions, which becomes extremely useful. r.table("users") .orderBy({index: r.desc("age")}) .limit(3) .changes() Get a change feed for the 3 oldest users

Slide 35

Slide 35 text

Changefeeds changes() can be chained after most commands that transform or select data: r.table("table").get(ID).changes() r.table("table").getAll(KEY).changes() r.table("table").filter(CONDITION).changes() r.table("table").map(FN).changes() r.table("table").pluck(SELECTOR).changes() r.table("table").between(X, Y).changes() r.table("table").union(SEQUENCE).changes() r.table("table").min(INDEX).changes() r.table("table").max(INDEX).changes() r.table(“table").orderBy(CONDITION) .limit(N).changes()

Slide 36

Slide 36 text

Changefeeds

Slide 37

Slide 37 text

Demo Time Changefeeds

Slide 38

Slide 38 text

“Horizon is an open-source developer platform for building sophisticated realtime apps. It provides a complete backend that makes it dramatically simpler to build, deploy, manage, and scale engaging JavaScript web and mobile apps. Horizon is extensible, integrates with the Node.js stack, and allows building modern, arbitrarily complex applications.” https://github.com/rethinkdb/horizon

Slide 39

Slide 39 text

Scaling up! Clusters, Sharding and Replication

Slide 40

Slide 40 text

Sharding and Replication • RethinkDB is designed for clustering and super-easy scalability • Adding a new server to the cluster is as easy as launching it with the --join flag • Sharding and Replication can be configured on a per-table basis • Seamless integration: Any feature that works with a single database will work in a sharded cluster

Slide 41

Slide 41 text

Add a Server to a Cluster $ rethinkdb --join server:29015 New instance asks to join the main server
 on it’s intracluster port (29015 by default)

Slide 42

Slide 42 text

Cluster Configuration • Interactively configure your cluster using the Admin Web UI • Programmatically configure your cluster with simple ReQL Commands such as config and reconfigure. • Fine-grained cluster control via full ReQL access to system tables • Automatic Failover - Added in RethinkDB 2.1

Slide 43

Slide 43 text

Demo Time Sharding and Replication

Slide 44

Slide 44 text

Platform Support Drivers

Slide 45

Slide 45 text

Drivers RethinkDB has drivers to support most modern clients, either written by RethinkDB or supported by the community Official Drivers: Javascript, Ruby, Python, Java Community-supported drivers: C#/.NET, C++, Clojure, Common Lisp, Dart, Delphi, Elixir, Erlang, Go, Haskell, Lua, Node.js, Nim, Perl, PHP, Scala

Slide 46

Slide 46 text

Want to learn more? Get started with RethinkDB

Slide 47

Slide 47 text

Where to Next? RethinkDB website:
 http://rethinkdb.com RethinkDB Docs & QuickStart:
 http://rethinkdb.com/docs/ RethinkDB on Slack:
 http://rethinkdb.slack.com/ RethinkDB Cookbook:
 http://rethinkdb.com/docs/cookbook/ SQL to ReQL Cheatsheet:
 http://rethinkdb.com/docs/sql-to-reql/javascript/

Slide 48

Slide 48 text

Thank You! Feel free to contact me with questions: Shai Mishali me@freak4pc.com freak4pc on