Build reactive systems on lambda

152
+ = BUILDING REACTIVE SYSTEMS WITH LAMBDA

Transcript of Build reactive systems on lambda

Page 1: Build reactive systems on lambda

+ =

BUILDING REACTIVE SYSTEMS WITH

LAMBDA

Page 2: Build reactive systems on lambda

hi, my name is Yan Cui@theburningmonk

Page 3: Build reactive systems on lambda
Page 4: Build reactive systems on lambda
Page 5: Build reactive systems on lambda

“as a Software Engineer, what is my job?”

Page 6: Build reactive systems on lambda

“to write code, of course!”- Me, circa 2006

Page 7: Build reactive systems on lambda

“to provide value to users & stakeholders”

- Me, 2016

Page 8: Build reactive systems on lambda
Page 9: Build reactive systems on lambda

- Dan North

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

metric that matters.”

Page 10: Build reactive systems on lambda

THEBALANCE

COMPETING

FORCES

Page 11: Build reactive systems on lambda

performance

security

scalabilitysimplicity

cost

team

time to market

Page 12: Build reactive systems on lambda

“Programmers know the benefits of everything and the tradeoffs of nothing.”

- Rich Hickey

https://www.infoq.com/presentations/Simple-Made-Easy

Page 13: Build reactive systems on lambda

context is the king

Page 14: Build reactive systems on lambda
Page 15: Build reactive systems on lambda
Page 16: Build reactive systems on lambda

ONLY ONE ZLATAN

Page 17: Build reactive systems on lambda

security

complexity OUTSIDE the code

deployment

load balancing

caching

monitoring

config management

https://www.infoq.com/presentations/complexity-simplicity-esb

centralised logging

elastic scalingsetup server

Page 18: Build reactive systems on lambda
Page 19: Build reactive systems on lambda
Page 20: Build reactive systems on lambda
Page 21: Build reactive systems on lambda
Page 22: Build reactive systems on lambda

Leaky Abstraction

Page 23: Build reactive systems on lambda

AWS re:invent 2014https://www.youtube.com/watch?v=9eHoyUVo-yg

Page 24: Build reactive systems on lambda

AWS re:invent 2014https://www.youtube.com/watch?v=9eHoyUVo-yg

FAAS(Function-As-A-Service)

Page 25: Build reactive systems on lambda
Page 26: Build reactive systems on lambda

THERE IS NO SERVER

Page 27: Build reactive systems on lambda

cost saving

Page 28: Build reactive systems on lambda

charged by invocations

Page 29: Build reactive systems on lambda

not paying for idle servers

Page 30: Build reactive systems on lambda
Page 31: Build reactive systems on lambda

elastic scaling

Page 32: Build reactive systems on lambda
Page 33: Build reactive systems on lambda

hi guys,come back at 10 to find

out who won!

Page 34: Build reactive systems on lambda

everyone came back at exactly 10pm!

Page 35: Build reactive systems on lambda

everyone came back at exactly 10pm!

Lambda scaled instantly

Page 36: Build reactive systems on lambda

these spikes happen to us

ALL THE TIME

Page 37: Build reactive systems on lambda

minimise undifferentiated

heavy-lifting

Page 38: Build reactive systems on lambda

“what about containers?”

Page 39: Build reactive systems on lambda
Page 40: Build reactive systems on lambda

important, butinvisible subsystems

Page 41: Build reactive systems on lambda

economy of scale

Page 42: Build reactive systems on lambda

NoOps!!

Page 43: Build reactive systems on lambda

reactive

Page 44: Build reactive systems on lambda
Page 45: Build reactive systems on lambda
Page 46: Build reactive systems on lambda
Page 47: Build reactive systems on lambda
Page 48: Build reactive systems on lambda

simple, fast deployment

Page 49: Build reactive systems on lambda

first Lambda function went live

(team size : 4)

Page 50: Build reactive systems on lambda

(team size : 7)

155 prod deployments!

Page 51: Build reactive systems on lambda

- Dan North

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

metric that matters.”

Page 52: Build reactive systems on lambda

easy to get started

Page 53: Build reactive systems on lambda
Page 54: Build reactive systems on lambda

now, we stand at 130 Lambda functions in prod, with 170 in dev

Page 55: Build reactive systems on lambda

fuelling the Yubl platform evolution

Page 56: Build reactive systems on lambda

My Beautiful Monolith

Page 57: Build reactive systems on lambda

“What would a good

architecture for us look like?”

Page 58: Build reactive systems on lambda

small, incremental deployments

fast deployments

no downtime

no lock-step deployments

features deployed independently

features loosely-coupled through messages

minimise cost for unused resources

minimise ops effort

Page 59: Build reactive systems on lambda

oh, and do all these whilst continue

to deliver value, thanks :-)

love, your users

Page 60: Build reactive systems on lambda

completely rebuilt search

Page 61: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearch

Page 62: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Page 63: Build reactive systems on lambda

analytics pipeline

Page 64: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Google BigQuery

Page 65: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Google BigQuery

1 developer, 2 daysdesign production

(his 1st serverless project)

Page 66: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Google BigQuery“nothing ever got done

this fast at Skype!”

- Chris Twamley

Page 67: Build reactive systems on lambda

- Dan North

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

metric that matters.”

Page 68: Build reactive systems on lambda

Rebuiltwith Lambda

Page 69: Build reactive systems on lambda
Page 70: Build reactive systems on lambda
Page 71: Build reactive systems on lambda
Page 72: Build reactive systems on lambda
Page 73: Build reactive systems on lambda
Page 74: Build reactive systems on lambda
Page 75: Build reactive systems on lambda

Rebuiltwith Lambda

Page 76: Build reactive systems on lambda
Page 77: Build reactive systems on lambda
Page 78: Build reactive systems on lambda
Page 79: Build reactive systems on lambda
Page 80: Build reactive systems on lambda
Page 81: Build reactive systems on lambda

and many more…

Page 82: Build reactive systems on lambda

“JavaScript doesn’t scale well with complexity”

- People on the Internet

Page 83: Build reactive systems on lambda

but

Page 84: Build reactive systems on lambda

“limit complexity, and JavaScript isn’t so bad”

- Me

Page 85: Build reactive systems on lambda

TESTING

Page 86: Build reactive systems on lambda
Page 87: Build reactive systems on lambda

amzn.to/29Lxuzu

Page 88: Build reactive systems on lambda

Level of Testing

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

Page 89: Build reactive systems on lambda
Page 90: Build reactive systems on lambda

Level of Testing

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

Page 91: Build reactive systems on lambda

handler

Page 92: Build reactive systems on lambda

handler

test by invoking the handler

Page 93: Build reactive systems on lambda

Level of Testing

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

Page 94: Build reactive systems on lambda

Level of Testing

unit

integration

acceptance

Page 95: Build reactive systems on lambda

Level of Testing

unit

integration

acceptance

can do all 3 with Lambda

Page 96: Build reactive systems on lambda

“…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 97: Build reactive systems on lambda

“…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 98: Build reactive systems on lambda

Don’t Mock Types You Can’t ChangeServices

Page 99: Build reactive systems on lambda

“…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 100: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Page 101: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Test Input

Page 102: Build reactive systems on lambda

Legacy Monolith Amazon Kinesis Amazon Lambda

Amazon CloudSearchAmazon API Gateway Amazon Lambda

Test Input

Validate

Page 103: Build reactive systems on lambda

“…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 104: Build reactive systems on lambda

Jenkins build config deploys and tests

unit + integration tests

deploy

acceptance tests

Page 105: Build reactive systems on lambda

build.sh allows repeatable builds on both local & CI

Page 106: Build reactive systems on lambda

LOGGING

Page 107: Build reactive systems on lambda
Page 108: Build reactive systems on lambda

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

Page 109: Build reactive systems on lambda

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 110: Build reactive systems on lambda

organised by Function + Version

Page 111: Build reactive systems on lambda

LOG OVERLOAD

Page 112: Build reactive systems on lambda

centralise your logs

Page 113: Build reactive systems on lambda

CloudWatch Logs AWS Lambda

LogStash ElasticSearch

Page 114: Build reactive systems on lambda

CloudWatch Logs AWS Lambda

LogStash ElasticSearch

AWS Elasticsearch

Page 115: Build reactive systems on lambda

CloudWatch Logs AWS Lambda

LogStash ElasticSearch

AWS Elasticsearch

Elastic Cloud

Page 116: Build reactive systems on lambda

CloudWatch Logs AWS Lambda

LogStash ElasticSearch

AWS Elasticsearch

Elastic Cloud

?

Page 117: Build reactive systems on lambda

correlation IDs

Page 118: Build reactive systems on lambda

MONITORING

Page 119: Build reactive systems on lambda

nowhere to install monitoring agents

Page 120: Build reactive systems on lambda

no time for background tasks

Page 121: Build reactive systems on lambda

• Invocation Count• Error Count• Latency (avg, min, max, sum)• Throttling• Granular to the minute• Support custom metrics

Page 122: Build reactive systems on lambda

• Same basic metrics• Better dashboard• Support custom metrics

https://www.datadoghq.com/blog/monitoring-lambda-functions-datadog/

Page 123: Build reactive systems on lambda
Page 124: Build reactive systems on lambda

Do It Yourself

Page 125: Build reactive systems on lambda

PRO TIPset up dashboards

Page 126: Build reactive systems on lambda

PRO TIPdon’t forget to set

up alarms

Page 127: Build reactive systems on lambda

PRO TIPadd application-level

metrics

Page 128: Build reactive systems on lambda

KEEP WARM

Page 129: Build reactive systems on lambda

functions are unloaded if idle for a while

Page 130: Build reactive systems on lambda

noticeable cold start time(package size matters)

Page 131: Build reactive systems on lambda

CloudWatch Event AWS Lambda

Page 132: Build reactive systems on lambda

CloudWatch Event AWS Lambda

ping

ping

ping

ping

Page 133: Build reactive systems on lambda

CloudWatch Event AWS Lambda

ping

ping

ping

ping

Page 134: Build reactive systems on lambda

CloudWatch Event AWS Lambda

ping

ping

ping

ping

HEALTH CHECKS?

Page 135: Build reactive systems on lambda

KNOW YOUR LIMITS

Page 136: Build reactive systems on lambda

max 50 MB deployment package size

Page 137: Build reactive systems on lambda

max 50 MB deployment package sizemax 75 GB total deployment package size*

* limit is per AWS region

Page 138: Build reactive systems on lambda

Janitor Monkey

Page 139: Build reactive systems on lambda

Janitor Lambda

Page 140: Build reactive systems on lambda

max 5 mins execution time

Page 141: Build reactive systems on lambda
Page 142: Build reactive systems on lambda

max 6 MB request payload size*

max 6 MB response payload size

* for a request-response event type

Page 143: Build reactive systems on lambda

default max 100 concurrent executions*

* soft-limit, can be raised via support ticket

Page 144: Build reactive systems on lambda

looking ahead

Page 145: Build reactive systems on lambda
Page 146: Build reactive systems on lambda

.Net core?SQS support?

Page 147: Build reactive systems on lambda

v1.0

Page 148: Build reactive systems on lambda

MULTI-CLOUD FUTURE?

Page 149: Build reactive systems on lambda

IBM OpenWhisk

Amazon Lambda Azure Web Functions

Google Cloud Functions

competition

faster innovation lower prices

Page 150: Build reactive systems on lambda
Page 151: Build reactive systems on lambda

@theburningmonk

@theburningmonktheburningmonk.comgithub.com/theburningmonk

Page 152: Build reactive systems on lambda

@theburningmonk

@theburningmonktheburningmonk.comgithub.com/theburningmonk

slides at http://bit.ly/2ecqEql