aws re:invent 2016: running lean architectures: how to optimize for cost efficiency (arc313)

57
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Markus Ostertag, Head of Development, Team Internet AG, @osterjour Constantin Gonzalez, Principal Solutions Architect, AWS, @zalez November 30, 2016 Running Lean Architectures How to Optimize for Cost Efficiency ARC313

Upload: amazon-web-services

Post on 06-Jan-2017

174 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

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

Markus Ostertag, Head of Development, Team Internet AG, @osterjour

Constantin Gonzalez, Principal Solutions Architect, AWS, @zalez

November 30, 2016

Running Lean ArchitecturesHow to Optimize for Cost Efficiency

ARC313

Page 2: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

What you’ll get out of this session

• Best practices on how to lower your AWS bill

• A more scalable, robust, dynamic architecture

• More time to innovate

• Real-world customer examples

• Easy to implement

Page 3: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Structure

Business

Architecture

Operations

Page 4: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Business Goals

“Pay as little as possible

for what we use.”

Page 5: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS pricing philosophy

Ecosystem

Global Footprint

New Features

New Services

More AWS

Usage

More

Infrastructure

Lower

Infrastructure

Costs

Reduced

Prices

More

CustomersInfrastructure

Innovation

57 price reductions

since 2006

Economies

of Scale

Page 6: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS TCO calculator

Page 7: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS simple monthly calculator

Page 8: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS billing alerts

Page 9: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS billing console

Page 10: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS Trusted Advisoraws.amazon.com/premiumsupport/trustedadvisor/

Free with Business or Enterprise Support

Page 11: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Free Trusted Advisor Trial!

• Free trial begins on 12/6/16

• Runs for 30 days

• Full suite of checks and best practice

recommendations available

• For customers not already on

business/enterprise support plans

• No action required:

Just log in and start using!

https://console.aws.amazon.com/trustedadvisor

Page 12: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Reserved Instances

Page 13: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Reserved Instances basics

1y RI

Break even

3y RI

Break even

Page 14: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Markus OstertagHead of Development @ Team Internet

Page 15: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Who is Team Internet?

Domain monetization business

30 people

HQ in Munich, Germany

Tech focused

Page 16: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Reserved Instances

Page 17: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Reserved Instances – our usage

Page 18: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Use the regional benefit

Change existing Reserved Instances to scope “Region”

Capacity reservation decoupled from cost optimization

Page 19: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Convertible Reserved Instances

Use case: “(Very) Long running, but flexible”

Page 20: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Architecture Goals

“Avoid waste as much

as possible.”

Page 21: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Turn off unused instances

• Developer, test, training instances

• Use simple instance start and stop

• Or tear down and build up all together

using AWS CloudFormation

• Instances are disposable!

Page 22: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Customer example

Monday Friday End of Vacation Season35% saved

Page 23: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Automate, automate, automate

• AWS SDKs

• AWS CLI

• AWS CloudFormation

• AWS OpsWorks

• Netflix Janitor Monkey

• Cloudlytics EC2 Scheduler

• Auto Scaling

Page 24: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

How Auto Scaling works

Page 25: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS CloudFormation example launch configuration

"LaunchConfig": {

"Type" : "AWS::AutoScaling::LaunchConfiguration",

"Metadata" : {

"AWS::CloudFormation::Init" : {

"config" : {

… packages, sources, files, services …

}

}

},

"Properties": {

"ImageId" : "ami-149f7863",

"InstanceType" : "m1.small",

"SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ],

"KeyName" : "MySSHKey",

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [

"#!/bin/bash -v\n",

… your user data script …

]]}}

}

}

Page 26: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS CloudFormation exampleAuto Scaling group definition

"WebServerGroup" : {

"Type" : "AWS::AutoScaling::AutoScalingGroup",

"Properties" : {

"AvailabilityZones" : [

"us-east-1a","us-east-1b","us-east-1c",

],

"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },

"MinSize" : “3",

"MaxSize" : “6",

"DesiredCapacity" : “3",

"LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ]

}

}

Page 27: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Align resources with demand

Page 28: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Use Spot Instances

• Price based on supply/demand

• You choose your maximum price/hour

• Your instance is started if the Spot price is lower

• Your instance is terminated if

the Spot price is higher, with 2 minutes notice

• But: You did plan for fault tolerance, didn’t you?

Page 29: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Spot Instance example

On-Demand:

$0.24

$0.028 (11.7%) $0.026 (10,8%)

$3.28

(1367%)

Page 30: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Spot Instance use cases

• Stateless Web/App server fleets

• Amazon EMR

• Continuous Integration (CI)

• High Performance Computing (HPC)

• Grid Computing

• Media Rendering/Transcoding

aws.amazon.com/ec2/spot

Page 31: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Spot Bid Advisor

Page 32: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Spot Instances recap

• Very dynamic pricing

• Opportunity to save 80-90% cost• But there are risks

• Different prices per AZ

• Leverage Auto Scaling!• One group with Spot Instances

• One group with On-Demand

• Get the best of both worlds

• Spot fleets – Manage thousands of

Spot Instances with one API call

Page 33: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

“But my applications are

too small

for Auto Scaling!”

Page 34: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Amazon EC2 Container Service

• Easily manage Docker containers

• Flexible container placement

• Designed for use with other AWS services

• Extensible

• Performance at Scale

• Secure

Page 35: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

10%

15%

7%

12%

20%

9%

Consolidate with Amazon ECS

App 1 App 2

App 3 App 4

App 5 App 6

6

12 345

Amazon ECS

cluster

Page 36: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

AWS Lambda

Amazon S3 bucket events AWS Lambda

Original object Compressed object

1

2

3

Page 37: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Get rid of idle time with AWS Lambda

• Automatic scaling

• Automatic provisioning

• No need to manage infrastructure

• Just bring your code

• $0.20 per million requests, 1M free

• 100 ms payment granularity

• Never pay for idle

Less than 40% utilization?

Consider using AWS Lambda instead!

Page 38: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Optimizing database utilization

Page 39: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Database optimization through caching

DynamoDB Amazon RDS DynamoDB Amazon RDS

ElastiCache

Page 40: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Caching saves money

DynamoDB reads

Saved 3k reads per second (>20k reads per second in total)

Page 41: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Cache really everything!

Cache hit ratio 25-30% Cache hit ratio 89-95%

Without negative caching With negative caching

Hit

Miss

Page 42: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Cache invalidation

“There are only two hard things in Computer Science:

cache invalidation and naming things” -- Phil Karlton

Two ways to cache:

Time to Live (TTL) with invalidation

Keep the cache in sync all the time

Page 43: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Synchronous writes

Sync/check in the app with after-write return values

DynamoDB

ElastiCache

write/update always

write/update always

Page 44: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Uncoupled writes/invalidation

Sync/updates via Lambda (uncoupled)

DynamoDB

ElastiCache

write/update always

no update

LambdaDynamoDB

Stream

update

Page 45: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Think of strategies for optimizing CU use

• Use multiple tables to support varied access patterns

• Understand access patterns for time series data

• Compress large attribute values

Consider read (4K) vs. write (1K) sizes

Use Amazon SQS to buffer over-capacity writes

Resize capacity units dynamically

Page 46: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Amazon SQS can buffer requests

Page 47: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Dynamic DynamoDB

Page 48: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Offload popular traffic to

Amazon S3 and/or Amazon CloudFront

Page 49: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Operational Goals

“Focus on what you do best,

let AWS do the rest.”

Page 50: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Leverage existing services

• Use Amazon RDS, DynamoDB,

ElastiCache for Redis or

Amazon Redshift

• Instead of running your own database

• Amazon Elasticsearch Service• Instead of running your own cluster

• Amazon SQS

• Amazon Kinesis,

Amazon Kinesis Firehose, Amazon SNS, and more …

AWS has experts for each service

RDSAmazon Redshift

Amazon

Elasticsearch

Service

Amazon KinesisSQS

Page 51: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

DynamoDB

Pick the right tool for the job

Key/Value

Scalable

throughput

Low latency

Amazon Aurora

More complex

data/queries

Scalable

storage

Amazon

Redshift

Big (complex)

data

Higher

latency

ElastiCache

for Redis

Key/Value

In-Memory

(Very) low

latency

Page 52: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

There is not one database to rule them all

MongoDB

Tracking

API

RTB

Engine

User&Stats

API

Tracking

API

RTB

Engine

DynamoDB

Decoupled

Amazon

Aurora

Amazon

Redshift

User&Stats

API

Page 53: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Advantages

• No undifferentiated heavy lifting

(= cost savings)

• AWS operates the DB

infrastructure for us

• Simple and more granular scale out

• No interference between

RTB/Tracking and User/Stats

Page 54: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Let’s recap

1. Use AWS TCO/cost/billing tools

2. Use Reserved Instances

3. Avoid idle instances through automation

4. Use Spot Instances

5. Optimize database utilization

6. Pick the right tool for the job

7. Offload your architecture

Page 55: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

But wait! There’s even more!

https://youtu.be/SG1DsYgeGEk

AWS re:Invent 2015

ARC302 Running Lean Architectures: Optimizing for Cost Efficiency

• DynamoDB GSI Tweaking

• Using CloudFront to avoid

multi-region setups

• Amazon S3 storage tiering

• … and much more!

Page 56: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Thank you!

Page 57: AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Efficiency (ARC313)

Remember to complete

your evaluations!