Sunteți pe pagina 1din 91

Getting Started with

Serverless Architectures

Email: {anything}@jedberg.net
Twitter: @jedberg
Web: www.jedberg.net
Jeremy Edberg Facebook: facebook.com/jedberg
CoFounder
Linkedin:
https://www.cloudnative.io
www.linkedin.com/in/jedberg

Physical Servers
Test and prod are different
Prod is in need of constant
updates
Slow iteration and deployment
Polyglot unfriendly
Deploy in weeks, live for years
Virtual Machines
Prod is immutable
Rapid iteration and deployment
Multi-tenancy
Polyglot friendly
Deploy in minutes, live for weeks
Containers
Test and prod are the same
Prod is immutable
Rapid(er) iteration and deployment
High multi-tenancy
Polyglot friendly
Deploy in seconds, live for hours
Serverless
Smallest unit of compute
Super scalable
Rapid iteration
Extreme multi-tenancy
Very polyglot friendly
Easier to collaborate
Deploy independently, live for
seconds
A whole lot of choices
Hodgepodge of services Amazons Ecosystem
A whole lot of choices
Amazons Serverless
Ecosystem
Lambda SQS

SNS S3

DynamoDB Kenisis
Benefits of AWS Lambda

No servers to Continuous Never pay for


manage scaling idle No cold
servers (only
happy
accountants)
What is serverless anyway?

There are still servers, you just


dont manage them anymore

It also means you dont access


them anymore

So you dont need to (or get to)


optimize them.
What is Serverless Computing?

VMs

Machine as the unit of scale


EC2
Abstracts the hardware

Containers

Application as the unit of scale ECS


Abstracts the OS

Serverless

Functions as the unit of scale


Lambda
Abstracts the language runtime
How do I choose?
VMs

I want to configure machines, EC2


storage, networking, and my OS

Containers

I want to run servers, configure


applications, and control scaling ECS

Serverless

Run my code when its needed


Lambda
Serverless computing is
all about speeding up
development by allowing
rapid iteration and
removing management
overhead
A brief journey through history
80s Mainframe Cycle

Cost $1MM to $100MM

1 to 5 years to execute

Usually had to bet the whole


company

Cost of failure -- Bankruptcy


90s Client/Server Cycle
Cost $100K to $10MM

3 to 6 months to execute

Usually had to bet a product or


division

Cost of failure -- Revenue hit, CXX


job
00s Agile Cycle

Cost $10K to $1MM

3 to 6 weeks to execute

Bet a product feature

Cost of failure -- product manager


reputation
Product Manager

Developer

QA

Ops

BI / Analytics
Cost and size
of risk
decreased

Rate of
change
increased
Build Test Release
Build Test Release

Build Test Release

Build Test Release

Build Test Release

Build Test Release


Success follows a standard
pattern

Monolithic

Multiple services

Internal Microservices Platform


Distributed Computing and a
Distributed Workforce

The two go hand in


hand when you have
a good distributed
systems culture

Microservices and
Micro Teams
Highly aligned, loosely
coupled
Services are built by different
teams who work together to
figure out what each service
will provide.
The service owner publishes
an API that anyone can use
and returns proper response
codes
The Microservices Architecture
Microservices Tools
Containers Deployment, CI/CD

Frameworks
etc.
Web Servers
etc.
Config Management

Code Libraries
etc.
API Management
Amazons Microservices
Tools
What do all the parts of
microservices have in common?
Servers
Patches
Access control
Utilization Right-sizing

Capacity planning

Tuning Load and performance

Autoscaling
Configuration Packages and AMIs
Serverless
Patches
Access control
Utilization
Fully managed Right-sizing

Capacity
Continuous
planning
Scaling

Tuning Function is the deployment unit


Load and performance

Autoscaling
Configuration Packages and AMIs
What is Lambda?

Serverless, event-driven compute service

Lambda == microservice without managing servers


What does Lambda do for you?

Scales server capacity


automatically

API to trigger execution

Ensures function is executed in


parallel and at scale

Logging, monitoring, etc

Easy pricing
Monitoring
Everything is in Cloudwatch or Cloudwatch logs
Pricing

Choose your RAM


from 128MB to
1500MB
CPU and Network
scaled based on
RAM
Cost Comparison
Cost Comparison
Theres about 2.5M seconds in a month, so 3M requests is about 1.2 per second

The T2.Small is $18.98 a month, more than Lambda already


Lambda allows for a
tight feedback loop

We turned around
both these
requests in less
than a day
How does work?

Author your code
NodeJS, Python
AWS SDK built in
Java and any JVM
Access to /tmp, language
processes,
threads, etc Use any library you
want

Choose an event source

S3 Config Rules
Kinesis Amazon Echo
SNS API Gateway
DynamoDB Lambda
functions
CloudWatch More coming

Choose a Network

Default Customer VPC


All functions have Private communication
internet access within your VPC

No access to your Same configuration as


other VPCs your other VPCs (ENI,
route table, security
Still in a VPC groups, NAT)

Deploy your code


Use the GUI or
Upload to S3 or
Lambda directly
Write the function
Create the IAM role
Add extra permissions for a push model
Zip the function and dependencies
Test the function with mock data
Add an event source to the function
View the output of the live function
Write the function
Create the IAM role
Add extra permissions for a push model
Zip the function and dependencies
Test the function with mock data
Add an event source to the function
View the output of the live function https://cloudnative.io/oss/
Word Generator

Generate some number of English


looking words using an ngram
database

Allow a prefix to be specified


Demo
Architecture

Slack ECS Lambda SNS

router.py Kinesis

Lambda DynamoDB
router.py
Call out to other Lambda
functions
Add their results as attachments
to the message
Demo
From conception to prod
in 5 minutes
Red/Black,
Blue/Green,
Mauve/Chartreuse
Codebase
Structure
Frontend vs Backend
Repos
Lambda lets you manage your
code and infrastructure in the
same place (as long as you use
Kappa or something like it).
Example use cases
Live video stream processing

Lambda Functions

HQ Copy
S3
480p Playbac
Transcode k
Cloudfront S3
360p
Ingest
Transcode

Audio Only
Transcode Cloudfront
Streaming
Thumbnails
Serverless Website

Static
Content
S3

Dynamic
Content

API Gateway Lambda DynamoDB


Use Cases

Application Backend
Data Processing
Command and Control
Any functional or event
based system
Tips and Tricks

Limit your function size (JVM


startup time especially)
Remember execution is async
Dont assume function container
reuse but take advantage of it
Tips and Tricks

Remember the 500MB in /tmp


Use function aliases
Use the included logger
Tips and Tricks

Set up alarms on all Lambda


Cloudwatch metrics
Avoid throttling by using SNS
between any service, such as
S3
Beware of infinite loops by
having functions call each other.
Avoiding Infinte Loops

With a distributed
team, this is an easy
mistake to make
To avoid it, pass a call
stack and check for
self in the stack
Store your data properly
No local instance
access
DynamoDB Store everything in S3
S3, DynamoDB, or
Elasticache
Difficulties weve solved
zip up with
dependencies
roles and permissions
dev vs prod
aliases
Problems we still have

efficient dependency usage


local dev environments
making sure we have the same
dependencies
knowing when someone else is
deploying the same function
Build Test Release

Build Test Release

Build Test Release

Build Test Release

Build Test Release


Next Steps
Problems we still have

efficient dependency usage


local dev environments
making sure we have the same
dependencies
knowing when someone else is
deploying the same function
Problems we still have

efficient dependency usage


local dev environments
making sure we have the same
dependencies
knowing when someone else is
deploying the same function
Testing
You cant test the
network, but a good
application test should
obviate the need to do so.
Not really a solved
problem. Can do local
testing.
Can also send json to the
function and compare the
results.
Questions?
Email: {anything}@jedberg.net
Twitter: @jedberg
Web: www.jedberg.net
Facebook: facebook.com/jedberg
Linkedin:
www.linkedin.com/in/jedberg
Company: cloudnative.io
Thank You!

S-ar putea să vă placă și