name: dblue class: bg-dark-blue, center, middle layout: true
@leggetter
name: pink layout: true
class: bg-pink, center, middle
@leggetter
name: green class: green-template, center, middle layout: true
@leggetter
name: lblue layout: true class: bg-light, center, middle
@leggetter
name: white layout: true class: bg-white, center, middle, black-text
@leggetter
template: lblue class: title
- Phil @leggetter
- Head of Developer Relations
???
class: bg-contain background-image: url(./img/trader2.png)
class: bg-contain background-image: url(./img/pusher-white-cloud.png)
template: white class: top black-text
- Why Real-Time? --
background-image: url(https://docs.google.com/drawings/d/1DxIqk4b1LhBadH_O277Vr3wHEBOD8ERZPuO7WNqaFKM/pub?w=1195&h=721)
- Tools, Tips & Techniques
???
- Firstly, apps don't have to have a UI
- Even so, if you are interested in UI considerations then there are lots of great resources on this from browser and mobile vendors.
template: dblue class: bg-dark-blue, h1-big
???
- Here are some examples of apps...
template: dblue class: em-text, bg-cover, trans-h, bottom background-image: url(./img/itv-news-may-2014.png)
???
- Something has happened
- Changed
- Alert - do something
class: bg-cover, em-text, trans-h, bottom background-image: url(./img/delighted-app.gif)
???
- a stream of activity
- things have - and are - happening
- synonymous with social apps
- Google+
- News
- Sports
template: dblue
class: bg-cover, em-text, trans-h, bg-white, bottom background-image: url(./img/senate-election-results.png)
template: lblue class: bg-video, bg-cover, trans-h, em-text, bottom
???
- The 101 of realtime
- An interactive experience
- Real-time matters
class: bg-white background-image: url(./img/messaging-apps.png)
template: dblue class: trans-h, bg-cover, bottom background-image: url(./img/uber.jpg)
template: lblue class: trans-h, bottom background-image: url(./img/atom-pair.gif)
???
- Google Apps
- Cloud 9
- TODO: other
template: lblue class: bg-cover, trans-h, bg-white background-image: url(./img/lunar-landing.png)
background-image: url(./img/robot-door-fail.gif) class: trans-h bottom bg-cover
template: pink class: top
--
--
template: dblue class: h1-big
class: bg-white top black-text background-image: url(https://docs.google.com/drawings/d/1_78n6-fvY8-iacXDtzfRlz0d-m57Ahz6P2DoKkJs_K4/pub?w=1195&h=721)
???
Whilst there's not one true anantomy for a real-time application the majorify of these applications consist of sources of data, maybe from database or 3rd party APIs, one or more applications servers glue all other components together, a real-time framework to deal with your real-time data delivery and functionality, and clients that interact with the real-time framework, and potentially the application server.
template: dblue class: h1-big
template: pink class: fixed-width-list top
--
Any event in your web stack...
- Incoming Data
- Data Changes
- System Interactions
- User Interactions
... represents real-time data.
???
class: bg-white background-image: url(https://docs.google.com/drawings/d/1dL5nNi8l_tjGSKXPCrCfKljMOUmeC8HKU81LrY1x0wU/pub?w=1195&h=721)
???
Other systems that ultimately interact with with your application server. Databases, message queues, 3rd party services and anything that interacts with web endpoints that your application server exposes.
class: bg-white background-image: url(https://docs.google.com/drawings/d/18g94RT1gHtORhiqTZon8j9U_TFtvto0SJJ9SfYejG6g/pub?w=1195&h=721)
???
This is open for debate.
But generally, the application server won't be the source of the real-time data - the real-time events. But it will be the organ within your living breathing real-time system that orchestrates the dataflow between the components.
class: bg-white background-image: url(https://docs.google.com/drawings/d/15fczP5XSDf2uhK43TPgTNYnO2vJDcqFwFwREvgytmUQ/pub?w=1195&h=721)
???
Your real-time framework is all about real-time data.
- It handles incoming and outgoing data.
- e.g. connections, subscriptions to data, data synchronisation events, over-the-wire method and function calls
- Use case specific events e.g. user presence events (online/offline) or events for chat functionality
- It will also likely provide access to a number of events specific to the functionality it offers
class: bg-white background-image: url(https://docs.google.com/drawings/d/1rZmX1utBDUNEigmUWrr6WsupuNFoqjSR9jXnEgKjUmQ/pub?w=1195&h=721)
???
Each interaction with the application from the user is a real-time event with associated real-time data. Which of those events is important and should be acted upon depends on your application requirements.
class: bg-white black-text top background-image: url(https://docs.google.com/drawings/d/144h2Lr-x5CAr7v1fqrV0MwHM77Mr5tAHtmpftBJ5j4I/pub?w=1195&h=721)
???
Now that we've truely set the scene, let's make our way through the components in this real-time application and identify the tools, tips & techniques that I've found are really useful as we develop our app.
template: pink class: tip top h1-big
--
When designing & building real-time apps, always think about how the decisions you're making - anywhere in your stack - will impact the client app.
???
template: dblue class: h1-big
class: bg-white black-text top background-image: url(https://docs.google.com/drawings/d/1lWV_UBvVoNWgO3u--0L5A6U2YSGSnaLPO_IC6YPF9uU/pub?w=1195&h=721)
???
When building real-time applications you quite frequently get data from 3rd party components.
- APIs/Services
- Databases
- Queues
There are a lot of potential places where this real-time data can comes from.
class: bg-white fixed-width-list trans-h em-text top background-image: url(img/apps-with-realtime-apis.png)
???
Not only are there lots of options, but they also deliver it in various forms.
--
--
--
--
class: bg-video, trans-h, em-text, bottom play_video:
class: bg-video, trans-h, em-text, bottom play_video:
class: top larger
You can't always control what the data source sends and when it sends it. Even it you can, it can be tedious to trigger test data.
With REST APIs we can generate fake data. With real-time... ?
--
Capture & replay
???
The problem: makes the development phase really difficult.
template: white class: top background-image: url(https://docs.google.com/drawings/d/1l-zpXT0rmra_oAmUJmO7dYiwAebHfUhJ3JTnWrt-fXM/pub?w=1195&h=721)
???
In production, you can capture this data. But in development you want a simple solution that requires less infrastructure.
class: top fixed-width-list
???
WebHooks are HTTP callbacks from one server to another. They're triggered when one server has data that it wants to send to another, normally via a POST
request.
--
Lots of options available
class: bg-video bg-cover trans-h em-text bottom
-- play_video:
template: white
???
HTTP Streaming and WebSocket connections are persistent connections that potentially provide a constant stream of data from the data source.
class: fixed-width-list template: white
template: white class: black-text
- A simple http traffic replication tool written in Go.
- No WebSocket support right now
class: bg-white top black-text background-image: url(https://docs.google.com/drawings/d/1-UKjjtf66kuYihycIQSXFiIIeyYVCYB36-6uppx3KS4/pub?w=1195&h=721)
class: bg-white trans-h background-image: url(./img/log-all-the-things.png)
class: fixed-width-list
- Monitor them
- Filter them
- Build tools around them
- Replay them
class: bg-video, bg-cover, trans-h, em-text, bottom
???
There are some amazing logging tools out there.
- librato
- data dog
- loggly
- logstash
But they do too much. For this, we need something simple.
You could...
log to stdout, use the logfmt format, know your good old grep / sed / awk - @zimbatm
But I want there to be better options
class: bg-green thought
We need better HTTP Streaming/WebSocket capture & replay tooling to improve the developer experience
???
We could do with simpler capture/replay tools
template: pink
The server is your real-time data work-horse. It should still do the vast majority of data processing and decision making. Web, Mobile an IoT clients are great, but they're not processing machines.
??? Don't just pass all this data directly on to the client.
template: dblue class: h1-big
- Queries
- Transformations
- Data formatting
???
- Do whatever you need to do with the data upon receipt.
- As mentioned, keep the client in mind as it's them you're going to be delivering to.
- What do I mean by that?
???
Here's what a standard tweet JSON looks like. Do I really want to send all this over the wire? It ultimately has to be converted from bytes or a string and parsed into a an object before the client can do anything with it. The larger it is the more work the client has to do.
template: pink
.left[ Don't send this
] .right[ When you only need this
{
"screen_name": "leggetter",
"text": "I love to tweet",
"created_at": "Wed Sep 23 18:10:25 +0000 2015"
}
]
???
- Once you've applied the queries or transformations you should only send the data to the client that it needs and is going to use.
- Even consider things like formatting dates so they can be directly displayed rather than needing to be parsed and formatted on the client. Or at least send in an easily parsable format.
class: top
- Maintain an image of the current state of data
- Only send data that changes
--
.left[
{
"home_team": "Liverpool",
"home_team_score": 0,
"away_team": "Arsenal",
"away_team_score": 0,
"event_time": "1443117125014"
}
.right[
{
"home_team": "Liverpool",
**"home_team_score": 1,**
"away_team": "Arsenal",
"away_team_score": 0,
**"event_time": "1443117150287"**
}
class: center-pre
.center[
{
"home_team_score": 1,
"event_time": "1443117150287"
}
]
class: bg-video, trans-h, em-text, top play_video:
???
Even if you've made sure you're:
- Doing all the heaving lifting on the server
- only sending the data that's required You still need to watch how often you're sending
class: top
--
-
100ms is instantaneous to a human --
-
250ms is average human reaction time --
-
Each update requires some processing
- Data parsing
- UI updates
- ... --
-
Consider batching
template: dblue class: h1-big
class: top background-image: url(https://docs.google.com/drawings/d/1ERZ2boQXQ8PHFF738ZwCupymA7fSKzr8xIjW4SHlJdM/pub?w=1195&h=721)
???
So, we've covered building up the data payloads that we're going to send to the Real-Time Server...
class: bottom background-image: url(https://docs.google.com/drawings/d/1k_7-4yTvs-cb6slQXvzgBwBL0SaFfE-hSpTjAfnS8Xg/pub?w=1195&h=721)
- Can we confirm what's going in?
- And see what's going out?
template: pink class: fixed-width-list
- connections
- subscriptions
- messages
- presence
- other events/features
???
As you're developing you really want to know if the code you are writing is having the desired effect. Are connections being established, are subscriptions to data being made, are messages going in to your real-time framework and going out the other side to connected clients?
Is the framework supported functionality working as expected?
class: fixed-width-list
## LOG ALL THE THINGS
- Monitor them
- Filter them
- Build tools around them
class: bg-video, trans-h, em-text, bottom
--
play_video:
class: bg-green thought
???
TODO: reach out to @zimbatm & @hpoom about real-time logging solutions
class: top background-image:url(https://docs.google.com/drawings/d/1KAb6UWTyOVCWMpf5ZOJHq4eW1nNSBcjnUrDTf0mw7Tw/pub?w=1195&h=721)
class: trans-h top background-image: url(./img/internet-http-es-ws.png)
???
- When thinking about web & mobile WebSocket with HTTP fallback is probably now the defacto standard.
- What networks lie between your RT server and the Client?
- What's the most efficient connection type for a client?
.left[
- Bayeux
- DDP
- dNode
- EPCP
- GRIP ] .right[
- MQTT
- Pusher Protocol
- STOMP
- WAMP (Web App Messaging Protocol)
- XMPP (various)
- Proprietary ]
class: trans-h background-image: url(https://docs.google.com/drawings/d/1378sTg1fKEzo4HVBW97JqU0RjJS6u7fsh1hGaCZR0PA/pub?w=960&h=720)
???
communication patterns on top of transports diagram
background-image: url(https://docs.google.com/drawings/d/1KiPBLoNpAY-4LAdqSE4YsT7_CzusLB5xC9AUYDin7Lg/pub?w=960&h=720) class: bg-white
background-image: url(https://docs.google.com/drawings/d/1mPgTs6fgL6R9-JkCxghNG2x4Jg-0m10oK09KUpO8pHY/pub?w=960&h=720) class: bg-white
template: pink class: top
Choose the right real-time framework for the functionality you want to build and the client devices you're targeting...
--
] .right[ ]class: top long
† erm, I mean use HTTP/2, ServiceWorker, Fullscreen and many more web features
--
class: bg-pink
## Use SSL all the time - including in development.
--
template: dblue class: h1-big
class: top-left background-image: url(https://docs.google.com/drawings/d/1rOpWrX-4xOoCmXDVuIZI50EKjRPWlIrFtcmYSJfoPuc/pub?w=1195&h=721)
class: top-left background-image: url(https://docs.google.com/drawings/d/1N6NRRYf_qzDgkpPTmrK5D4F-fttyPwvw0NMs3o8ls3o/pub?w=1195&h=721)
class: fixed-width-list top
--
- Processing - on the server
- Payload - focused & minimal
- Image + Changes
- Formatted - further reduce processing
- Update frequency - controlled / batched
template: pink
class: fixed-width-list
- Timestamp published messages
- Check time upon receipt
- Consider:
- Timezone differences
- System clock offsets
- If latency gets high, inform the user
class: top-left
background-image: url(https://docs.google.com/drawings/d/1qN0CJUvdhgIc9iZnNiRrFGKggsJ5UxCP57IiCG9vzTI/pub?w=1195&h=721)
If updating the UI causes a delay, a queue of messages can start building up
setTimeout
requestAnimationFrame
???
http://jsbin.com/sarobe/edit?js,console
class: fixed-width-list
Let the server know the client is struggling
If things get really bad
class: top-left background-image: url(https://docs.google.com/drawings/d/1nKhiqmidFMSJuVrWnBYKoLS4UWKsx7HHTzrMbuy-__I/pub?w=1195&h=721)
???
The point of integration between the real-time tech and your application.
class: fixed-width-list
- Data Sources - you can't control the data
- Data considerations: processing, payload, update frequency
- Connectivity - Online/Offline, SSL, transports & protocols
- Monitoring client performance
class: bg-video, bg-cover, trans-h, em-text, top
???
Now, I'm sure Ben has lots of friends. But do you think he has them round his house for hours on end to help him make sure his demos work?
No!
template: pink
class: fixed-width-list top
- Angular/Ember/your own Services
var myModule = angular.module('myModule', []);
myModule.factory('pusher', function() {
var pusher = new Pusher('YOUR_APP_KEY');
return pusher;
});
class: fixed-width-list top
- Angular/Ember/your own Services
var myModule = angular.module('myModule', []);
// myModule.factory('pusher', function() {
// var pusher = new Pusher('YOUR_APP_KEY');
// return pusher;
// });
myModule.factory('pusher', function() {
var pusher = new FakePusher();
return pusher;
});
class: trans-h bottom
<iframe style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" src="./examples/twitter-viewer/workbench.html"></iframe>Bonus: Abstractions enable change. You could swap out the underlying real-time technology in the future.
class: top-left background-image: url(https://docs.google.com/drawings/d/1S8HlwfMF7iMyoFQhx9YBmVeU3ebyJmjpIPJe9qiSlSk/pub?w=1195&h=721)
As discussed, not covered in this talk.
But...
class: fixed-width-list
Performance Monitoring / UI rendering
- Advanced Performance Audits With Chrome DevTools - @paul_irish
- Chrome Rendering Performance - @aerotwist
- MSEdge Dev Tools - Performance
- Firefox Dev Tools - Performance
- High Performance Browser Networking - @igrigorik
template: pink class: fixed-width-list top background-image: url(https://docs.google.com/drawings/d/1a-lXfKQ-3wbXMAIxgIEVIVW10jvV4RIQnAe19jnqtk4/pub?w=1195&h=721)
.left[
]
template: lblue class: title
- Phil @leggetter
- Head of Developer Relations