Real-time is becoming the life blood of applications. Facebook, Twitter, Uber, Google Docs and many more apps have increased user expectation to demand real-time features. Features such as Notifications, activity streams, real-time data visualisations, chat or collaborative experiences instantly keep users up to date and enable them to work much more effectively. So, how do you build these sorts of features with .NET?
This talk will cover the benefits of moving away from polling to push, the options you have with .NET web application to do this and when adding real-time features to your apps, and the pros and cons of each to help choose which is the best solution for you.
4. What we'll cover
1. Why Real-Time?
2. Common Real-Time Use Cases
3. What are your options?
How do you choose? inc. Communication Patterns
.NET examples
Pros & Cons
4. Q&A
5 / 105
@leggetter
29. Polling Calculations
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, with a 10 second polling interval
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
23 / 105
@leggetter
30. Polling Calculations
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, with a 10 second polling interval
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
4. Poll requests per user/minute = (60 / 10) = 6
23 / 105
@leggetter
31. Polling Calculations
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, with a 10 second polling interval
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
4. Poll requests per user/minute = (60 / 10) = 6
5. Poll requests per user/hour = (6 * 60) = 360
23 / 105
@leggetter
32. Polling Calculations
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, with a 10 second polling interval
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
4. Poll requests per user/minute = (60 / 10) = 6
5. Poll requests per user/hour = (6 * 60) = 360
6. Poll requests site wide per hour = (360 * 10,000) = 3,600,000
23 / 105
@leggetter
33. Polling Calculations
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, with a 10 second polling interval
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
4. Poll requests per user/minute = (60 / 10) = 6
5. Poll requests per user/hour = (6 * 60) = 360
6. Poll requests site wide per hour = (360 * 10,000) = 3,600,000
With polling the site would need to handle 3.65 Million requests per hour
Or 50k HTTP requests + maintain 10k persistent connections?
23 / 105
@leggetter
35. 2. Use an existing solution
Don't reinvent the wheel
Unless you've a unique use case
25 / 105
@leggetter
36. Why use an existing solution?
Connection fallback/upgrade hacks still required
WebSocket: 91% of connections
HTTP fallback: 9% of connections
26 / 105
@leggetter
37. Why use an existing solution?
Connection fallback/upgrade hacks still required
WebSocket: 91% of connections
HTTP fallback: 9% of connections
Support/Community
26 / 105
@leggetter
38. Why use an existing solution?
Connection fallback/upgrade hacks still required
WebSocket: 91% of connections
HTTP fallback: 9% of connections
Support/Community
Maintenance
26 / 105
@leggetter
39. Why use an existing solution?
Connection fallback/upgrade hacks still required
WebSocket: 91% of connections
HTTP fallback: 9% of connections
Support/Community
Maintenance
Future features
26 / 105
@leggetter
40. Why use an existing solution?
Connection fallback/upgrade hacks still required
WebSocket: 91% of connections
HTTP fallback: 9% of connections
Support/Community
Maintenance
Future features
Scaling
26 / 105
@leggetter
48. Client Device Support
Only some have a selection of client libraries
Supported connection transports
31 / 105
@leggetter
49. Client Device Support
Only some have a selection of client libraries
Supported connection transports
How much data are you sending?
31 / 105
@leggetter
50. Client Device Support
Only some have a selection of client libraries
Supported connection transports
How much data are you sending?
SSL required on 3/4G networks
31 / 105
@leggetter
57. Simple Messaging
// client
var ws = new WebSocket('wss://localhost/');
ws.onmessage = function(evt) {
var data = JSON.parse(evt.data);
35 / 105
@leggetter
58. Simple Messaging
// client
var ws = new WebSocket('wss://localhost/');
ws.onmessage = function(evt) {
var data = JSON.parse(evt.data);
// ^5
performHighFive();
};
35 / 105
@leggetter
59. Simple Messaging
// client
var ws = new WebSocket('wss://localhost/');
ws.onmessage = function(evt) {
var data = JSON.parse(evt.data);
// ^5
performHighFive();
};
// server
server.on('connection', function(socket){
35 / 105
@leggetter
60. Simple Messaging
// client
var ws = new WebSocket('wss://localhost/');
ws.onmessage = function(evt) {
var data = JSON.parse(evt.data);
// ^5
performHighFive();
};
// server
server.on('connection', function(socket){
socket.send(JSON.stringify({action: 'high-5'}));
});
35 / 105
@leggetter
61. Simple Messaging
using Nexmo.Api;
// SMS
var results = SMS.Send(new SMS.SMSRequest
{
from = "15555551212",
to = "17775551212",
text = "this is a test"
});
// Voice
var result = Voice.TextToSpeech(new Voice.TextToSpeechCallCommand
{
to = "17775551212",
from = "15555551212",
text = "Hello from Nexmo"
});
36 / 105
@leggetter
86. Data Sync
// client
var ref = new Firebase("https://app.firebaseio.com/doc1/lines");
48 / 105
@leggetter
87. Data Sync
// client
var ref = new Firebase("https://app.firebaseio.com/doc1/lines");
ref.on('child_added', function(childSnapshot, prevChildKey) {
// code to handle new child.
});
48 / 105
@leggetter
88. Data Sync
// client
var ref = new Firebase("https://app.firebaseio.com/doc1/lines");
ref.on('child_added', function(childSnapshot, prevChildKey) {
// code to handle new child.
});
ref.on('child_changed', function(childSnapshot, prevChildKey) {
// code to handle child data changes.
});
48 / 105
@leggetter
89. Data Sync
// client
var ref = new Firebase("https://app.firebaseio.com/doc1/lines");
ref.on('child_added', function(childSnapshot, prevChildKey) {
// code to handle new child.
});
ref.on('child_changed', function(childSnapshot, prevChildKey) {
// code to handle child data changes.
});
ref.on('child_removed', function(oldChildSnapshot) {
// code to handle child removal.
});
48 / 105
@leggetter
90. Data Sync
// client
var ref = new Firebase("https://app.firebaseio.com/doc1/lines");
ref.on('child_added', function(childSnapshot, prevChildKey) {
// code to handle new child.
});
ref.on('child_changed', function(childSnapshot, prevChildKey) {
// code to handle child data changes.
});
ref.on('child_removed', function(oldChildSnapshot) {
// code to handle child removal.
});
ref.push({ 'editor_id': 'leggetter', 'text': 'Nexmo Rocks!' });
48 / 105
@leggetter
91. Data Sync
// client
var ref = new Firebase("https://app.firebaseio.com/doc1/lines");
ref.on('child_added', function(childSnapshot, prevChildKey) {
// code to handle new child.
});
ref.on('child_changed', function(childSnapshot, prevChildKey) {
// code to handle child data changes.
});
ref.on('child_removed', function(oldChildSnapshot) {
// code to handle child removal.
});
ref.push({ 'editor_id': 'leggetter', 'text': 'Nexmo Rocks!' });
Framework handles updates to other clients
48 / 105
@leggetter
120. Pros
.NET
Maps well to PubSub
Loosely coupled
Could use another runtime
Cons
How does it fit with RMI/SignalR?
Multiple components
Self-scaling
Queue routing questions
In: HTTP. Out: WebSocket
Self-Hosted: .NET + Message Queue - Pro &
Cons
69 / 105
@leggetter
121. If SignalR or XSockets aren't a good fit
you may have to look at a non-.NET solution
70 / 105
@leggetter
126. Pros
Simple & powerful
Instantly scalable
Managed & dedicated
Direct integration. No overhead.
Cons
3rd party reliance
Difficult to influence functionality
Hosted - Pros & Cons
74 / 105
@leggetter
127. Why use a hosted service?
Scenario
1. Site average of 10,000 Users
75 / 105
@leggetter
128. Why use a hosted service?
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, no polling
75 / 105
@leggetter
129. Why use a hosted service?
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, no polling
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
75 / 105
@leggetter
130. Why use a hosted service?
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, no polling
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
4. That's it! Total: 50,000
75 / 105
@leggetter
131. Why use a hosted service?
Scenario
1. Site average of 10,000 Users
2. Over 1 Hour, no polling
3. Requests from pages load + HTML, CSS, JS, Images for 10k users = 50,000
4. That's it! Total: 50,000
Your servers handle 50k requests per hour instead of 3.6M
You offload the polling or persistent connections to the service
75 / 105
@leggetter
134. How do you choose?
7 Realtime Framework Considerations
1. Should you keep on polling?
2. Use an Existing Solution
3. Use a language you're comfortable with
4. Do you need multiple client device support?
5. Simple Messaging, PubSub/Evented, RMI or DataSync
6. Architectural considerations
7. Hosted v Self-Hosted (Build vs. Buy)
78 / 105
@leggetter
135. You need Real-Time!
There are lots of options.
Make the choice that's right for you.
I hope this helps!
79 / 105
@leggetter
148. A thing can be anything
Sensors
Appliances
Vehicles
Smart Phones
Devices (Arduino, Electric Imp, Raspberry Pi etc.)
91 / 105
@leggetter
149. A thing can be anything
Sensors
Appliances
Vehicles
Smart Phones
Devices (Arduino, Electric Imp, Raspberry Pi etc.)
Servers
Browsers
Apps: Native, Web, running anywhere
91 / 105
@leggetter
150. The Majority of code we'll write will still be
for "Apps"
Configuring
Monitoring
Interacting
App Logic
92 / 105
@leggetter
151. Real-Time Use Case Evolution
Notifications & Signalling
Activity Streams
Data Viz & Polls
Chat
Collaboration
Multiplayer Games
93 / 105
@leggetter