Top Banner
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Jakub Wójciak with Tim Bray 07/13/2017 Decouple and Scale Applications Using Amazon SQS and Amazon SNS
50

Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Jan 28, 2018

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Jakub Wójciak with Tim Bray

07/13/2017

Decouple and Scale

Applications Using

Amazon SQS and Amazon SNS

Page 2: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Modern Apps

Compute Database

Messaging

Page 3: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Modern Apps

Compute Database

Messaging

Page 4: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Message

Page 5: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

JSON Message

{

"bookingId": "456ab773-dccb-4bc9-87b7-322ff5c29eab",

"bookingNumber": "CDG-64453",

"locationId": "563890",

"customer": {

"id": "8943",

"email": "[email protected]"

},

"stayStart": "2017-09-04",

"stayEnd": "2017-09-06",

"price": {

"amount": "67.80",

"currency": "EUR"

}

}

Page 6: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

XML Message

<booking>

<bookingId>456ab773-dccb-4bc9-87b7-322ff5c29eab</bookingId>

<bookingNumber>CDG-64453</bookingNumber>

<locationId>563890</locationId>

<customer>

<id>8943</id>

<email>[email protected]</email>

</customer>

<stayStart>2017-09-04</stayStart>

<stayEnd>2017-09-06</stayEnd>

<price>

<amount>67.80</amount>

<currency>EUR</currency>

</price>

</booking>

Page 7: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Payload and Attributes

Key/value pairs

With business meaning: CustomerId=6445

MessageType=NewBooking

With technical meaning: SourceHost=ip-12-34-56-78.us-west-2.compute.internal

ProgramName=WebServer-PID:9989

Page 8: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Queues

Page 9: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Simple Queue Service (Amazon SQS):

Standard Queue

4

3

3

5

2

1

Page 10: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Simple Queue Service (Amazon SQS):

Standard Queue

4

3

3

5

2

1

Page 11: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Simple Queue Service (Amazon SQS):

Standard Queue

4

3

3

5

2

1

Page 12: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Simple Queue Service (Amazon SQS):

Standard Queue

4

3

3

5

2

1

Page 13: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Simple Queue Service (Amazon SQS):

FIFO Queue

4

C

3

B

2 1

A

IV III II I

Page 14: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Pub/Sub Messaging

Page 15: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Simple Notification Service

(Amazon SNS)

Publisher

Lambda

SQS

HTTP

Subscriber

SNS Topic

Page 16: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Streams

Page 17: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Amazon Kinesis

Page 18: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Service to Service Communication

Internet Load balancer Web servers

Page 19: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Service to Service Communication

Internet Load balancer Load balancerWeb servers Booking service

Page 20: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Service to Service Communication

Internet Load balancer Load balancerWeb servers Booking service Database

Page 21: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Capacity Imbalance

Internet Load balancer Load balancerWeb servers Booking service Database

Page 22: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Overload

Internet Load balancer Load balancerWeb servers Booking service Database

Page 23: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Queue as a Safe and Fast Buffer

Internet Load balancer Booking queueWeb servers Booking service Database

Page 24: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Demo

Page 25: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Improving Synchronous Latency

Booking takes up to 3 seconds, it’s too slow!

Page 26: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Improving Synchronous Latency

Booking takes up to 3 seconds, it’s too slow!

Let’s break it down:

Change status in database 30 ms

Notify external booking supplier 800 ms

Prepare a PDF invoice 900 ms

Send a confirmation e-mail with large PDF 500 ms

Page 27: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Use Background Thread

Synchronous:

Background thread:

Change status in database 30 ms

Notify external booking supplier 800 ms

Prepare a PDF invoice 900 ms

Send a confirmation e-mail with large PDF 500 ms

Page 28: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Use Background Thread

Synchronous:

Background thread:

Work can get lost!

Change status in database 30 ms

Notify external booking supplier 800 ms

Prepare a PDF invoice 900 ms

Send a confirmation e-mail with large PDF 500 ms

Page 29: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Safe Asynchronous Tasks

Synchronous:

Background poller:

Change status in database 30 ms

Store task in queue 10 ms

Get next task from queue 10 ms

Notify external booking supplier 800 ms

Prepare a PDF invoice 900 ms

Send a confirmation e-mail with large PDF 500 ms

Delete task from queue 10 ms

Page 30: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Private Task Queues

Task queuesBooking service

Page 31: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Shared Task Queue

Task queueBooking service

Page 32: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Microservices

Booking service

Email notification service

External partner integration service

Financial ledger queue

Payment processing service

Page 33: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Notify Everyone!

Booking service

Email notification service

External partner integration service

Financial ledger queue

Payment processing service

New booking

completed!

Page 34: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Notify Everyone!

Booking service

Email notification service

External partner integration service

Financial ledger queue

Payment processing service

New booking

completed!

Page 35: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Decouple by Publishing Event through SNS

Booking service Booking topic

Email notification service

External partner integration service

Financial ledger queue

Payment processing service

Page 36: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Decouple by Publishing Event through SNS

Booking service Booking topic

Email notification service

External partner integration service

Financial ledger queue

Payment processing service

New booking

completed!

Page 37: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Decouple by Publishing Event through SNS

Booking service Booking topic

Email notification service

External partner integration service

Financial ledger queue

Payment processing service

Page 38: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Queues in SQS

Long polling:

instant push

deliveries of

messages

Page 39: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Queues in SQS

Long polling:

instant push

deliveries of

messages

Server side

encryption

Page 40: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Queues in SQS

Long polling:

instant push

deliveries of

messages

Server side

encryption

Dead letter

queues

Page 41: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Queues in SQS

Long polling:

instant push

deliveries of

messages

Server side

encryption

Dead letter

queues

Easy monitoring

with CloudWatch,

with alarming

Page 42: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Queues in SQS

Long polling:

instant push

deliveries of

messages

Server side

encryption

Dead letter

queues

Easy monitoring

with CloudWatch,

with alarming

Integrated with

other AWS

services as a

destination

Page 43: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Pub/Sub messaging in SNS

Multiple

transports

Page 44: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Pub/Sub messaging in SNS

Multiple

transports

Customizable

delivery retries for

HTTP

Page 45: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Pub/Sub messaging in SNS

Multiple

transports

Customizable

delivery retries for

HTTP

Failure

notifications

Page 46: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Pub/Sub messaging in SNS

Multiple

transports

Customizable

delivery retries for

HTTP

Failure

notifications

Easy monitoring

with CloudWatch,

with alarming

Page 47: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

There’s more! Pub/Sub messaging in SNS

Multiple

transports

Customizable

delivery retries for

HTTP

Failure

notifications

Easy monitoring

with CloudWatch,

with alarming

Integrated with

other AWS

services as a

destination

Page 48: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Enterprises using Amazon SQS and SNS

BMWJohnson &

JohnsonNordstrom

Page 49: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

For more information

www.aws.amazon.com/sqs

www.aws.amazon.com/sns

Page 50: Decouple and Scale Applications Using Amazon SQS and Amazon SNS - July 2017 AWS Online Tech Talks

Thank you!