Transcript
Page 1: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

© 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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Demo

N-Tier App

PopEvent

Page 4: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

N-tier architecture

Front-end

server

Internal

APIInternal

APIAPI

Poll

Poll

Database

Storage

Queries

Synchronous

User waits

for update

Page 5: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Application requirements have

changed

Page 7: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Application requirements have

changedPetabytes of

data

Page 8: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Application requirements have

changedPetabytes of

data100% uptime

Page 9: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Application requirements have

changed

Sub seconds

response time

Petabytes of

data100% uptime

Page 10: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Traditional Style of applications

cannot deliver on these

requirements any longer

Page 12: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

Reactive Applications

Page 13: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Demo

Reactive Apphttp://popevent.elasticbeanstalk.com

PopEvent

Page 14: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

ResponsiveApplication pushes updates to client in real time

Responsive

Elastic Resilient

Message-driven

Page 15: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

ElasticScales out and in as demand varies

Responsive

Elastic Resilient

Message-driven

Page 16: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

ElasticScales out and in as demand varies

Responsive

Elastic Resilient

Message-driven

Page 17: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

ResilientSurvives failure of individual components

Page 18: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

ResilientSurvives failure of individual components

Page 19: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

ResilientSurvives failure of individual components

Page 20: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Message drivenLoosely coupled, message-driven components

Responsive

Elastic Resilient

Message-driven

Page 21: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

Transition

• Synchronous

• Tightly coupled

• Blocking

• Pull-based

N-Tier

Reactive

N-tier to Reactive

Page 22: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

N-tier to Reactive

Internal

APIInternal

APIAPI

Poll

Poll

Database

Storage

Queries

Synchronous

User waits

for update

Front-end

server

Page 23: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

N-tier to Reactive

Front-end

server

Internal

APIInternal

APIAPI

Database

Storage

Queries

Synchronous

User waits

for update

Push

Push/Broadcast

Page 24: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Let's build a reactive application

Goals• React to Users

• React to Requests

• React to Load

• React to Failures

PopEvent

Page 30: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Reacting to users

Responsive

Elastic Resilient

Message-driven

Page 31: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

messageTopicWebSocket

Server (EC2)

Subscribe/Notify

HTML5 Clients

SNS

Responsive

Elastic Resilient

Message-driven

Page 32: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

messageTopicWebSocket

Server (EC2)

HTML5 Clients

WebSocket

Server (EC2) Subscribe/NotifySNS

Responsive

Elastic Resilient

Message-driven

Page 33: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Amazon SNS - Overview

• Publish-subscribe model

• Scalable, robust way to implement push

• Topics

• Broadcast messages

Responsive

Elastic Resilient

Message-driven

Page 34: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

WebSocket - overview

• HTML5 Technology

• Full-duplex communication over TCP

Responsive

Elastic Resilient

Message-driven

Page 35: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Server – Subscribe to Amazon SNS topic

Page 37: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Server – Define endpoints

Page 38: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Server – Create SockJS server

Page 39: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Client – Connect to SockJS server

Page 40: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Server – handle client connection

Page 41: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Client– Send Message to SockJS server

http://popevent.elasticbeanstalk.com

Page 42: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Server - Broadcast to clients

Page 43: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

messageTopicWebSocket

Server (EC2)

Subscribe/Notify

HTML5 Clients

SNS

Done!!

Page 44: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

Page 45: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Reacting to requests

Responsive

Elastic Resilient

Message-driven

Page 46: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

DynamoDB- overviewResponsive

Elastic Resilient

Message-driven• Fully managed cloud NoSQL database

• Seamless Scaling

• Highly Available

• Flexible data models( key-value/document )

Page 49: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Key 1 Key 2 Key 3

Server 1 Server 2 Server 3 Server 4 Server 5

Use unique keys to increase throughput

Page 52: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Hotkey - likeCounter

Page 53: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

Page 54: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Demo

Deploying with

Elastic Beanstalk

PopEvent

Page 56: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Making WebSocket work

Select TCP

Page 57: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Making WebSocket work

Select None

Page 58: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Reacting to load—elastic

Responsive

Elastic Resilient

Message-driven

Page 59: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Elastic Load Balancing - Overview

• Distribute the load automatically

• Works seamlessly with Auto Scaling groups

• Cross-zone load balancing

• Perform health checks

Page 61: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Reacting to load—elastic• Auto Scaling

• Elastic Load Balancing

• Configure in Elastic Beanstalk

Page 62: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Auto Scaling

Page 63: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Auto Scaling – contd.

Page 64: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Elastic Load Balancing - Config

Page 65: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Elastic Load Balancing - Config

Page 66: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Elastic Load Balancing

Users

Load Balancer

EC2 Instances with Auto Scaling

Page 67: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Reacting to failures—resilient

Responsive

Elastic Resilient

Message-driven

Page 69: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Users

Load Balancer

EC2 Instances with Auto Scaling

Reacting to failures—Level 1

Page 71: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Reacting to failures—Level 2

Users

Load Balancer

EC2 Instances with Auto Scaling.

Secured with Amazon VPC

Page 72: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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 73: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Amazon Route 53

Page 74: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Across regions – Amazon Route 53

Region 1 Region 2

Based on a routing policy

Amazon Route 53

Page 75: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

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: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Multi AZ and Multi region

Users

AZ1 AZ2

AZ1 AZ2

Region 1

Region 2

Page 77: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

DemoReacting to failures—resilient

Page 78: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

Page 79: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Responsive

Elastic Resilient

Message-driven

Reactive Applications

Page 80: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Thank You!

Page 81: (ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014

Please give us your feedback on this session.

Complete session evaluations and earn re:Invent swag.

http://bit.ly/awsevalsARC206


Top Related