Page 1
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 1/40
Building Scalable Serverless ApplicationsBuilding Scalable Serverless ApplicationsBuilding Scalable Serverless Applicationson AWSon AWSon AWSBy: Kevin S LinBy: Kevin S LinBy: Kevin S Lin
1 / 401 / 401 / 40
Page 2
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 2/40
Agenda
Hello, my name is...
Serverless: What is it?
Serverless: Why Care
Serverless: Offerings & Applications
Serverless: Scaling
Takeaways
2 / 40
Page 3
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 3/40
founder of cloud.thence, consulting firm that helps companies scale and prevail onAWS
5+ years as developer at AWS with focus on scaling and monitoring
run FolkStories podcast where I have longform conversation with awesome people
3 / 40
Page 4
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 4/40
Serverless: What is it?Serverless: What is it?Serverless: What is it?
4 / 404 / 404 / 40
Page 5
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 5/40
What Its Not
Courtesy of giphy
having no serversmanaged serverscontainers
5 / 40
Page 6
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 6/40
Serverless as a Spectrum
ephermal compute, nothing allocated with no utilization
pay for use
higher abstraction knobs
6 / 40
Page 7
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 7/40
Serverless: Why care?Serverless: Why care?Serverless: Why care?
7 / 407 / 407 / 40
Page 8
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 8/40
Serverless in Context
8 / 40
Page 9
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 9/40
Serverless Benefits
lower costs for most use cases, no $ when no utilization
∞* scale
no provisioning or management
9 / 40
Page 10
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 10/40
Serverless OfferingsServerless OfferingsServerless Offerings
10 / 4010 / 4010 / 40
Page 11
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 11/40
AWS Lambda: Serverless Compute
Run code without servers
Automatic scaling
Pay only for compute you consume (charged by every 100ms)$0.20 per 1 million requests$0.00001667 for every GB-second of compute1 million requests running 200ms = $0.62 per month
11 / 40
Page 12
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 12/40
API Gateway: Serverless REST Endpoint
Create API endpoint without servers
Automatic scaling
Builtin Versioning, Security Controls, and Monitoring
Pay only for API calls made (num requests)$3.5 per million API calls$1 per million websocket messages1 million API calls = $3.5
12 / 40
Page 13
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 13/40
DynamoDB Serverless: Serverless NoSQL DB
Create Databases without servers
Automatic scaling
Pay only for database resource consumed (per second basis)$1.25 per million write request units$0.25 per million read request units$0.25 per GB-month (first 25GB free)1 million read & write + 50GB storage = $20.25
13 / 40
Page 14
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 14/40
Serverless ApplicationsServerless ApplicationsServerless Applications
14 / 4014 / 4014 / 40
Page 15
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 15/40
Web AppWeather Application
Courtesy of aws.amazon.com/serverless
Reference Architecture: https://github.com/aws-samples/lambda-refarch-webapp
15 / 40
Page 16
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 16/40
Mobile AppMobile Backend for Social Media App
Courtesy of aws.amazon.com/serverless
Reference Architecture: https://github.com/awslabs/lambda-refarch-mobilebackend/
16 / 40
Page 17
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 17/40
Data ProcessingImage Thumbnail Creation
Courtesy of aws.amazon.com/serverless
Reference Architecture: https://github.com/awslabs/lambda-refarch-fileprocessing
17 / 40
Page 18
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 18/40
Serverless: ScalingServerless: ScalingServerless: Scaling
18 / 4018 / 4018 / 40
Page 19
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 19/40
Challenges
platform
performance
architecture
19 / 40
Page 20
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 20/40
Platform LimitationsThey exist
max execution time: 15min
max memory: 3GB
payload: 6MB
concurrent executions: 1000
state persistence: false
non-persistent scratch area: 512 MB
deployment package size (zipped): 50MB
deployment package size (unzipped): 250MB
file descriptors: 1024
execution processors/threads: 1024
20 / 40
Page 21
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 21/40
Platform LimitationsIts not me its you
consider if your micro service is doing too much
persistent state not a good assumption in cloud based world
guardrails can be nice
21 / 40
Page 22
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 22/40
Platform LimitationsIts Getting Better
execution time: 5min -> 15min
memory: 1GB -> 3GB
deployment package size: Lambda Layers
22 / 40
Page 23
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 23/40
Platform LimitationsWorkarounds
concurrent executions: ask for limit increase
max executiont time: API + Workflow pattern
payload: use S3 signed urls (limit of 5TB)
23 / 40
Page 24
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 24/40
PerformanceCold Starts
first start penalty
24 / 40
Page 25
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 25/40
PerformanceOptimizations
use the right language
don't use VPC
cache expensive things outside of function handler
25 / 40
Page 26
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 26/40
PerformanceRight Language
26 / 40
Page 27
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 27/40
PerformanceAvoid VPC
27 / 40
Page 28
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 28/40
PerformanceAvoid VPC
28 / 40
Page 29
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 29/40
PerformanceLambda Execution Contextletlet dbletlet initialized = falseletlet var1, var2, var3
functionfunction initinit() { ifif (initialized) { returnreturn } db = mysql.create(...) var1 = initVar1 // ... initialized = true returnreturn}
module.exports.handler = (event, context, cb) => {
init() // ... other function logic cb(null, results)}
29 / 40
Page 30
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 30/40
ArchitectureMonolith vs MicroServices
Courtesy of https://www.weave.works
30 / 40
Page 31
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 31/40
ArchitectureInstrumentation/Tracing
AWS X-Ray
trace code through multiple subsystemsautomatically capture http[s] calls, aws sdk calls, etc
traces, segments and annotations
sampling
31 / 40
Page 32
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 32/40
ArchitectureInstrumentation/Tracing
Courtesy of AWS X-ray docs 32 / 40
Page 33
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 33/40
ArchitectureInstrumentation/Tracing
Courtesy of AWS X-ray docs33 / 40
Page 34
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 34/40
ArchitectureInstrumentation/Logging
request idx-amzn-requestid: api gateway requestxray-trace-id
correlation idgenerate in initial request(eg. api gateway)add to all outgoing requestpass along in all services
DEBUGif an issue occurs, you might need to switch to debug logsconsider having special header to enable DEBUG on all downstream serviceshave small percentage of logs always be DEBUG
34 / 40
Page 35
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 35/40
ArchitectureEtc
all the servicesone server vs 100 microservices
pricingfixed hourly cost vs cost by use
best practicesdeployment, languages, libraries, frameworks
35 / 40
Page 36
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 36/40
Getting Started
strangler pattern
longstanding workloads, still use servers (for now)
use toolsbuiltin: XRay, Cloudwatch Logsframeworks: serverless, SAMservices: IOPipe, Stackery.io
36 / 40
Page 37
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 37/40
Mental Model
Compute ModelOnPrem Pets: need to be taken care ofCloud Cattle: swap out when neededServerless Bug: should not exist
37 / 40
Page 38
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 38/40
Takeaways
serverless is a spectrum, "serverless" is at the end of the spectrum
serverless is higher abstractions, pay-by-use, and "infinite" scale
serverless requires a deep understanding of platform and performance limitations
serverless is coming
38 / 40
Page 39
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 39/4039 / 40
Page 40
2/28/2019 My Presentation
http://localhost:8000/dist/presentation.html#1 40/40
You might also be interested in...cloud.thence.io where you can find articles about serverless and all things aws related
Everything is Broken on April 3rd where I'm giving a talk focused exclusively on scaling Lambda
[email protected] if you have quesitons or want to talk further
40 / 40