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

Realtime Apps with RethinkDB and Socket.io

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Chris Atkins Chris Atkins
November 18, 2015

Realtime Apps with RethinkDB and Socket.io

Talk at Melbourne NodeJS Meetup. Wednesday 18th November, 2015.

Avatar for Chris Atkins

Chris Atkins

November 18, 2015
Tweet

Other Decks in Programming

Transcript

  1. WHO’S THIS GUY ANYWAY? BY DAY ▸ Senior Software Engineer

    at Zendesk ▸ Writes of lots of Ruby and Javascript ▸ Lots of contemplative beard stroking + 3 +
  2. WHO’S THIS GUY ANYWAY? BY NIGHT ▸ Kendama Enthusiast ▸

    Dreamer of Stilton ▸ Reddit induced insomniac ▸ Lover of noisey guitars 4
  3. REALTIME APPS EXAMPLES OF REALTIME APPS ▸ Collaboration tools ▸

    Google Docs ▸ Google Wave ▸ Trello ▸ Communication Tools ▸ Slack ▸ Facebook Chat ▸ Twitter ▸ Games 6
  4. REALTIME APPS TWO MAIN ISSUES ▸ Persistence ▸ How do

    I know when data has changed? ▸ Transport ▸ How do I send updates to to my users? 7
  5. REALTIME APPS SOLUTIONS IN THE SPACE ▸ End to end

    – persistence + transport ▸ Meteor ▸ Firebase ▸ Hosted Messaging platforms ▸ Pusher ▸ Pubnub 8 ▸ Server push libraries ▸ Socket.io (NodeJS) ▸ SockJS ▸ SignalR (.NET) ▸ Faye (Ruby + Node) ▸ Ratchet (PHP) ▸ Traditional push solutions ▸ Ajax Polling ▸ Comet / Long polling ▸ HTML5 Server Sent Events (SSE) / EventSource
  6. REALTIME APPS PERSISTENCE ▸ ActiveRecord callbacks (Rails) ▸ As CRUD

    actions occur in your app publish updates ▸ Very manual + error prone ▸ Tightly couples your models with other app concerns ▸ “[ActiveRecord] callbacks are the devil” – Sam Mullen 9
  7. REALTIME APPS PERSISTENCE ▸ MongoDB ▸ Polling ▸ Oplog tailing

    ▸ Mainly for replication on sharded clusters ▸ Also used by Meteor ▸ Have to decide in the application layer what to send to who 10
  8. 11

  9. SOCKET.IO FEATURES ▸ Client + Server Libraries ▸ Easy to

    install via npm ▸ Abstracts away transport via engine.io ▸ Falls back to polling on older browsers without WebSocket supply ▸ Namespaces / Rooms ▸ Broadcasting ▸ Distributed via socket.io-redis ▸ ~2 million downloads a month 12
  10. RETHINKDB FEATURES ▸ JSON database ▸ Changefeeds ▸ Clustered ▸

    ReQL ▸ Automatically parallelised queries ▸ Slick Administration Console http://localhost:8080 ▸ Official drivers for Python, Ruby + NodeJS ▸ Distributed Joins ▸ Map/Reduce ▸ Geospatial indicies 14
  11. RETHINKDB HISTORY ▸ 2009 ▸ Started as MySQL storage engine

    designed to take advantage of SSDs ▸ YCombinator backed ▸ Append-only design, similar to ideas to Datomic ▸ November 2012 (1.2) ▸ First open source release, transformed into a JSON Database ▸ June 2014 (1.13) ▸ Changefeeds introduced ▸ April 2015 (2.0) ▸ Declared Production Ready ▸ August 2015 (2.1) ▸ High Availablity ▸ Automatic Failover 15
  12. RETHINKDB DOWNSIDES ▸ Not sure yet ▸ No unique constraints

    on secondary indicies ▸ Some limitations on change feeds ▸ Tricky to secure – need SSH tunnels to db servers 16
  13. CLICKSQUAD BASIC GAME IDEA ▸ Teams compete in real time

    to click on a big blue button the most times ▸ Live leaderboard ▸ Yep. ▸ I’ll see y’all next year for my keynote at PAX 18
  14. CLICKSQUAD TOOLS USED ▸ RethinkDB + Socket.io (unsurprisingly) ▸ Express

    ▸ Node v4.2.2 ▸ Webpack ▸ React ▸ Rethinkdbdash (alternate driver) 19