nodejs & socket io on microsoft azure cloud web sites - dwx 2014
DESCRIPTION
Presentation used as a support for the "Move you NodeJS application on the cloud" session on the DWX 2014. Contains detailed informations on how to start from a local working application to a fully scalable and highly available one on Microsoft Azure Cloud. See the Github associated project: https://github.com/brainsonic/AzureJSChat where you can find all source code: > local branch: the application running on a local machine or a "classic" server > azure-servicebus: the application "almost ready" for use with Azure Service Bus (will be updated) > azure-redis: the application fully working on Azure Web Sites synchronizing data through Azure Redis Cache service and Azure Table StorageTRANSCRIPT
NODEJS ON MICROSOFT AZUREMake your application highly available
Developer Week 2014 | #dwx142014 July, 14th-16th
2
WHO’S THAT…
• STÉPHANE ESCANDELL– Technical Project Manager – Brainsonic– [email protected]
@BrainsonicParis
@sescandell
github.com/sescandell
github.com/Brainsonic
(France - Paris / Lyon)
3
Microsoft Azure
4
MICROSOFT AZURE HOSTING SOLUTIONS 1/3
Microsoft Azure Web Sites
Modern Web AppsFit perfectly for client and server-side project with database requirements.
High scalabitlity
Continuous developmentDeploy immediatly from your GIT repository or your TFS or via FTP (you don’t do that, isn’t it?)
Open source appsThanks to the integrated Gallery, start easily your professionnal websites via WordPress, Joomla!, Drupal, DotNetNuke or Umbraco…
5
MICROSOFT AZURE HOSTING SOLUTIONS 2/3
Microsoft Azure Cloud Services (WebRole & WorkerRole)
Multi-tier applicationsFor cloud applications where you need to seperate different layers or make asynchronous processes using WebRole and WorkerRoles
Admin requirementsProvide a root access to instances with RDP connection activated.
Specific network capacitiesFor applications with specific network requirements or based on Windows Azure Connect or Windows Azure Virtual Network.
6
MICROSOFT AZURE HOSTING SOLUTIONS 3/3
IAAS Microsoft Azure Virtual Machines
For existing applicationsMake your application immediately running on the Cloud with no change. Takes benefits from first Cloud Services available (SQLServer, SharePoint Server, Database, Active Directory, …)
Use Virtual disk to initiate your VMSelect one VHD from the Microsoft Azure Gallery, or use your own (Puppet capacities available)
Windows & LinuxProviding Windows Server, and Linux distributions. Connect IAAS platform to Cloud Services and get a first step in the Cloud with no changes
7
HOSTING… AND SERVICES
Load balancer / endpoints LB Microsoft Azure Storage
SQL database Table storage Blob storage
Microsoft Azure Cache …
8
Move NodeJS & Socket.IO on MAWS
9
WHY WEB SITES?
Easy to create Open
.Net PHP JAVA NodeJS …
Easy to deploy (git push) Customizable (hook on git push)
10
WEB SITES INFRASTRUCTURES
Windows Server IIS Web server « Auto-scalling » capacities
No root No RDP (only CLI available on « one » instance… but which one…, no one
knows…)
11
WICH APP?
• SIMPLE CHAT APPLICATION Be able to join a room Instant notifications Gravatar integration
• SOFTWARE STACK NodeJS… of course SocketIO
12
NODEJS
• NODE For those in the know
• OPEN SOURCE PROJECT Created in 2009 Built on top of V8 (Chrome’s Javascript Runtime)
• NODE IS A C SOFTWARE Running as a dameon for today sample Event-driven (did you see the presentation this morning?) Non-blocking I/O
13
SOCKET.IO
JAVASCRIPTREALTIME
WEB
APP
BI-
DIR
EC
TIO
NN
AL
WEBSOCKETS
UNIFIED API
NO
DEJS
FALLBACK
EVENT DRIVENASYNCHRONOUS
OPEN SOURCEBROADCASTING
CLIE
NT
SER
VER
WR
APPE
R
DATA
AJA
X
CROSS PLATFORM
MULTI-CLIENTBi-directionnal communication
Emit message
Broadcasting
14
HOW IS THE APP WORKING?
connect()
connect
load
peopleInChat
login
imgparticipantJoined
msgreceive
Login process
Notify users
Chat
loop
Notify users
15
Let’s see it…
16
MOVE ON AZURE WEB SITES
# http://azure.microsoft.com/en-us/documentation/articles/xplat-cli/$> npm install azure-cli –g$> azure account download$> azure account import <file.publishsettings>
• PREPARE YOUR ENVIRONMENT Executed once Secure access to your portal
• USE IT AS YOU PREFERE Portal: http://manage.windowsazure.com (preview: http://portal.azure.com ) Rest API Cross Platform CLI (based on Rest API integrated via NodeJs)
17
MOVE ON AZURE WEB SITES
• GET THE SERVERS DevOps friendly!!!
# And deploy$> git push azure master
18
MOVE ON AZURE WEB SITES
• ACTIVATE WEB SOCKETS Because of SocketIO
# CLI version$> azure site set –w dwx2014demo
19
Be scalable and highly available
20
WHAT’S WRONG?
Messages are not broadcasted to other « socket.io instances »
Participants storage is not shared (informations missing)
1
1 1? ?
2
2 2 2
21
TARGETED SOLUTION
Participants storage uses Azure Table Storage service(a Key-Value storage based)
Sockets connectoruses Azure Service Bus service(an AMQP compliant messagebroadcaster)
App endpoint via Azure Web SitesActs as a Load Balancer
One instance
22
Great, let’s do it
23
AZURE SERVICE BUS & NODEJS… LET’S ENTER REDIS
• INTEGRATION BROKEN WITH NODEJS Because of NodeJS / dependencies updates Issue created on Github:
https://github.com/Azure/azure-sdk-for-node/issues/1255
Deploying fix… socket.io-adapter for Service Bus coming soon:
https://github.com/brainsonic/socket.io-azureservicebus
• NEED A « PLAN B » Redis as a Service Fully integrated into Azure Master / Slave Preview… but free! Using https://github.com/automattic/socket.io-redis
24
OUR NEW ARCHITECTURE
Participants storage uses Azure Table Storage service(a Key-Value storage based)
Sockets connectoruses Azure Redis Cache service(and pub/sub capacities)
App endpoint via Azure Web SitesActs as a Load Balancer
One instance
25
You’d better have the right
recipe to make the
right magic potion
26
I/O ABSTRACTION
Should be required
Create common interfaces (Javascript doesn’t natively support Interface, so define team rules or create specific tests)
Dependency Injection Data storage File system / storage Event manager … all your I/Os
27
YOU HAVE QUESTIONS…
… I can try to answer them…