Page 1
© 2014 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc.
November 13, 2014 | Las Vegas, NV
ARC 206
Architecting Reactive Applications on AWSAtul Shukla, USEReady
Revanth Talari, USEReady
Page 2
Agenda
• N-tier architecture and its limitations
• What is a Reactive Application
• Reactive Application architecture
• AWS for Reactive Applications
• Build a Reactive Application
Page 3
Demo
N-Tier App
PopEvent
Page 4
N-tier architecture
Front-end
server
Internal
APIInternal
APIAPI
Poll
Poll
Database
Storage
Queries
Synchronous
User waits
for update
Page 5
N-tier architecture• Synchronous communication
• Blocking– Lower throughput
– Hardware under-utilization and higher costs
• Tightly coupled– Location dependent
– Difficult to extend and maintain
• Blocking
• Pull-based
Page 6
Application requirements have
changed
Page 7
Application requirements have
changedPetabytes of
data
Page 8
Application requirements have
changedPetabytes of
data100% uptime
Page 9
Application requirements have
changed
Sub seconds
response time
Petabytes of
data100% uptime
Page 10
Change is inevitable• Users
– Demands richer experiences
– Expects super fast response time
• Applications
– Need to scale-on-demand
– Always-On
– Real-time
• Business
– Need to react to these changing requirements
Page 11
Traditional Style of applications
cannot deliver on these
requirements any longer
Page 12
Responsive
Elastic Resilient
Message-driven
Reactive Applications
Page 13
Demo
Reactive Apphttp://popevent.elasticbeanstalk.com
PopEvent
Page 14
ResponsiveApplication pushes updates to client in real time
Responsive
Elastic Resilient
Message-driven
Page 15
ElasticScales out and in as demand varies
Responsive
Elastic Resilient
Message-driven
Page 16
ElasticScales out and in as demand varies
Responsive
Elastic Resilient
Message-driven
Page 17
Responsive
Elastic Resilient
Message-driven
ResilientSurvives failure of individual components
Page 18
Responsive
Elastic Resilient
Message-driven
ResilientSurvives failure of individual components
Page 19
Responsive
Elastic Resilient
Message-driven
ResilientSurvives failure of individual components
Page 20
Message drivenLoosely coupled, message-driven components
Responsive
Elastic Resilient
Message-driven
Page 21
Responsive
Elastic Resilient
Message-driven
Transition
• Synchronous
• Tightly coupled
• Blocking
• Pull-based
N-Tier
Reactive
N-tier to Reactive
Page 22
N-tier to Reactive
Internal
APIInternal
APIAPI
Poll
Poll
Database
Storage
Queries
Synchronous
User waits
for update
Front-end
server
Page 23
N-tier to Reactive
Front-end
server
Internal
APIInternal
APIAPI
Database
Storage
Queries
Synchronous
User waits
for update
Push
Push/Broadcast
Page 24
N-tier to Reactive
Front-end
server
Internal
APIInternal
API
Database
Storage
Queries
Synchronous
User waits
for update
Push
Push/Broadcast
Message
handlers
Page 25
N-tier to Reactive
Front-end
server
Internal
APIInternal
API
Database
Storage
Queries
Synchronous
User waits
for update
Push
Push/Broadcast
Message
handlersQueue
messages
Page 26
N-tier to Reactive
Front-end
server
Internal
APIInternal
API
Database
Storage
Queries
Asynchronous
User waits
for update
Push
Push/Broadcast
Message
handlersQueue
messages
Page 27
Reactive architecture• Asynchronous message passing
• Non-blocking– Higher throughput
– Effective hardware utilization and lower costs
• Loosely coupled– Location independent
– Easy to extend and maintain
• Push-based
Page 28
AWS for Reactive Applications• Responsive
– Amazon EC2 (Websocket
Server)
– Amazon SNS
• Elastic– Elastic Load Balancing
– Auto Scaling
– Elastic Beanstalk
– Amazon DynamoDB
• Resilient– Availability Zones
– Amazon Route 53
– Auto Scaling
– Amazon VPC
– DynamoDB
• Message Driven– Amazon SQS
– Amazon SWF
Page 29
Let's build a reactive application
Goals• React to Users
• React to Requests
• React to Load
• React to Failures
PopEvent
Page 30
Reacting to users
Responsive
Elastic Resilient
Message-driven
Page 31
messageTopicWebSocket
Server (EC2)
Subscribe/Notify
HTML5 Clients
SNS
Responsive
Elastic Resilient
Message-driven
Page 32
messageTopicWebSocket
Server (EC2)
HTML5 Clients
WebSocket
Server (EC2) Subscribe/NotifySNS
Responsive
Elastic Resilient
Message-driven
Page 33
Amazon SNS - Overview
• Publish-subscribe model
• Scalable, robust way to implement push
• Topics
• Broadcast messages
Responsive
Elastic Resilient
Message-driven
Page 34
WebSocket - overview
• HTML5 Technology
• Full-duplex communication over TCP
Responsive
Elastic Resilient
Message-driven
Page 35
SockJS - overview• Wrapper library over WebSocket
• Available for both clients and server
• SockJS library - https://github.com/sockjs
– Client side – sockjs-client
– Server Side – sockjs-node
Responsive
Elastic Resilient
Message-driven
Page 36
Server – Subscribe to Amazon SNS topic
Page 37
Server – Define endpoints
Page 38
Server – Create SockJS server
Page 39
Client – Connect to SockJS server
Page 40
Server – handle client connection
Page 41
Client– Send Message to SockJS server
http://popevent.elasticbeanstalk.com
Page 42
Server - Broadcast to clients
Page 43
Responsive
Elastic Resilient
Message-driven
messageTopicWebSocket
Server (EC2)
Subscribe/Notify
HTML5 Clients
SNS
Done!!
Page 44
Responsive
Elastic Resilient
Message-driven
Page 45
Reacting to requests
Responsive
Elastic Resilient
Message-driven
Page 46
Amazon SQS - overviewResponsive
Elastic Resilient
Message-driven• Enables loose coupling
• Enables location independent components
• Designed to provide high durability
• At least once delivery
• Timeouts to manage failure
Page 47
Message to Tasks – Amazon SWF Responsive
Elastic Resilient
Message-driven• Task based programming models
• Run application workflows
• Asynchronous invocation
• Coordinate distributed application processing
• Ordered execution of application steps
• At most once delivery
• Reliable and auditable
Page 48
DynamoDB- overviewResponsive
Elastic Resilient
Message-driven• Fully managed cloud NoSQL database
• Seamless Scaling
• Highly Available
• Flexible data models( key-value/document )
Page 49
messageTopic
WebSocket
Server (EC2) Subscribe/Notify
HTML5 Clients
Message
Worker
1. Receive
Message
DynamoDB
saveMessage
compute
Popular
calcPop
Worker
4.Queue
Message
1. Get
Message
SQS
SQS
SNS
Responsive
Elastic Resilient
Message-driven
Page 50
Data ModelResponsive
Elastic Resilient
Message-driven• Tables
– Message• messageId(String) – Primary Hash Key
• timeCreated(Number) – Primary Range Key
– likeCounter• messageId(String) – Primary Hash Key
• dislikeCount(Number)
• likeCount(Number)
Page 51
Key 1 Key 2 Key 3
Server 1 Server 2 Server 3 Server 4 Server 5
Use unique keys to increase throughput
Page 52
Hotkey - likeCounter
Page 53
Responsive
Elastic Resilient
Message-driven
Page 54
Elastic Beanstalk - overview
• Fast and Simple way to deploy apps
• Makes development process productive
• Provides Auto Scaling and Elastic Load Balancing
out of the box
• Complete resource control
• Free!! Pay only for resources used
Page 55
Demo
Deploying with
Elastic Beanstalk
PopEvent
Page 56
Making WebSocket work
Select TCP
Page 57
Making WebSocket work
Select None
Page 58
Reacting to load—elastic
Responsive
Elastic Resilient
Message-driven
Page 59
Auto Scaling - Overview• Scale-out and scale-in
• Works seamlessly with Amazon CloudWatch
• Define Auto Scaling groups
• Enables fault tolerance
• Enables high availability
Page 60
Elastic Load Balancing - Overview
• Distribute the load automatically
• Works seamlessly with Auto Scaling groups
• Cross-zone load balancing
• Perform health checks
Page 61
Reacting to load—elastic• Auto Scaling
• Elastic Load Balancing
• Configure in Elastic Beanstalk
Page 63
Auto Scaling – contd.
Page 64
Elastic Load Balancing - Config
Page 65
Elastic Load Balancing - Config
Page 66
Elastic Load Balancing
Users
Load Balancer
EC2 Instances with Auto Scaling
Page 67
messageTopic
WebSocket
Servers(EC2) Subscribe/Notify
Messag
e
Worker
1. Receive
Message
DynamoDB
saveMessage
compute
Popular
4.Queue
Message
1. Get
Message
SQS
SQS
SNS
calcPop
Worker
Load Balancer
Users
Page 68
Reacting to failures—resilient
Responsive
Elastic Resilient
Message-driven
Page 69
Reacting to failures—Level 1• Avoiding single points of failures
• Auto Scaling and Elastic Load Balancing in a single
Availability Zone.
• Configure minimum number of instances
Responsive
Elastic Resilient
Message-driven
Page 70
Users
Load Balancer
EC2 Instances with Auto Scaling
Reacting to failures—Level 1
Page 71
Reacting to failures—Level 2
Users
Load Balancer
EC2 Instances with Auto Scaling.
Secured with Amazon VPC
Page 72
Reacting to failures—Level 3• Auto Scaling and Elastic Load Balancing across
regions
• Configure minimum number of instances in each
zone in each region
• Configure DNS entries in Amazon Route 53Responsive
Elastic Resilient
Message-driven
Page 74
Across regions – Amazon Route 53
Region 1 Region 2
Based on a routing policy
Amazon Route 53
Page 75
Multi AZ and Multi region
messageTopic
WebSocket
Servers(EC2) Subscribe/Notify
Messag
e
Worker
1. Receive
Message
DynamoDB
saveMessage
compute
Popular
4.Queue
Message
1. Get
Message
SQS
SQS
SNS
calcPop
Worker
Load Balancer
Users
Page 76
Multi AZ and Multi region
Users
AZ1 AZ2
AZ1 AZ2
Region 1
Region 2
Page 77
DemoReacting to failures—resilient
Page 78
Responsive
Elastic Resilient
Message-driven
Page 79
Responsive
Elastic Resilient
Message-driven
Reactive Applications
Page 81
Please give us your feedback on this session.
Complete session evaluations and earn re:Invent swag.
http://bit.ly/awsevalsARC206