Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to RethinkDB : Move fast and break...

Introduction to RethinkDB : Move fast and break things

Jorge Silva

August 06, 2015
Tweet

More Decks by Jorge Silva

Other Decks in Programming

Transcript

  1. Push databases, RethinkDB, and building realtime apps Move Fast and

    Break Things San Francisco, CA August 5, 2015
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. Push Database RethinkDB is an excellent database for: • Collaborative

    web and mobile apps • Multiplayer games • Streaming analytics apps • Connected devices
  9. Introduction to ReQL • ReQL embeds natively into your programming

    language • Compose ReQL queries by chaining commands
  10. Additional ReQL Features • Geospatial indexing for location- based queries

    • Date and time functions • Support for storing binary objects • Execute http requests using r.http
  11. Changefeeds • The changes command returns a cursor that receives

    updates • Each update includes the new and old value of the modified record
  12. 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 }
  13. 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' } }
  14. 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