Reactive Microservices Architecture
on AWS
Sascha Möllering
Solutions Architect, @sascha242, Amazon Web Services Germany GmbH
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Why are we
here today?
https://secure.flickr.com/photos/mgifford/4525333972
Agenda
What is Reactive Architecture?
How to build Reactive Architectures on AWS?
Application Architecture
Deployment
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What is Reactive Architecture?
What is Reactive Architecture?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
N-Tier architecture
Frontend Storage
Servers API
User waits
for update Poll Poll
Queries
Database
Synchronous
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Software moves
faster today
Traditional style of
applications cannot deliver
on these requirements any
longer
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reactive Applications
Responsive
Elastic Resilient
Message-driven
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reactive Architecture
Reactive programming Reactive system
“A development model focusing “An architecture style used to
on the observation of data build responsive and robust
streams, reacting on changes, distributed systems based on
and propagating them.” asynchronous message-
passing.”
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reactive Architecture
• Asynchronous message passing
• Non-blocking
• Higher throughput
• Efficient compute utilization and lower costs
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reactive Architecture
• Loosely coupled
• Location independent
• Easy to extend and maintain
• Push-based
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Microservices
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Microservices should be
stateless.
Keep state in managed services.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
No shared libraries or
shared SDKs.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Avoid
Host-Affinity.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Use lightweight
protocols for
communication.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Use mechanisms for
registration.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How to build Reactive Architectures
on AWS?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Example use case
Banner
Customer visits Customer clicks Customer buys
website on a banner from online-shop
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
High Level Architecture
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data Collection
Amazon Elastic
Container Registry
Application Amazon Elastic Amazon AWS Amazon
Data ingestion
Load Balancer Container Service Kinesis Data Lambda DynamoDB
Streams
Core data updates
AWS Amazon Core data
Amazon
Lambda Kinesis Data update
ElastiCache
Streams
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
High Level Architecture
• Amazon ECS and Docker used for the main
application
• Fargate launch type
• Resiliency and elasticity implemented by
using auto scaling
Amazon Elastic
Container Service
© 2018, 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
AWS Lambda
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
High Level Architecture
• Amazon Kinesis Data Streams used to
decouple components
• Asynchronously push event data to NoSQL-
store
• Update core-data in Redis
Amazon Kinesis
Data Streams
© 2018, 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
Amazon ElastiCache
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
High Level Architecture
• Amazon DynamoDB NoSQL-store used to
persist event-data
• Backup and restore
• Encryption at rest
Amazon DynamoDB
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data Collection
Amazon Elastic
You are here now!
Container Registry
Application Amazon Elastic Amazon AWS Amazon
Data ingestion
Load Balancer Container Service Kinesis Data Lambda DynamoDB
Streams
Core data updates
AWS Amazon Core data
Amazon
Lambda Kinesis Data update
ElastiCache
Streams
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
Source: http://vertx.io/docs/guide-for-java-devs/
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
Source: http://vertx.io/docs/guide-for-java-devs/
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
Source: http://vertx.io/docs/guide-for-java-devs/
© 2018, 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 Data
Stream
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Subscribe to event bus
Convert data
Send data to Kinesis stream
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Consume
Subscribe to EB
data from
event bus
Send data to
cache verticle
Subscribe to
Redis channel
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data Collection You are here now!
Amazon Elastic
Container Registry
Application Amazon Elastic Amazon AWS Amazon
Data ingestion
Load Balancer Container Service Kinesis Data Lambda DynamoDB
Streams
Core data updates
AWS Amazon Core data
Amazon
Lambda Kinesis Data update
ElastiCache
Streams
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application Architecture
AWS Lambda
© 2018, 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Iterate over
batch of events
Unmarshal
protobuf messages
Map to struct
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Design principles
• Use push instead of pull
• Avoid blocking calls
• Decouple your services using async message passing
• Keep state in managed services
• Use caching
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Deployment
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Deployment
AWS CloudFormation
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
S3 Bucket
and
Lambda function filename
configuration
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Network
mode
ECS
Launch
Type
CPU and
RAM
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Go build something!
Amazon API AWS Lambda Amazon
Gateway DynamoDB
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Related Sessions
Container-based Architectures on AWS (Blackfoot)
Kubernetes Running on AWS (Blackfoot)
Serverless Architectural Patterns (Amelia)
Deep Dive into Concepts and Tools for Analyzing
Streaming Data on AWS (Coral)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Question? Ask this guy
at the Ask an Architect
booth:
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Please complete the session
survey in the summit mobile app.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.