48
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sascha Möllering, Solutions Architect, @sascha242 07.11.2017 Reactive Architectures with Microservices

Reactive Architectures with Microservices

Embed Size (px)

Citation preview

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

Sascha Möllering, Solutions Architect, @sascha242

07.11.2017

Reactive Architectures with Microservices

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

https://secure.flickr.com/photos/mgifford/4525333972

Why are we here today?

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

Agenda

• What is Reactive Architecture?• How to build Reactive Architectures in AWS?• Application Architecture• Global Rollout• Q&A

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

What is Reactive Architecture?

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

Front-end server

Internal APIInternal

APIAPI

Poll

Poll

Database

Storage

Queries

Synchronous

User waits for update

N-Tier architecture

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

Software moves faster today

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

Traditional style of applications cannot deliver on these requirements any

longer

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

Responsive

Elastic Resilient

Message-driven

Reactive Applications

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

Reactive programming“A development model focusing on the observation of data streams, reacting on changes, and propagating them”

Reactive Architecture

Reactive system“An architecture style used to build responsive and robust distributed systems based on asynchronous message-passing.”

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

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

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

Microservices

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

Microservices should be stateless.

Keep state in external systems.

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

AvoidHost-Affinity.

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

Use lightweight protocols for

communication.

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

Use mechanisms for registration.

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

How to build Reactive Architectures in AWS?

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

Example use case

Banner

Icon made by Freepik from www.flaticon.com

Customer visits website

Customer clickson a banner

Customer buysfrom online-shop

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

High Level Architecture

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

Amazon ECSApplication Load Balancer

Amazon ECR

Kinesis Stream

Kinesis Stream

Lambda function

Lambda function

ElastiCachecluster

Data ingestion

Core data update

Amazon DynamoDB

Core data updates

Data collection

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

High Level Architecture

• Amazon ECS and Docker used for the main application

• Resiliency and Elasticity implemented by using Auto Scaling

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

High Level Architecture

• AWS Lambda functions• Consume messages• Persist data in NoSQL-store• Update core-data in Redis• Send notifications to main application• Resiliency and Scalability part of the service

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

High Level Architecture

• Amazon Kinesis Streams used to decouple components

• Asynchronously push event data to NoSQL-store

• Update core-data in Redis

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

High Level Architecture

• Amazon ElastiCache with Redis 3 engine• Multi-AZ setup with failover and one shard• Used to store core-data • Notification channel

• Redis supports pub/sub

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

High Level Architecture

• Amazon DynamoDB NoSQL-store used to persist event-data

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

Application Architecture

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

Amazon ECSApplication Load Balancer

Amazon ECR

Kinesis Stream

Kinesis Stream

Lambda function

Lambda function

ElastiCachecluster

Data ingestion

Core data update

Amazon DynamoDB

Core data updates

Data collectionYou are here now!

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

Application Architecture

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

Application Architecture

Picture source: http://vertx.io/docs/guide-for-java-devs/

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

Application Architecture

“Don’t block the event loop!”

- Vert.x golden rule

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

Application Architecture

Picture source: http://vertx.io/docs/guide-for-java-devs/

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

Application Architecture

Picture source: http://vertx.io/docs/guide-for-java-devs/

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

Application Architecture

• HttpVerticle: exposes HTTP endpoint• CacheVerticle: implements L1 cache• RedisVerticle: implements Redis access• KinesisVerticle: messages to Amazon Kinesis Stream

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

Subscribe to EB

Send prepared data

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

Application Architecture

CacheRulesEverythingAroundMe

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

Subscribe to EB

Subscribe to Redis channel

Consume data from event bus

Send data to cache verticle

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

Amazon ECSApplication Load Balancer

Amazon ECR

Kinesis Stream

Kinesis Stream

Lambda function

Lambda function

ElastiCachecluster

Data ingestion

Core data update

Amazon DynamoDB

Core data updates

Data collection You are here now!

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

Application Architecture

AWS Lambda

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

Lambda considerations and best practices

AWS Lambda is stateless—architect accordingly• Assume no affinity with underlying compute

infrastructure• Local filesystem access and child process may not

extend beyond the lifetime of the Lambda request

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

Kinesis event processing

Iterate over batch of events

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

Global Rollout

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

16 Regions44 Availability Zones

AWS Global Infrastructure

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

Global Rollout

AWS CloudFormation

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

Global Rollout

• Infrastructure as Code• Create and manage resources with CloudFormation

templates• CloudFormation template is used to deploy stacks

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

Global Rollout

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

Master Region• One stream of data• One region to process data• Data has to be transferred

inter region

Global Rollout

Distributed Processing• Data processing in every

region• No unified view on data

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

Summary

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

Summary

• Reactive Architectures very good fit for AWS Cloud• Microservices improve isolation • AWS offers a lot of services for decoupled application

design• Focus on business requirements, don’t reinvent the

wheel

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

Thank you!