serverless in production (o'reilly software architecture)

218
Serverless in production an experience report Yan Cui

Upload: yan-cui

Post on 21-Jan-2018

705 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Serverless in production (O'Reilly Software Architecture)

Serverless in production an experience report

Yan Cui

Page 2: Serverless in production (O'Reilly Software Architecture)

What’s in this talk?

! how to responsibly run a serverless architecture (aka. how to do ops in serverless)

! testing, CI/CD! logging, distributed tracing, monitoring! config management, securing secrets! coldstarts! gotchas/limitations + workarounds/hacks

Page 3: Serverless in production (O'Reilly Software Architecture)

hi, I’m Yan Cui

Page 4: Serverless in production (O'Reilly Software Architecture)

hi, I’m Yan CuiAWS user since 2009

Page 5: Serverless in production (O'Reilly Software Architecture)
Page 6: Serverless in production (O'Reilly Software Architecture)
Page 7: Serverless in production (O'Reilly Software Architecture)
Page 8: Serverless in production (O'Reilly Software Architecture)
Page 9: Serverless in production (O'Reilly Software Architecture)
Page 10: Serverless in production (O'Reilly Software Architecture)
Page 11: Serverless in production (O'Reilly Software Architecture)
Page 12: Serverless in production (O'Reilly Software Architecture)

apr, 2016

Page 13: Serverless in production (O'Reilly Software Architecture)

Before

! hidden complexities and dependencies! low utilisation to leave headroom for large spikes! EC2 scaling is slow, so scale earlier! paying for lots of used resources! up to 30 mins to deploy! deployments required downtime

Page 14: Serverless in production (O'Reilly Software Architecture)

- Dan North

“lead time to someone saying thank you is the only reputation

metric that matters.”

Page 15: Serverless in production (O'Reilly Software Architecture)
Page 16: Serverless in production (O'Reilly Software Architecture)

“what would good look like for us?”

Page 17: Serverless in production (O'Reilly Software Architecture)

Deployments should…

! be small! be fast! have zero downtime! require no lock-step

Page 18: Serverless in production (O'Reilly Software Architecture)

Features should…

! be independently deployable! be loosely-coupled

Page 19: Serverless in production (O'Reilly Software Architecture)

We want to…

! minimise cost of unused resources! minimise ops effort! reduce technical mess! deliver visible improvements to users faster

Page 20: Serverless in production (O'Reilly Software Architecture)

nov, 2016

Page 21: Serverless in production (O'Reilly Software Architecture)

170 Lambda functions in prod

1.2 GB deployment packages in prod

95% cost saving vs EC2

15x no. of prod releases per month

Page 22: Serverless in production (O'Reilly Software Architecture)

timeis a good fit

Page 23: Serverless in production (O'Reilly Software Architecture)

1st function in prod!time

is a good fit

Page 24: Serverless in production (O'Reilly Software Architecture)

?

timeis a good fit

1st function in prod!

Page 25: Serverless in production (O'Reilly Software Architecture)

Practices ToolsPrinciples

what is good? how to make it good? with what?

Page 26: Serverless in production (O'Reilly Software Architecture)

Principles outlast Tools

Page 27: Serverless in production (O'Reilly Software Architecture)

ALERTING

CI / CD

TESTING

LOGGING

MONITORING

Page 28: Serverless in production (O'Reilly Software Architecture)

170 functions

WOOF!

? ?

timeis a good fit

1st function in prod!

Page 29: Serverless in production (O'Reilly Software Architecture)

CONFIG MANAGEMENT

SECURITY

DISTRIBUTED TRACING

Page 30: Serverless in production (O'Reilly Software Architecture)

evolving the platform

Page 31: Serverless in production (O'Reilly Software Architecture)

building a better search experience

Page 32: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearch

Page 33: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Page 34: Serverless in production (O'Reilly Software Architecture)

building an analytics pipeline

Page 35: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Google BigQuery

Page 36: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Google BigQuery1 developer, 2 daysdesign production

(his 1st serverless project)

Page 37: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Google BigQuery“thank you, nothing ever got

done this fast at Skype!”

Page 38: Serverless in production (O'Reilly Software Architecture)

- Dan North

“lead time to someone saying thank you is the only reputation

metric that matters.”

Page 39: Serverless in production (O'Reilly Software Architecture)

rebuilding the timeline feature

Page 40: Serverless in production (O'Reilly Software Architecture)
Page 41: Serverless in production (O'Reilly Software Architecture)
Page 42: Serverless in production (O'Reilly Software Architecture)
Page 43: Serverless in production (O'Reilly Software Architecture)
Page 44: Serverless in production (O'Reilly Software Architecture)
Page 45: Serverless in production (O'Reilly Software Architecture)
Page 46: Serverless in production (O'Reilly Software Architecture)

building better user recommendations

Page 47: Serverless in production (O'Reilly Software Architecture)

BigQuery

Page 48: Serverless in production (O'Reilly Software Architecture)

BigQuery

Page 49: Serverless in production (O'Reilly Software Architecture)

grapheneDB

BigQuery

Page 50: Serverless in production (O'Reilly Software Architecture)

grapheneDB

BigQuery

Page 51: Serverless in production (O'Reilly Software Architecture)

grapheneDB

BigQuery

Page 52: Serverless in production (O'Reilly Software Architecture)

getting PRODUCTION READY

Page 53: Serverless in production (O'Reilly Software Architecture)

CHOOSE A

FRAMEWORK

DEPLOYMENT

Page 54: Serverless in production (O'Reilly Software Architecture)

http://serverless.com

Page 55: Serverless in production (O'Reilly Software Architecture)

https://github.com/awslabs/serverless-application-model

Page 56: Serverless in production (O'Reilly Software Architecture)

http://apex.run

Page 57: Serverless in production (O'Reilly Software Architecture)

https://apex.github.io/up

Page 58: Serverless in production (O'Reilly Software Architecture)

https://github.com/claudiajs/claudia

Page 59: Serverless in production (O'Reilly Software Architecture)

https://github.com/Miserlou/Zappa

Page 60: Serverless in production (O'Reilly Software Architecture)

http://gosparta.io/

Page 61: Serverless in production (O'Reilly Software Architecture)

TESTING

Page 62: Serverless in production (O'Reilly Software Architecture)

amzn.to/29Lxuzu

Page 63: Serverless in production (O'Reilly Software Architecture)

Level of Testing

1.Unitdo our objects do the right thing?are they easy to work with?

Page 64: Serverless in production (O'Reilly Software Architecture)
Page 65: Serverless in production (O'Reilly Software Architecture)

1.Unit2.Integrationdoes our code work against code we can’t change?

Level of Testing

Page 66: Serverless in production (O'Reilly Software Architecture)

handler

Page 67: Serverless in production (O'Reilly Software Architecture)

handler

test by invoking the handler

Page 68: Serverless in production (O'Reilly Software Architecture)

Level of Testing

1.Unit2.Integration3.Acceptancedoes the whole system work?

Page 69: Serverless in production (O'Reilly Software Architecture)

Level of Testing

unit

integration

acceptance

feedb

ack

confidence

Page 70: Serverless in production (O'Reilly Software Architecture)

“…We find that tests that mock external libraries often need to be complex to get the code into the right state for the functionality we need to exercise.

The mess in such tests is telling us that the design isn’t right but, instead of fixing the problem by improving the code, we have to carry the extra complexity in both code and test…”

Don’t Mock Types You Can’t Change

Page 71: Serverless in production (O'Reilly Software Architecture)

“…The second risk is that we have to be sure that the behaviour we stub or mock matches what the external library will actually do…

Even if we get it right once, we have to make sure that the tests remain valid when we upgrade the libraries…”

Don’t Mock Types You Can’t Change

Page 72: Serverless in production (O'Reilly Software Architecture)

ServicesDon’t Mock Types You Can’t Change

Page 73: Serverless in production (O'Reilly Software Architecture)

Paul Johnston

The serverless approach to testing is different and

may actually be easier.http://bit.ly/2t5viwK

Page 74: Serverless in production (O'Reilly Software Architecture)

LambdaAPI Gateway DynamoDB

Page 75: Serverless in production (O'Reilly Software Architecture)

LambdaAPI Gateway DynamoDB

Unit Tests

Page 76: Serverless in production (O'Reilly Software Architecture)

LambdaAPI Gateway DynamoDB

Unit Tests

Mock/Stub

Page 77: Serverless in production (O'Reilly Software Architecture)

is our request correct?

is the request mapping set up

is the API resources configured correctly?

are we assuming the correct schema?

LambdaAPI Gateway DynamoDB

is Lambda proxy configured correctly?

is IAM policy set up correctly?

is the table created?

what unit tests will not tell you…

Page 78: Serverless in production (O'Reilly Software Architecture)
Page 79: Serverless in production (O'Reilly Software Architecture)

most Lambda functions are simple have single purpose, the risk of shipping broken

software has largely shifted to how they integrate with external services

observation

Page 80: Serverless in production (O'Reilly Software Architecture)
Page 81: Serverless in production (O'Reilly Software Architecture)

But it slows down my feedback loop…

IT’S NOT ABOUT YOU!

Page 82: Serverless in production (O'Reilly Software Architecture)

me

test your system, not (just) your code

Page 83: Serverless in production (O'Reilly Software Architecture)

API Gateway

IOT

Kinesis

SNS

ElastiCache

CloudWatch

DynamoDB

IAM

S3

Auth0

GrapheneDB

SES

Twilio

Google BigQuery

MongoLab

CloudSearch

APN

GCM

Lambda

EC2

Page 84: Serverless in production (O'Reilly Software Architecture)

…if a service can’t provide you with a relatively easy way to test the

interface in reality, then you should consider using another one.

Paul Johnston

Page 85: Serverless in production (O'Reilly Software Architecture)

“…Wherever possible, an acceptance test should exercise the system end-to-end without directly calling its internal code.

An end-to-end test interacts with the system only from the outside: through its interface…”

Testing End-to-End

Page 86: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Page 87: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Test Input

Page 88: Serverless in production (O'Reilly Software Architecture)

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Test Input

Validate

Page 89: Serverless in production (O'Reilly Software Architecture)

integration tests exercise system’s Integration with its

external dependencies

Page 90: Serverless in production (O'Reilly Software Architecture)

acceptance tests exercise system End-to-End from

the outside

Page 91: Serverless in production (O'Reilly Software Architecture)

integration tests differ from acceptance tests only in HOW the

Lambda functions are invoked

observation

Page 92: Serverless in production (O'Reilly Software Architecture)
Page 93: Serverless in production (O'Reilly Software Architecture)
Page 94: Serverless in production (O'Reilly Software Architecture)
Page 95: Serverless in production (O'Reilly Software Architecture)

CI/CD PIPELINE

Page 96: Serverless in production (O'Reilly Software Architecture)

“…We prefer to have the end-to-end tests exercise both the system and the process by which it’s built and deployed…

This sounds like a lot of effort (it is), but has to be done anyway repeatedly during the software’s lifetime…”

Testing End-to-End

Page 97: Serverless in production (O'Reilly Software Architecture)

me

Deployment scripts that only live on the CI box is a disaster

waiting to happen.

Page 98: Serverless in production (O'Reilly Software Architecture)

Jenkins build config deploys and tests

unit + integration tests

deploy

acceptance tests

Page 99: Serverless in production (O'Reilly Software Architecture)

if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4

npm install AWS_PROFILE=$PROFILE 'node_modules/.bin/sls' deploy -s $STAGE -r $REGION …

Page 100: Serverless in production (O'Reilly Software Architecture)

if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4

npm install AWS_PROFILE=$PROFILE 'node_modules/.bin/sls' deploy -s $STAGE -r $REGION …

install serverless framework as dev dependency

Page 101: Serverless in production (O'Reilly Software Architecture)

can be run locally & on the CI box

Page 102: Serverless in production (O'Reilly Software Architecture)
Page 103: Serverless in production (O'Reilly Software Architecture)

auto auto manual

Page 104: Serverless in production (O'Reilly Software Architecture)

LOGGING

Page 105: Serverless in production (O'Reilly Software Architecture)
Page 106: Serverless in production (O'Reilly Software Architecture)

2016-07-12T12:24:37.571Z 994f18f9-482b-11e6-8668-53e4eab441ae GOT is off air, what do I do now?

Page 107: Serverless in production (O'Reilly Software Architecture)

2016-07-12T12:24:37.571Z 994f18f9-482b-11e6-8668-53e4eab441ae GOT is off air, what do I do now?

UTC Timestamp API Gateway Request Id

your log message

Page 108: Serverless in production (O'Reilly Software Architecture)

function name

date

function version

Page 109: Serverless in production (O'Reilly Software Architecture)

me

Logs are not easily searchable in CloudWatch Logs.

Page 110: Serverless in production (O'Reilly Software Architecture)

LOG OVERLOAD

Page 111: Serverless in production (O'Reilly Software Architecture)

CENTRALISE LOGS

Page 112: Serverless in production (O'Reilly Software Architecture)

CENTRALISE LOGS

MAKE THEM EASILYSEARCHABLE

Page 113: Serverless in production (O'Reilly Software Architecture)

+ +the elk stack

Page 114: Serverless in production (O'Reilly Software Architecture)

CloudWatch Logs

Page 115: Serverless in production (O'Reilly Software Architecture)

CloudWatch Logs AWS Lambda ELK stack

Page 116: Serverless in production (O'Reilly Software Architecture)

CloudWatch Events

Page 117: Serverless in production (O'Reilly Software Architecture)

CloudWatch Logs

Page 118: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2f3zxQG

Page 119: Serverless in production (O'Reilly Software Architecture)

DISTRIBUTED TRACING

Page 120: Serverless in production (O'Reilly Software Architecture)
Page 121: Serverless in production (O'Reilly Software Architecture)

“my followers didn’t receive my new post!”

- a user

Page 122: Serverless in production (O'Reilly Software Architecture)

where could the problem be?

Page 123: Serverless in production (O'Reilly Software Architecture)

correlation IDs*

* eg. request-id, user-id, yubl-id, etc.

Page 124: Serverless in production (O'Reilly Software Architecture)

ROLL YOUR OWNCLIENTS

Page 125: Serverless in production (O'Reilly Software Architecture)

kinesis client

http client

sns client

Page 126: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2k93hAj

kinesisglobal.CONTEXT

log.info(…)

api-b

global.CONTEXT

global.CONTEXT

global.CONTEXT

x-correlation-id = … x-correlation-xxx = …

API Gateway Kinesis

SNS

API Gateway

API Gatewayapi-a api-c

sns

headers[“User-Agent”] headers[“Debug-Log-Enabled”]

MessageAttributes: [ “x-correlation-id”: … “User-Agent”: … “Debug-Log-Enabled”: … ]

global.CONTEXT

headers[“User-Agent”] headers[“Debug-Log-Enabled”] headers[“x-correlation-id”]

headers[“User-Agent”] headers[“Debug-Log-Enabled”] headers[“x-correlation-id”]

data.__context

capture

forward

function

event

Page 127: Serverless in production (O'Reilly Software Architecture)

ROLL YOUR OWNCLIENTS

X-RAY

Page 128: Serverless in production (O'Reilly Software Architecture)

Amazon X-Ray

Page 129: Serverless in production (O'Reilly Software Architecture)

Amazon X-Ray

Page 130: Serverless in production (O'Reilly Software Architecture)

traces do not span over API Gateway

Page 131: Serverless in production (O'Reilly Software Architecture)

MONITORING + ALERTING

Page 132: Serverless in production (O'Reilly Software Architecture)

“where do I install monitoring agents?”

Page 133: Serverless in production (O'Reilly Software Architecture)

you can’t

Page 134: Serverless in production (O'Reilly Software Architecture)

• invocation Count• error Count• latency• throttling• granular to the minute• support custom metrics

Page 135: Serverless in production (O'Reilly Software Architecture)

• invocation Count• error Count• latency• throttling• granular to the minute• support custom metrics

Page 136: Serverless in production (O'Reilly Software Architecture)
Page 137: Serverless in production (O'Reilly Software Architecture)
Page 138: Serverless in production (O'Reilly Software Architecture)
Page 139: Serverless in production (O'Reilly Software Architecture)

Why not IOPipe?

! pervasive access to your entire application! adds latency for tracking

Page 140: Serverless in production (O'Reilly Software Architecture)

me

The only “background” processing you get are the capabilities the platform provides out of the box.

Page 141: Serverless in production (O'Reilly Software Architecture)

“how do I batch up and send logs/metrics in the

background?”

Page 142: Serverless in production (O'Reilly Software Architecture)

you can’t (kinda)

Page 143: Serverless in production (O'Reilly Software Architecture)

console.log(“hydrating yubls from db…”);

console.log(“fetching user info from user-api”);

console.log(“MONITORING|1489795335|27.4|latency|user-api-latency”);

console.log(“MONITORING|1489795335|8|count|yubls-served”);

timestamp metric value

metric type

metric namemetrics

logs

Page 144: Serverless in production (O'Reilly Software Architecture)

CloudWatch Logs AWS Lambda

ELK stacklogs

metrics

CloudWatch

Page 145: Serverless in production (O'Reilly Software Architecture)

CloudWatch Logs

Page 146: Serverless in production (O'Reilly Software Architecture)

CloudWatch Logs AWS Lambda

ELK stacklogs

metrics

CloudWatch

memory usedmemory size

billed duration

Page 147: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2gGredx

Page 148: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2goFZ8F

Page 149: Serverless in production (O'Reilly Software Architecture)

DASHBOARDS

Page 150: Serverless in production (O'Reilly Software Architecture)

DASHBOARDS

SET ALARMS

Page 151: Serverless in production (O'Reilly Software Architecture)

DASHBOARDS

SET ALARMS

TRACK APP-LEVELMETRICS

Page 152: Serverless in production (O'Reilly Software Architecture)

Not Only CloudWatch

Page 153: Serverless in production (O'Reilly Software Architecture)
Page 154: Serverless in production (O'Reilly Software Architecture)

don’t put all your eggs in one basket

aka. you don’t want your monitoring system to fail at the same time as the systems it monitors

Page 155: Serverless in production (O'Reilly Software Architecture)

CONFIG MANAGEMENT

Page 156: Serverless in production (O'Reilly Software Architecture)

Lambda

Page 157: Serverless in production (O'Reilly Software Architecture)

me

Environment variables make it hard to share configurations

across functions.

Page 158: Serverless in production (O'Reilly Software Architecture)

me

Environment variables make it hard to implement fine-grained

access to sensitive info.

Page 159: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2uQKABA

Page 160: Serverless in production (O'Reilly Software Architecture)

couples ability to deploy with access to sensitive data, which often don’t overlap in a large

engineering team or in a regulated environment

Page 161: Serverless in production (O'Reilly Software Architecture)

CENTRALISEDCONFIG SERVICE

Page 162: Serverless in production (O'Reilly Software Architecture)

config servicegoes here

Page 163: Serverless in production (O'Reilly Software Architecture)
Page 164: Serverless in production (O'Reilly Software Architecture)
Page 165: Serverless in production (O'Reilly Software Architecture)

Why not consul or etcd?

! multiple EC2 instances in multi-AZ for HA! have to manage servers, patch OS, patch software, etc.! learning curve for configuring the service! learning curve for using the CLI tools

Page 166: Serverless in production (O'Reilly Software Architecture)
Page 167: Serverless in production (O'Reilly Software Architecture)

SSM Parameter

Store

Page 168: Serverless in production (O'Reilly Software Architecture)

SSM Parameter Store

HTTPS

role-based access

encrypted in-flight

Page 169: Serverless in production (O'Reilly Software Architecture)

SSM Parameter Store

encrypt

role-based access

Page 170: Serverless in production (O'Reilly Software Architecture)

SSM Parameter Store

encrypted at-rest

Page 171: Serverless in production (O'Reilly Software Architecture)

HTTPS

role-based access

SSM Parameter Store

encrypted in-flight

Page 172: Serverless in production (O'Reilly Software Architecture)

SSM Parameter Store

decrypt

role-based access

Page 173: Serverless in production (O'Reilly Software Architecture)

CENTRALISEDCONFIG SERVICE

CLIENT LIBRARY

Page 174: Serverless in production (O'Reilly Software Architecture)

Requirements for client library

! standardise and encapsulate how you manage configs! supports client-side caching (fetch & cache at coldstart)! invalidate cache at interval! invalidate cache explicitly when staleness is detected

Page 175: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2yLUjwd

Page 176: Serverless in production (O'Reilly Software Architecture)

PRO TIPS

Page 177: Serverless in production (O'Reilly Software Architecture)

max 75 GB total deployment package size*

* limit is per AWS region

Page 178: Serverless in production (O'Reilly Software Architecture)

Janitor Monkey

Page 179: Serverless in production (O'Reilly Software Architecture)

Janitor Lambda

http://bit.ly/2xzVu4a

Page 180: Serverless in production (O'Reilly Software Architecture)

disable versionFunctions in

Page 181: Serverless in production (O'Reilly Software Architecture)

install Serverless framework as dev dependency at project level

dev dependencies are excluded since 1.16.0

Page 182: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2vzBqhC

Page 183: Serverless in production (O'Reilly Software Architecture)

http://amzn.to/2vtUkDU

Page 184: Serverless in production (O'Reilly Software Architecture)

UNDERSTANDCOLDSTARTS

Page 185: Serverless in production (O'Reilly Software Architecture)

Amazon X-Ray1st invocation

2nd invocation

cold start

Page 186: Serverless in production (O'Reilly Software Architecture)

source: http://bit.ly/2oBEbw2

Page 187: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2rtCCBz

Page 188: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2rtCCBz

C#

Page 189: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2rtCCBz

Java

Page 190: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2rtCCBz

NodeJs, Python

Page 191: Serverless in production (O'Reilly Software Architecture)

me

C# and Java experiences ~100 times the cold start time of Python and also suffer from

much higher standard deviation

Page 192: Serverless in production (O'Reilly Software Architecture)

me

memory size improves cold start time linearly

Page 193: Serverless in production (O'Reilly Software Architecture)

AVOIDCOLDSTARTS

Page 194: Serverless in production (O'Reilly Software Architecture)

CloudWatch Event AWS Lambda

Page 195: Serverless in production (O'Reilly Software Architecture)

CloudWatch Event AWS Lambda

ping

ping

ping

ping

Page 196: Serverless in production (O'Reilly Software Architecture)

CloudWatch Event AWS Lambda

ping

ping

ping

ping

Page 197: Serverless in production (O'Reilly Software Architecture)

CloudWatch Event AWS Lambda

ping

ping

ping

ping

HEALTH CHECKS?

Page 198: Serverless in production (O'Reilly Software Architecture)

AWS Lambda docs

Take advantage of container re-use to improve the performance of your function. Make sure any

externalized configuration or dependencies that your code retrieves are stored and referenced locally after initial execution. Limit the re-initialization of variables/objects on

every invocation. Instead use static initialization/constructor, global/static variables and singletons. Keep alive and reuse connections (HTTP, database, etc.) that

were established during a previous invocation.

http://amzn.to/2jzLmkb

Page 199: Serverless in production (O'Reilly Software Architecture)

max 5 mins execution time

Page 200: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2w6ItdI

Page 201: Serverless in production (O'Reilly Software Architecture)

CONSIDERPARTIAL

FAILURES

Page 202: Serverless in production (O'Reilly Software Architecture)

AWS Lambda docs

AWS Lambda polls your stream and invokes your Lambda function.

Therefore, if a Lambda function fails, AWS Lambda attempts to process the erring batch of records until the time

the data expires.

http://amzn.to/2vs2lIg

Page 203: Serverless in production (O'Reilly Software Architecture)

vsprocessing halts until failed

events are retried successfully/expired from stream

prioritize realtime-ness, retry failed events with best effort,

then skip

Page 204: Serverless in production (O'Reilly Software Architecture)

SNS

Kinesis

SQS

after 3 attempts

share processing logic

events are processed in chronological order

failed events are retried out of sequence

Page 205: Serverless in production (O'Reilly Software Architecture)

PROCESS SQSWITH RECURSIVE

FUNCTIONS

Page 206: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2npomX6

Page 207: Serverless in production (O'Reilly Software Architecture)

AVOID HOTKINESS

STREAMS

Page 208: Serverless in production (O'Reilly Software Architecture)

AWS Lambda docs

Each shard can support up to 5 transactions per second for

reads, up to a maximum total data read rate of 2 MB per second.

http://amzn.to/2ubyaot

Page 209: Serverless in production (O'Reilly Software Architecture)

AWS Lambda docs

If your stream has 100 active shards, there will be 100 Lambda functions running concurrently. Then, each Lambda function

processes events on a shard in the order that they arrive.

http://amzn.to/2ubyaot

Page 210: Serverless in production (O'Reilly Software Architecture)

when no. of processors goes up…

Page 211: Serverless in production (O'Reilly Software Architecture)

ReadProvisionedThroughputExceeded

can have too many Kinesis read operations…

Page 212: Serverless in production (O'Reilly Software Architecture)

ReadRecords.IteratorAge

unpredictable spikes in read ‘latency’…

Page 213: Serverless in production (O'Reilly Software Architecture)

can kinda workaround…

Page 214: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2uv5LsH

Page 215: Serverless in production (O'Reilly Software Architecture)

clever, but costly

Page 216: Serverless in production (O'Reilly Software Architecture)

new tool, new problemsbut they’re easier to deal with

Page 217: Serverless in production (O'Reilly Software Architecture)

@theburningmonktheburningmonk.comgithub.com/theburningmonk

Page 218: Serverless in production (O'Reilly Software Architecture)

http://bit.ly/2yQZj1H