SlideShare a Scribd company logo
Updating Ember
in Real-time
CLASS DISCUSSION UI
THE PROBLEM WITH CLASS DISCUSSION
• Everything should be real-time… eventually
• Connect to a live events socket
• Receive a mixed feed of all subscribed events
• Manually register for chat channels
• Forced disconnection every minute
Going Real-time
SERVICE CONSTRAINTS
First Attempt
• Staying connected to a unpredictable service
• Updating with messages sent while disconnected
• Maintaining state on live chat channels
• Logic for all event types lived in one service
• Slowly building an app-wide state machine
It Worked! But…
KEY ISSUES
RxJSA complicated solution to a complicated problem!
RxJSA complicated solution to a complicated problem!
“[…] transforms an observable sequence of
observable sequences into an observable
sequence producing values only from the
most recent observable sequence.”
🤔
It’s Not as Bad as You Think™
RxJS
• Observers
• Events
• Bindings
• Array functions
• Promises
RxJS
IT’S MOSTLY STUFF YOU ALREADY KNOW
Staying Connected to a
Unpredictable Service
STAYING CONNECTED TO A UNPREDICTABLE SERVICE
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
http://rxmarbles.com/#zip
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
STAYING CONNECTED TO A UNPREDICTABLE SERVICE WITH RX
ANYONE FEELING LIKE THIS?
Me too! Let’s keep going!
Actually Updating a Model
ACTUALLY UPDATING A MODEL
ACTUALLY UPDATING A MODEL
ACTUALLY UPDATING A MODEL
ACTUALLY UPDATING A MODEL
MAINTAINING STATE ON LIVE CHAT CHANNELS

More Related Content

What's hot

An Introduction to Reactive Application, Reactive Streams, and options for JVM
An Introduction to Reactive Application, Reactive Streams, and options for JVMAn Introduction to Reactive Application, Reactive Streams, and options for JVM
An Introduction to Reactive Application, Reactive Streams, and options for JVM
Steve Pember
 

What's hot (17)

NLUUG print conference May 26 2016
NLUUG print conference May 26 2016NLUUG print conference May 26 2016
NLUUG print conference May 26 2016
 
Kubernetes and elixir
Kubernetes and elixirKubernetes and elixir
Kubernetes and elixir
 
Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...
Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...
Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...
 
Infinum Android Talks #05 - Square tape
Infinum Android Talks #05 - Square tapeInfinum Android Talks #05 - Square tape
Infinum Android Talks #05 - Square tape
 
Scaling a Facebook Application
Scaling a Facebook ApplicationScaling a Facebook Application
Scaling a Facebook Application
 
Innovation in the Cloud - Rackspace Zurich Event
Innovation in the Cloud - Rackspace Zurich EventInnovation in the Cloud - Rackspace Zurich Event
Innovation in the Cloud - Rackspace Zurich Event
 
What's new in FME 2019: FME Server
What's new in FME 2019: FME ServerWhat's new in FME 2019: FME Server
What's new in FME 2019: FME Server
 
An Introduction to Reactive Application, Reactive Streams, and options for JVM
An Introduction to Reactive Application, Reactive Streams, and options for JVMAn Introduction to Reactive Application, Reactive Streams, and options for JVM
An Introduction to Reactive Application, Reactive Streams, and options for JVM
 
From Ruby to Elixir
From Ruby to ElixirFrom Ruby to Elixir
From Ruby to Elixir
 
What's new in FME 2019: FME Desktop
What's new in FME 2019: FME DesktopWhat's new in FME 2019: FME Desktop
What's new in FME 2019: FME Desktop
 
My works-lan1
My works-lan1My works-lan1
My works-lan1
 
Site reliability in the serverless age - Serverless Boston Meetup
Site reliability in the serverless age  - Serverless Boston MeetupSite reliability in the serverless age  - Serverless Boston Meetup
Site reliability in the serverless age - Serverless Boston Meetup
 
Real-time Data Integration with Kafka and Cassandra (Ewen Cheslack-Postava, C...
Real-time Data Integration with Kafka and Cassandra (Ewen Cheslack-Postava, C...Real-time Data Integration with Kafka and Cassandra (Ewen Cheslack-Postava, C...
Real-time Data Integration with Kafka and Cassandra (Ewen Cheslack-Postava, C...
 
Keep your projects up-to-date
Keep your projects up-to-dateKeep your projects up-to-date
Keep your projects up-to-date
 
What we learned from the AWS Outage
What we learned from the AWS OutageWhat we learned from the AWS Outage
What we learned from the AWS Outage
 
Reactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of GroovyReactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of Groovy
 
In the hunt of 100% delivery rate with mobile push notifications
In the hunt of 100% delivery rate with mobile push notificationsIn the hunt of 100% delivery rate with mobile push notifications
In the hunt of 100% delivery rate with mobile push notifications
 

Viewers also liked (12)

Hassan Elaref CV 3
Hassan Elaref CV 3Hassan Elaref CV 3
Hassan Elaref CV 3
 
Vardhan Electrical_resume (2)
Vardhan Electrical_resume (2)Vardhan Electrical_resume (2)
Vardhan Electrical_resume (2)
 
SAP_Book os Simple - SAP per il Retail
SAP_Book os Simple - SAP per il RetailSAP_Book os Simple - SAP per il Retail
SAP_Book os Simple - SAP per il Retail
 
ktiria smek_tx49
ktiria smek_tx49ktiria smek_tx49
ktiria smek_tx49
 
Foco e disciplina personaldosucesso
Foco e disciplina personaldosucessoFoco e disciplina personaldosucesso
Foco e disciplina personaldosucesso
 
6 a josefcarstens_slide presentation
6 a josefcarstens_slide presentation6 a josefcarstens_slide presentation
6 a josefcarstens_slide presentation
 
Introduccion a la computacion en la nube
Introduccion a la computacion en la nubeIntroduccion a la computacion en la nube
Introduccion a la computacion en la nube
 
GabrielaGutierrez
GabrielaGutierrezGabrielaGutierrez
GabrielaGutierrez
 
Love marriage problem solution
Love marriage problem solutionLove marriage problem solution
Love marriage problem solution
 
My new resume
My new resumeMy new resume
My new resume
 
C.V & PHOTO
C.V & PHOTOC.V & PHOTO
C.V & PHOTO
 
Concepto de deportes extremos
Concepto de deportes extremos Concepto de deportes extremos
Concepto de deportes extremos
 

Similar to Updating Ember Models in Real-time with Sockets and Rx

Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPCRestate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
HostedbyConfluent
 
Erlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to ThroughputErlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to Throughput
Wooga
 

Similar to Updating Ember Models in Real-time with Sockets and Rx (17)

Micro services and Containers
Micro services and ContainersMicro services and Containers
Micro services and Containers
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 
Building a [micro]services platform on AWS
Building a [micro]services platform on AWSBuilding a [micro]services platform on AWS
Building a [micro]services platform on AWS
 
Events in a microservices architecture
Events in a microservices architectureEvents in a microservices architecture
Events in a microservices architecture
 
Coolblue Behind the Scenes | Pat Hermens - On the shoulders of giants.
Coolblue Behind the Scenes | Pat Hermens - On the shoulders of giants.Coolblue Behind the Scenes | Pat Hermens - On the shoulders of giants.
Coolblue Behind the Scenes | Pat Hermens - On the shoulders of giants.
 
Iot cloud service v2.0
Iot cloud service v2.0Iot cloud service v2.0
Iot cloud service v2.0
 
Scaling
ScalingScaling
Scaling
 
Introduction to Realm Mobile Platform
Introduction to Realm Mobile PlatformIntroduction to Realm Mobile Platform
Introduction to Realm Mobile Platform
 
Adventures with Microservices
Adventures with MicroservicesAdventures with Microservices
Adventures with Microservices
 
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPCRestate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
 
Micro Services Architecture
Micro Services ArchitectureMicro Services Architecture
Micro Services Architecture
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event Architectures
 
Microservices Design and Best Practices on AWS
Microservices Design and Best Practices on AWSMicroservices Design and Best Practices on AWS
Microservices Design and Best Practices on AWS
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughput
 
Erlang as a Cloud Citizen
Erlang as a Cloud CitizenErlang as a Cloud Citizen
Erlang as a Cloud Citizen
 
Erlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to ThroughputErlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to Throughput
 

Recently uploaded

527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf
rajpreetkaur75080
 

Recently uploaded (15)

Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...
Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...
Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...
 
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
 
05232024 Joint Meeting - Community Networking
05232024 Joint Meeting - Community Networking05232024 Joint Meeting - Community Networking
05232024 Joint Meeting - Community Networking
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 
123445566544333222333444dxcvbcvcvharsh.pptx
123445566544333222333444dxcvbcvcvharsh.pptx123445566544333222333444dxcvbcvcvharsh.pptx
123445566544333222333444dxcvbcvcvharsh.pptx
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 
Oracle Database Administration I (1Z0-082) Exam Dumps 2024.pdf
Oracle Database Administration I (1Z0-082) Exam Dumps 2024.pdfOracle Database Administration I (1Z0-082) Exam Dumps 2024.pdf
Oracle Database Administration I (1Z0-082) Exam Dumps 2024.pdf
 
527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
Hi-Tech Industry 2024-25 Prospective.pptx
Hi-Tech Industry 2024-25 Prospective.pptxHi-Tech Industry 2024-25 Prospective.pptx
Hi-Tech Industry 2024-25 Prospective.pptx
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 
The Canoga Gardens Development Project. PDF
The Canoga Gardens Development Project. PDFThe Canoga Gardens Development Project. PDF
The Canoga Gardens Development Project. PDF
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 

Updating Ember Models in Real-time with Sockets and Rx

Editor's Notes

  1. Hi everyone, I’m going to give a quick talk today on how Showbie is handling real-time updates in our Ember app
  2. Showbie is an app for teachers in 1:1 classrooms — where every student has a device. We make it easy to share files, add written or audio annotations, grade, and a bunch of other neat stuff. Showbie is a _very old_ Ember app — we started with version 1.6, but our team has worked really hard to keep it up-to-date (mostly…). It’s built exactly as you’d expect, using Ember Data to connect to our service and retrieve data as users navigate through routes.
  3. Recently we added two great new features: group chat, and class discussions! And suddenly, we had a problem… can anyone guess what it is?
  4. It’s that refresh button. Do you know what is _no fun_? Clicking to refresh the feed in a “live” chat. It is a terrible user experience (that we totally launched with)
  5. So clearly, we had the need to go real-time, and that effort was driven by our hard-working and talented, service team! Unfortunately, they had some requirements that made this “not that easy”.
  6. We set out and built a proof-of-concept using Ember Concurrency… but it was quite a bit of work
  7. Ideally, it would be impossible to register for multiple groups… managing subscriptions to groups would have to be handled manually… tied tightly to entering and exiting groups → difficult to enforce single-group subscription difficult to extend + add handlers for different events So we ended up coming to a somewhat surprising solution…
  8. Yeah! We had a hard problem, so we threw an impossibly complicated library at it! Has anyone here ever read up on RxJS? If not, you’re missing out on sweet, helpful stuff like this:
  9. Yeah, I swear that makes sense.
  10. Anyways, Rx has some quasi-impenetrable documentation, but once you start getting a feel for it, you realize that it’s not _too_ different from the concepts we already know from working with Ember.
  11. So Rx has “Observers”, but instead of watching for property changes, they’re a lot more generic. Observers just watch for Events, and emit them in streams. In Rx, _basically everything_ is either a stream of events, or a subscriber to an event stream. The great thing about Rx Observers, is that the API feel really similar to Array operation. It lets you write code that feels synchronous, even though it really, really isn’t. So let’s take a quick look at the problems we faced, and how we solved them with Rx
  12. So as we discussed, our service hates us, and likes to do fun things like disconnect us without letting us know every minute.
  13. Let’s take a quick look at how we handled this with Ember… we created a firehose service to connect to the socket and fire off events… and handle all of the reconnection logic dictated by our service team.
  14. And now let’s take a look with Rx. I know this is dense, but it’s not _too_ scary! It’s functionally the same as the previous example, but it’s a lot more concise. Let’s walk through it step by step.
  15. We start by creating an Observable, which I prefer to call a “stream”. This will connect to our web socket, and start receiving service events. Every time our service emits an Event, this Observable will forward it on to all of its subscribers. (We’ll get to subscribers in a little bit)
  16. Now, if an error happens with our websocket connection, `retryWhen` will be called with a single parameter, which is an Observable stream of errors What `retryWhen` needs back is an Event telling it to try to connect again… so let’s figure out how to get it one!
  17. Here, we do a neat thing. The `zip` method combines streams sequentially. So we’ll combine our error stream with a numeric range 0–10…
  18. If you take a look at this marble image from rxmarbles.com it helps illustrate what’s happening here… you can see how an event has to fire from each stream before it’s propagated. Also note that “3” and “C” are matched, even though “D” fires before “3”.
  19. So back to the code: the first time an error occurs, it will be matched with the first number from our range (0), the second time an error occurs, it will be combined with the second number from our range (1) and on and on until 10 The last argument is a function. When the last argument to is a function, `zip` will emit a value from the combined streams. In this case, we’re using it to count how many times an error has occurred trying to connect to the websocket
  20. Now we can chain on the `zip` with a `flatMap`. The `flatMap` lets us transform the values from `zip` back into a stream. In this case, we use that value to create a timer that emits the event, which will kick off `retryWhen`!
  21. This is really the short, short, short version, so sorry if I’m rushing a little… but let’s keep going!
  22. We’ve established what it takes to connect (and stay connected) to the live events service, now let’s move on to actually updating a model
  23. Let’s add a method to our firehose service. Well take the stream we set up earlier, and extending to make a stream just for our group chats… that multiplex stuff is _super neat_. The first param is set to the service when we connect (registering a group for messages), the second when we disconnect (unregistering a group from messages), and the third is used to filter the incoming events (ensuring only messages for our group are sent). It a single call we manage to knock off a whole bunch of service requirements!
  24. We have a `LiveRoute` mixin, that handles building and disposing our live event stream on `setupController` and `resetController`. It requires us to define a `setupFirehose` method. That’s where we subscribe to the stream. So that method is going to get called with every single event sent by the service. And what does that data look like?
  25. BOOM! A big, gross pile of JSON
  26. But we only really care about these bits… So `event` tells us what the service wants us to do… That data looks an _awful lot_ like the data that would be returned by a GET request to our endpoint…
  27. So now let’s go back to our route, and actually handle that data! Subscribe needs a method that’s going to handle that data.
  28. So we create a Object we call a reducer, pass it the store, then send it all of our live events. The reducers job is to take the all of the events, and proxy them to the proper method call.
  29. And the reducer is really simple! It checks for a method that matches the provided event name, and if it exists, passes it the data and the store! So did you follow all of that?