serverless:
by Yan Cui
@theburningmonk
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
hey guys, vote on this post
and I’ll announce a winner at
10PM tonight
@theburningmonk theburningmonk.com
10PM
traffic
@theburningmonk theburningmonk.com
10PM
traffic
70-100x
@theburningmonk theburningmonk.com
system couldn’t fast enough
@theburningmonk theburningmonk.com
updates required 30 mins downtime
@theburningmonk theburningmonk.com
features took months to deliver
@theburningmonk theburningmonk.com
Dan North
“lead time to someone saying thank you is the
only reputation metric that matters.”
@theburningmonk theburningmonk.com
6 months, 6 devs
@theburningmonk theburningmonk.com
95% cost saving compared to existing EC2-based solution
@theburningmonk theburningmonk.com
velocity went from months to days
@theburningmonk theburningmonk.com
https://www.youtube.com/watch?v=evsz__BDprs
@theburningmonk theburningmonk.com
https://www.youtube.com/watch?v=evsz__BDprs
AppSync
DynamoDB
Lambda
Yan Cui
http://theburningmonk.com
@theburningmonk
AWS user for 10 years
Yan Cui
http://theburningmonk.com
@theburningmonk
http://bit.ly/yubl-serverless
Yan Cui
http://theburningmonk.com
@theburningmonk
Developer Advocate @
Yan Cui
http://theburningmonk.com
@theburningmonk
Independent Consultant
advisetraining delivery
theburningmonk.com/courses
theburningmonk.com/courses
realworldserverless.com
@theburningmonk theburningmonk.com
2010
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
users are distributed
around the world
systems have to be
available 24/7
@theburningmonk theburningmonk.com
millions of unique daily-active users
SCALABILITY
SCALABILITY
RESILIENCE
SCALABILITY
RESILIENCE
SECURITY
SCALABILITY
RESILIENCE
SECURITY
SPEED
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
networking
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
@theburningmonk theburningmonk.com
networking VMs
apply patches
install dependencies
create base AMI
set up auto-scaling
set up multi-AZ
set up load balancer
configure IAM roles
set up logging agent
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
@theburningmonk theburningmonk.com
networking VMs
apply patches
install dependencies
create base AMI
set up auto-scaling
set up multi-AZ
set up load balancer
configure IAM roles
set up logging agent
application
set up web server
configure middlewares
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
@theburningmonk theburningmonk.com
networking VMs
apply patches
install dependencies
create base AMI
set up auto-scaling
set up multi-AZ
set up load balancer
configure IAM roles
set up logging agent
application
set up web server
configure middlewares
write 1st line of
business logic
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
@theburningmonk theburningmonk.com
networking VMs
apply patches
install dependencies
create base AMI
set up auto-scaling
set up multi-AZ
set up load balancer
configure IAM roles
set up logging agent
application
set up web server
configure middlewares
write 1st line of
business logic
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
the only thing the
customer cares about!
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
networking VMs
apply patches
install dependencies
create base AMI
set up auto-scaling
set up multi-AZ
set up load balancer
configure IAM roles
set up logging agent
application
set up web server
configure middlewares
write 1st line of
business logic
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
@theburningmonk theburningmonk.com
networking VMs
apply patches
install dependencies
create base AMI
set up auto-scaling
set up load balancer
configure IAM roles
set up logging agent
application
set up web server
configure middlewares
write 1st line of
business logic
set up VPC
set up public subnet
set up private subnet
set up Internet Gateway
set up NAT Gateway
configure Route Tables
configure Network ACL
configure Security Groups
mooooo..
@theburningmonk theburningmonk.com
but, nonetheless… they’re important for setting you up to succeed
@theburningmonk theburningmonk.com
spinning up a web-server a production-ready environment!===
@theburningmonk theburningmonk.com
“we ain’t gonna need it”
@theburningmonk theburningmonk.com
“we ain’t gonna need it”
translation: “we will never be successful”
@theburningmonk theburningmonk.com
traffic
holy crap, we’ve
got traction!
@theburningmonk theburningmonk.com
traffic
oh no… our server died!
@theburningmonk theburningmonk.com
prepare for success
@theburningmonk theburningmonk.com
isn’t the savior?
@theburningmonk theburningmonk.com
0
Theory
“it works on
my machine!”
“production
ready!”days
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
0
Theory
“it works on
my machine!”
“production
ready!”
0
Reality
“it works on
my machine!”
“production
ready!”
days
days
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
mooooo..
@theburningmonk theburningmonk.com
scale
@theburningmonk theburningmonk.com
scale complexity
@theburningmonk theburningmonk.com
but our cognitive capacity hasn’t increased…
@theburningmonk theburningmonk.com
leverage: do more with less
@theburningmonk theburningmonk.com
EC2
EC2
@theburningmonk theburningmonk.com
EC2
EC2
we’re still managing
infrastructure
@theburningmonk theburningmonk.com
https://bit.ly/2Im61VK
“Unless you’re an infrastructure company,
infrastructure is basically overhead.”
Matt Klein
@theburningmonk theburningmonk.com
infrastructure
you
@theburningmonk theburningmonk.com
Serverless means…
don’t pay for it if no-one uses it
don’t need to worry about scaling
don’t need to provision and manage servers
@theburningmonk theburningmonk.com
“Serverless”
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
Gojko Adzic
It is serverless the same way
WiFi is wireless.
http://bit.ly/2yQgwwb
@theburningmonk theburningmonk.com
“Function-as-a-Service”
AWS Lambda
Azure Functions
Google Cloud Functions
Auth0 Webtask
Spotinst Functions Kubeless
IBM Cloud Functions
AWS Lambda
AWS Lambda
API Gateway IOT SNS Kinesis CloudWatch
@theburningmonk theburningmonk.com
Why serverless?
@theburningmonk theburningmonk.com
more Scalable
@theburningmonk theburningmonk.com
100% SERVERLESS
IN PRODUCTION
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
80 MILLION
MONTHLY USERS
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
Cheaper
(don’t pay for idle servers)
@theburningmonk theburningmonk.com
Resilience
(built-in redundancy and multi-AZ)
@theburningmonk theburningmonk.com
Secure
@theburningmonk theburningmonk.com
idea production
amazing VELOCITY from idea to product
@theburningmonk theburningmonk.com
idea production
choose language
+ framework
master language
+ framework
figure out
deployment
configure AMI
configure ELB
configure
autoscaling
capacity planning
over-provision for
launch
are we doing
microservices?
configure CI/CD
@theburningmonk theburningmonk.com
idea production
choose language
+ framework
master language
+ framework
figure out
deployment
configure AMI
configure ELB
configure
autoscaling
capacity planning
over-provision for
launch
are we doing
microservices?
configure CI/CD
@theburningmonk theburningmonk.com
truly “fullstack” developers are rare, and expensive
@theburningmonk theburningmonk.com
AWS
Scalability
Resilience
Security
DevOps
Distributed
Systems
JavaScript
CSS
HTML
SPA Framework
Responsive
Design
Debugging
@theburningmonk theburningmonk.com
AWS
Scalability
Resilience
Security
DevOps
Distributed
Systems
JavaScript
CSS
HTML
SPA Framework
Responsive
Design
Debugging
@theburningmonk theburningmonk.com
AWS
Scalability
Resilience
Security
DevOps
Distributed
Systems
JavaScript
CSS
HTML
SPA Framework
Responsive
Design
Debugging
@theburningmonk theburningmonk.com
AWS
Scalability
Resilience
Security
DevOps
Distributed
Systems
JavaScript
CSS
HTML
SPA Framework
Responsive
Design
Debugging
@theburningmonk theburningmonk.com
what you need to know to build a production-ready backend on AWS
EC2 / Containers Serverless
@theburningmonk theburningmonk.com
what you need to know to build a production-ready backend on AWS
EC2 / Containers Serverless
@theburningmonk theburningmonk.com
what you need to know to build a production-ready backend on AWS
EC2 / Containers Serverless
@theburningmonk theburningmonk.com
frontend focused teams can delay the point when they need a backend specialist
@theburningmonk theburningmonk.com
backend engineers can get so much more done with less effort and stress
@theburningmonk theburningmonk.com
https://www.youtube.com/watch?v=evsz__BDprs
@theburningmonk theburningmonk.com
what you need to know to build a production-ready backend on AWS
EC2 / Containers Serverless
AWS basics, DynamoDB,
Lambda, SNS, etc.
@theburningmonk theburningmonk.com
AppSync
DynamoDB
Lambda
ElasticSearch
@theburningmonk theburningmonk.com
focus your time and energy on improving the UX
@theburningmonk theburningmonk.com
the backend should “just work”
@theburningmonk theburningmonk.com
the backend should “just work”
it shouldn’t be THAT hard, and it doesn’t have to
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
don’t use callbacks, use async-await
@theburningmonk theburningmonk.com
avoid mixing callbacks with Promises
@theburningmonk theburningmonk.com
too sequential
@theburningmonk theburningmonk.com
missing Promise.all
@theburningmonk theburningmonk.com
async-await in forEach
@theburningmonk theburningmonk.com
not useing AWS SDK’s .promise()
cold starts
@theburningmonk theburningmonk.com
INITIALISE
CONTAINER
INITIALISE
RUNTIME
INITIALISE
HANDLER
YOUR CODE
EXECUTES
@theburningmonk theburningmonk.com
INITIALISE
CONTAINER
INITIALISE
RUNTIME
INITIALISE
HANDLER
YOUR CODE
EXECUTES
COLD START
@theburningmonk theburningmonk.com
“cold starts only happen to the first request”
@theburningmonk theburningmonk.com
function invocationconcurrent execution
i.e. a container
@theburningmonk theburningmonk.com
function invocationconcurrent execution
i.e. a container
class instance method call
@theburningmonk theburningmonk.com
Lambda scales the number of concurrent executions based on traffic
@theburningmonk theburningmonk.com
existing “containers” are reused where possible
@theburningmonk theburningmonk.com
time
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
invocation
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
invocation
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
invocation
invocation
invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
invocation
invocation
invocation invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
invocation
invocation
invocation invocation
@theburningmonk theburningmonk.com
time
invocation
invocation
invocation
invocation
invocation
invocation
invocation invocation
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
FREQUENCY DURATION
@theburningmonk theburningmonk.com
FREQUENCY DURATION
dictated by user traffic,
out of your control
@theburningmonk theburningmonk.com
FREQUENCY DURATION
optimize this!
@theburningmonk theburningmonk.com
if you need good cold start performance
DON’T run express.js in a Lambda
@theburningmonk theburningmonk.com
“Lambda is not a suitable solution for me because of cold starts”
@theburningmonk theburningmonk.com
“what is your latency requirement?”
@theburningmonk theburningmonk.com
cold starts that don’t add to user-facing latency is
generally not worth worrying about
@theburningmonk theburningmonk.com
sporadic spikes latency existed before Lambda
@theburningmonk theburningmonk.com
GC pauses…
@theburningmonk theburningmonk.com
overloaded servers…
@theburningmonk theburningmonk.com
slow downstream, databases, etc.
@theburningmonk theburningmonk.com
networking issues…
@theburningmonk theburningmonk.com
cold starts is generally not an issue if you have a steady traffic pattern
@theburningmonk theburningmonk.com
time
req/s
@theburningmonk theburningmonk.com
time
req/s
El Classico
@theburningmonk theburningmonk.com
time
req/s
lunch dinner
@theburningmonk theburningmonk.com
minimise the duration of cold starts so they
fall within acceptable latency range
@theburningmonk theburningmonk.com
require specific clients instead of the full AWS SDK
@theburningmonk theburningmonk.com
use webpack to bundle functions during deployment
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
then, consider using Provisioned Concurrency as a fallback
@theburningmonk theburningmonk.com
time
req/s
lunch dinner
Provisioned
Concurrency
@theburningmonk theburningmonk.com
time
req/s
lunch dinner
Provisioned
Concurrency
On-Demand
Concurrency
@theburningmonk theburningmonk.com
there are no silver bullets
@theburningmonk theburningmonk.com
Provisioned Concurrency is a powerful tool
IFF you have a cold start problem
DON’T use it by default
theburningmonk.com/hire-me
AdviseTraining Delivery
“Fundamentally, Yan has improved our team by increasing our
ability to derive value from AWS and Lambda in particular.”
Nick Blair
Tech Lead
homeschool.dev/class/production-ready-serverless
15% OFF WITH “YANPRS15”
@theburningmonk
theburningmonk.com
github.com/theburningmonk
159

Serverless a superpower for frontend developers