+ All Categories
Home > Documents > Microserviceson AWS: Architectural Patterns and Best Practices... · • Data source integrations...

Microserviceson AWS: Architectural Patterns and Best Practices... · • Data source integrations...

Date post: 25-Mar-2020
Category:
Upload: others
View: 16 times
Download: 0 times
Share this document with a friend
44
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. SUMMIT Microservices on AWS: Architectural Patterns and Best Practices Sascha Möllering Senior Solutions Architect Amazon Web Service EMEA SARL SessionID
Transcript

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Microservices on AWS: Architectural Patterns and Best PracticesSascha MölleringSenior Solutions ArchitectAmazon Web Service EMEA SARL

S e s s i o n I D

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Agenda

Options for architecting your microservices

Serverless best practices

Containers best practices

Serverless and containers combined

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Related breakouts

Observability for Modern ApplicationsChristoph Kassen

Extending EKS with open source toolsRic Harvey

Best Practices for Safe Deployments on AWS Lambda and Amazon API Gateway

Danilo Poccia

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

When the impact of change is small,release velocity can increase

MonolithDoes everything

MicroservicesDoes one thing

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

MICROSERVICE API

API MICROSERVICE

MICROSERVICEEVEN

T

APIMICROSERVICE

EVENT

API MICROSERVICE

APPLICATION

Mobile client

Client

IoT

PERSISTENCE PERSISTENCE

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Options for architecting your microservices

AWS Lambda

Amazon EKS

Amazon ECS

AWS Fargate

Containers Serverless

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Containers: ECS, EKS, Fargate• Portability• Control• Rich ecosystem

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Serverless: Lambda• Event-driven framework• Multiple invocation models• Opinionated

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

What is serverless?

No infrastructure provisioning, no management

Automatic scaling

Pay for value Highly available and secure

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Comparison of operational responsibility

AWS LambdaServerless functions

AWS FargateServerless containers

ECS/EKSContainer-management as a service

EC2Infrastructure-as-a-Service

More opinionated

Less opinionated

AWS manages Customer manages

• Data source integrations• Physical hardware, software, networking,

and facilities• Provisioning

• Application code

• Container orchestration, provisioning• Cluster scaling• Physical hardware, host OS/kernel,

networking, and facilities

• Application code• Data source integrations• Security config and updates, network config,

management tasks

• Container orchestration control plane• Physical hardware software,

networking, and facilities

• Application code• Data source integrations• Work clusters• Security config and updates, network config,

firewall, management tasks

• Physical hardware software, networking, and facilities

• Application code• Data source integrations• Scaling• Security config and updates, network config,

management tasks• Provisioning, managing scaling and

patching of servers

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

What if I can’t decide?

Lambda Function

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Inter-container communication*

or storage-intensive?

Desire orchestration portability OR open

source fan? Amazon EKS

Are you comfortable managing your own

infrastructure?Amazon ECSAWS Fargate

Deployment Package size

<= 50MB

Desired Service runtime <= 15

minutes?

AWS Lambda

Decision Tree – well, almost!

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Most important!

• Ask yourself: do you really need containers?• Start with a serverless approach!• Switch to containers if necessary!

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

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

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Lambda considerations and best practices

Can your Lambda functions survive the cold?

• AWS clients and database clients outside the scope of the handler

• CloudWatch Events for warmth• VPC support: ENI attached (cold start)

import sys import logging import rds_configimport pymysql

rds_host = "rds-instance" db_name = rds_config.db_nametry:

conn = pymysql.connect( except:

logger.error("ERROR:def handler(event, context):

with conn.cursor() as cur:

Executes with each invocation

Executes during cold start

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Lambda Best Practices

• Minimize package size • Separate the Lambda handler from core logic• Use Environment Variables to modify operational behavior• Self-contain dependencies• Leverage “Max Memory Used” to right-size your functions

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Stream processing characteristics

• High ingest rate• Near real-time processing• Spiky traffic• Message durability and ordering

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Streaming data ingestion

Delivery metrics

Buffered files

Table loads

Domain loads

Source record backup

Transformations &enrichment Lookup tables

Raw records

Lookup

Transformed records

Transformed records

Raw records

Delivery stream

ProducersGroup

KinesisAgent

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Best practices

• Tune Firehose buffer size and buffer interval

• Enable compression

• Enable Source Record Backup

• Amazon Redshift Best Practices for Loading Data

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Amazon Kinesis Data Streams and AWS Lambda

• Number of Amazon Kinesis Streams shards corresponds to concurrent invocations of Lambda function

• Batch size = max number of records per Lambda function invocation

Data Stream Processor function

Streaming source Other AWS services

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Fan-out pattern

Strict message ordering vs higher throughput & lower latency

Data Stream Dispatcher function Processor function

Increase throughput, reduce processing latency

Streaming source

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Think about your applications‘ needs

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Optimizing your container

• Optimize for smaller size

• Use a minimalist operating system

• Not all runtimes are equal!

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Popular base images have a huge range by size

REPOSITORY SIZEnode:latest 674MBjava:latest 643MBnode:slim 184MBubuntu:latest 85.8MBalpine:latest 4.41MBbusybox:latest 1.15MB

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Multi-stage Docker build

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Multi-stage Docker build

1

2

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Multi-stage Docker build

1

2

3

4

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Optimize pods

• How many sidecar containers?

• Admission controllers add overhead!

• Keep pods lightweight!

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Optimize pod placement

Make sure you use resource constraints:

• Request the baseline average resource needs of the app

• Put a limit on the max resources of a pod

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

New: Lambda Layers

• Share code between functions (crosscutting concerns)

• Promote separation of responsibilities

• Built in support for secure sharing by ecosystem

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

New: Custom Runtimes

Bring any Linux compatible language runtime

Powered by new Runtime API

Custom runtimes distributed as “layers”

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

AWS Lambda Container Image Convertercd example

docker build -t lambda-php .

./bin/local/img2lambda -i lambda-php:latest -r us-east-1

https://github.com/awslabs/aws-lambda-container-image-converter

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

MICROSERVICE API

API MICROSERVICE

MICROSERVICE

EVENT

APIMICROSERVICE

EVENT

API MICROSERVICE

APPLICATION

Mobile client

Client

IoT

PERSISTENCE PERSISTENCE

Go build something!

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T

Thank you!

S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Sascha Mö[email protected]: @sascha242

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I TS U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.


Recommended