serverless tales from the trenches · iaas paas serverless unit of scale virtual machine or...

40
1 Serverless Tales from the Trenches

Upload: others

Post on 21-May-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

1

Serverless Tales from the Trenches

Page 2: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

AuthorServerless Architectures on AWS

https://book.acloud.guru

VP Engineering | VP ContentA Cloud Guru

https://acloud.guru

Peter Sbarski, PhDAWS Community Hero

@sbarski

OrganizerServerlessconf

https://serverlessconf.io

Page 3: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

3

Page 4: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer
Page 5: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

IaaS PaaS Serverless

Unit of Scale Virtual Machine or Container (Docker)

Application Function

Fleet Operational Responsibility

Application developer Shared between developer and vendor

Vendor only

Required Management & Maintenance

High – Operating System level

Medium – Application level

Low – function level

Billing Per VM per minute or hour

Per VM per minute or hour

Per 100 milliseconds (continuous)

Impact of Idle Time Economic loss when machines are idle or underused

Economic loss when machines are idle or underused

None – functions execute only when needed

Integration with other vendor services

Manual Mixed Automatic

Source: Serverless Design Patterns (T. Wagner, Y. Kiriaty, P. Sbarski)

Why Serverless?

Page 6: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer
Page 7: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer
Page 8: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Service Cost

API Gateway $100.00

Lambda $206.66

DynamoDB $424.27

Elastic Transcoder $169.89

Kinesis $20.16

Redshift $503.50

Simple Storage Service $58.36

Developer Support $178.74

CloudWatch $586.24

CloudFront $3,775.42

Total $6,023.24

February 2018

Page 9: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

GraphQL EndpointAPI Gateway

Microservice #B

DynamoDB

CloudFront S3

Microservice #A

DynamoDB

Page 10: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Other Services

Jester

Cypress

Page 11: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Serverless Stories

Frontend and API Failover

Making functions & services more resilient

Patterns and architectures

Page 12: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Frontend Failover

Page 13: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Frontend Failover

Page 14: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Frontend Failover

Route 53User

CloudFront S3 Bucket

Health Check

Primary Website

Backup Website

Check health every few seconds

Page 15: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Frontend Failover

Page 16: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Frontend Failover

Page 17: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Frontend Failover

Page 18: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Failover

Page 19: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Failover

Route 53User

Health Check

API Gateway

API Gateway

US East 1

US West 1

Lambda

Lambda

DynamoDBGlobal Tables

Page 20: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Failover

API Gateway – US East 1 API Gateway – US West 1

Page 21: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Failover

Page 22: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Failover

Page 23: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Failover

Page 24: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Making functions & services more resilient

Page 25: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Handling Errors

Peter uploads a file

LambdaFirebase (Database)

Source S3 Bucket Lambda Elastic Transcoder

Destination S3SNS

LambdaDestination S3 Lambda

Page 26: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Handling Errors

Peter uploads a file

LambdaFirebase (Database)

Source S3 Bucket Lambda Elastic Transcoder

Destination S3SNS

Dead Letter Queue

(SNS)

Error!

Error!

Lambda

Page 27: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Burning down the house

Page 28: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Burning down the house

You might still over provision or under provision DB connections

Multiple functions may need DB access with different usage profiles at different times.

Page 29: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Burning down the house

https://github.com/aws-samples/aws-lambda-manage-rds-connections

Page 30: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Tips• 1 function = 1 task (avoid fat monoliths)

• No state (be idempotent)

• Design for failure

• More memory = more CPU and IO

• Set function concurrency to 0 as a kill switch

• Keep permissions and roles tight

• Incremental architecture is not dirty

Page 31: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Patterns and Architectures

Page 32: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Primitive- Periodical (Cron Jobs)

API- Proxy- Facade

Orchestration- One way chain- Two way chain- Fan in- Fan out

Workflows- Long Running tasks - Pipes and Filters- Inline Stream Transform

Traditional- Command- Singleton

Compound- Backends- CQRS- Data processing

Patterns

Source: Serverless Design Patterns (T. Wagner, Y. Kiriaty, P. Sbarski)

Page 33: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Patterns

NameAPI Proxy (also known as wrapper)

DescriptionActs as a mediator between two systems that cannot communicate directly. Transforms request and response payloads to facilitate exchange of information.

MotivationUseful when incompatible systems need to talk. Reduces coupling by removing the need to build direct dependencies between incompatible systems.

Page 34: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

API Proxy

System A (JSON) Transformation FunctionAPI Gateway System B (XML)

Transformer function transforms JSON to XML and back again.

Page 35: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Patterns

NameSimple fan-out

DescriptionAllows multiple endpoints to receive a copy of an input event. Turns any single-receiver delivery system into a multiple-receiver system.

MotivationEvent-based systems are often designed to have a single receiver for events, and API calls are by definition single receiver. The simple fan-out pattern asynchronously delivers its triggering event to one or more workers.

Page 36: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Simple fan-out

How would you design transactional fan-out?

Page 37: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Patterns

NameInline stream transform

DescriptionTransmits data between systems. Can be chained, can multiple and demultiplexat the source or destination. A transformation function can transform a record with the result progressing through the stream.

MotivationA way to decouple systems that share data. Can offer temporal decoupling by allowing producers and consumers to operate at different rates. A transform function is used to clean, modify, group, analyze data before it gets to the consumer.

Page 38: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Streams

Producer A

Consumer

Same Stream

STREAM

Transformation Function

STREAM

Consumer A stream can be shardedif order is not important

Page 39: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

39

How can you get started?

• serverlessconf.io & video.serverlessconf.io

• Follow @serverlessconf for serverlessconf info

• A Cloud Guru acloud.guru/serverless

• Book: “Serverless Architectures on AWS”https://book.acloud.guru

• Follow @acloudguru and @sbarski

Page 40: Serverless Tales from the Trenches · IaaS PaaS Serverless Unit of Scale Virtual Machine or Container (Docker) Application Function Fleet Operational Responsibility Application developer

Thanks :-)

https://acloud.guru

https://serverlessconf.io

@sbarski