Getting Started with Serverless Architectures

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

Transcript of Getting Started with Serverless Architectures

Page 1: Getting Started with Serverless Architectures

Getting Started with

Serverless Architectures

Email: [email protected]

Twitter: @jedberg

Web: www.jedberg.net

Facebook: facebook.com/jedberg

Linkedin:

www.linkedin.com/in/jedberg

Jeremy Edberg

CoFounder

https://www.cloudnative.io

Page 2: Getting Started with Serverless Architectures
Page 3: Getting Started with Serverless Architectures

λ

Page 4: Getting Started with Serverless Architectures

Test and prod are different

Prod is in need of constant

updates

Slow iteration and deployment

Polyglot unfriendly

Deploy in weeks, live for years

Physical Servers

Page 5: Getting Started with Serverless Architectures

Prod is immutable

Rapid iteration and deployment

Multi-tenancy

Polyglot friendly

Deploy in minutes, live for weeks

Virtual Machines

Page 6: Getting Started with Serverless Architectures

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

Containers

Page 7: Getting Started with Serverless Architectures

Smallest unit of compute

Super scalable

Rapid iteration

Extreme multi-tenancy

Very polyglot friendly

Easier to collaborate

Deploy independently, live for

seconds

Serverless

Page 8: Getting Started with Serverless Architectures

A whole lot of choices

Amazon’s EcosystemHodgepodge of services

Page 9: Getting Started with Serverless Architectures

A whole lot of choices

Page 10: Getting Started with Serverless Architectures

Amazon’s Serverless

Ecosystem

Lambda

SNS

DynamoDB

SQS

S3

Kenisis

Page 11: Getting Started with Serverless Architectures

Continuous

scaling

No servers to

manage

Never pay for

idle – No cold

servers (only

happy

accountants)

Benefits of AWS Lambda

Page 12: Getting Started with Serverless Architectures

What is serverless anyway?

• There are still servers, you just

don’t manage them anymore

• It also means you don’t access

them anymore

• So you don’t need to (or get to)

optimize them.

Page 13: Getting Started with Serverless Architectures

What is Serverless Computing?

• VMs

• Machine as the unit of scale

• Abstracts the hardware

• Containers

• Application as the unit of scale

• Abstracts the OS

• Serverless

• Functions as the unit of scale

• Abstracts the language runtime

EC2

ECS

Lambda

Page 14: Getting Started with Serverless Architectures

How do I choose?

• VMs

• “I want to configure machines,

storage, networking, and my OS”

• Containers

• “I want to run servers, configure

applications, and control scaling”

• Serverless

• “Run my code when it’s needed”

EC2

ECS

Lambda

Page 15: Getting Started with Serverless Architectures

Serverless computing is

all about speeding up

development by allowing

rapid iteration and

removing management

overhead

Page 16: Getting Started with Serverless Architectures

A brief journey through history

Page 17: Getting Started with Serverless Architectures

80’s Mainframe Cycle

• Cost $1MM to $100MM

• 1 to 5 years to execute

• Usually had to bet the whole

company

• Cost of failure -- Bankruptcy

Page 18: Getting Started with Serverless Architectures

90‘s 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

Page 19: Getting Started with Serverless Architectures

00‘s Agile Cycle

• Cost $10K to $1MM

• 3 to 6 weeks to execute

• Bet a product feature

• Cost of failure -- product manager

reputation

Page 20: Getting Started with Serverless Architectures

Product Manager

Developer

QA

Ops

BI / Analytics

Page 21: Getting Started with Serverless Architectures

Cost and size

of risk

decreased

Rate of

change

increased

Page 22: Getting Started with Serverless Architectures

ReleaseTestBuild

Page 23: Getting Started with Serverless Architectures

ReleaseTestBuild

ReleaseTestBuild

ReleaseTestBuild

ReleaseTestBuild

ReleaseTestBuild

Page 24: Getting Started with Serverless Architectures

Multiple services

Internal Microservices Platform

Monolithic

Success follows a standard

pattern

Page 25: Getting Started with Serverless Architectures

Distributed Computing and a

Distributed Workforce

• The two go hand in

hand when you have

a good distributed

systems culture

• Microservices and

Micro Teams

Page 26: Getting Started with Serverless Architectures

• 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

Highly aligned, loosely

coupled

Page 27: Getting Started with Serverless Architectures

The Microservices Architecture

Page 28: Getting Started with Serverless Architectures

Microservices Tools

Web Servers

Code Libraries

Frameworks

Config Management

API Management

Deployment, CI/CDContainers

etc.

etc.

etc.

Page 29: Getting Started with Serverless Architectures

Amazon’s Microservices

Tools

Page 30: Getting Started with Serverless Architectures

What do all the parts of

microservices have in common?

Page 31: Getting Started with Serverless Architectures

Servers

Capacity planning

Right-sizing

Autoscaling

Load and performance

Patches

Tuning

Configuration

Utilization

Access control

Packages and AMIs

Page 32: Getting Started with Serverless Architectures

Serverless

Right-sizing

Autoscaling

Load and performance

Patches

Tuning

Configuration

Utilization

Access control

Packages and AMIs

Fully managed

Continuous Scaling

Function is the deployment unit

Capacity planning

Page 33: Getting Started with Serverless Architectures

What is Lambda?

Serverless, event-driven compute service

Lambda == microservice without managing servers

Page 34: Getting Started with Serverless Architectures

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

Page 35: Getting Started with Serverless Architectures

Monitoring• Everything is in Cloudwatch or Cloudwatch logs

Page 36: Getting Started with Serverless Architectures

Pricing

• Choose your RAM

from 128MB to

1500MB

• CPU and Network

scaled based on

RAM

Page 37: Getting Started with Serverless Architectures

Cost Comparison

Page 38: Getting Started with Serverless Architectures

Cost Comparison

There’s 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

Page 39: Getting Started with Serverless Architectures

Lambda allows for a

tight feedback loop

• We turned around

both these

requests in less

than a day

Page 40: Getting Started with Serverless Architectures

How does work?λ

Page 41: Getting Started with Serverless Architectures

Author your code

• AWS SDK built in

• Access to /tmp,

processes,

threads, etc

λ

• NodeJS, Python

• Java and any JVM

language

• Use any library you

want

Page 42: Getting Started with Serverless Architectures

Choose an event source

• S3

• Kinesis

• SNS

• DynamoDB

• CloudWatch

λ

• Config Rules

• Amazon Echo

• API Gateway

• Lambda

functions

• More coming

Page 43: Getting Started with Serverless Architectures

Choose a Network

• Default

• All functions have

internet access

• No access to your

other VPCs

• Still in a VPC

λ

• Customer VPC

• Private communication

within your VPC

• Same configuration as

your other VPCs (ENI,

route table, security

groups, NAT)

Page 44: Getting Started with Serverless Architectures

Deploy your code

• Use the GUI or

• Upload to S3 or

Lambda directly

λ

Page 45: Getting Started with Serverless Architectures
Page 46: Getting Started with Serverless Architectures

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

Page 47: Getting Started with Serverless Architectures
Page 48: Getting Started with Serverless Architectures

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/

Page 49: Getting Started with Serverless Architectures

Word Generator

• Generate some number of English

looking words using an ngram

database

• Allow a prefix to be specified

Page 50: Getting Started with Serverless Architectures
Page 51: Getting Started with Serverless Architectures
Page 52: Getting Started with Serverless Architectures
Page 53: Getting Started with Serverless Architectures
Page 54: Getting Started with Serverless Architectures

Demo

Page 55: Getting Started with Serverless Architectures

ECS

Architecture

Lambda

Lambda DynamoDB

SNS

Kinesis

Slack

router.py

Page 56: Getting Started with Serverless Architectures

Call out to other Lambda

functions

Add their results as attachments

to the message

router.py

Page 57: Getting Started with Serverless Architectures

Demo

Page 58: Getting Started with Serverless Architectures
Page 59: Getting Started with Serverless Architectures
Page 60: Getting Started with Serverless Architectures
Page 61: Getting Started with Serverless Architectures

From conception to prod

in 5 minutes

Page 62: Getting Started with Serverless Architectures
Page 63: Getting Started with Serverless Architectures
Page 64: Getting Started with Serverless Architectures

Red/Black,

Blue/Green,

Mauve/Chartreuse

Page 65: Getting Started with Serverless Architectures

Codebase

Structure

Page 66: Getting Started with Serverless Architectures
Page 67: Getting Started with Serverless Architectures

Frontend vs Backend

Repos

Page 68: Getting Started with Serverless Architectures

Lambda lets you manage your

code and infrastructure in the

same place (as long as you use

Kappa or something like it).

Page 69: Getting Started with Serverless Architectures

Example use cases

Page 70: Getting Started with Serverless Architectures

Live video stream processing

Cloudfront S3

Ingest

Lambda Functions

HQ Copy

480p

Transcode

360p

Transcode

Audio Only

Transcode

Thumbnails

S3

Playbac

k

Cloudfront

Streaming

Page 71: Getting Started with Serverless Architectures

Serverless Website

S3

Static

Content

Dynamic

Content

API Gateway Lambda DynamoDB

Page 72: Getting Started with Serverless Architectures

Use Cases

• Application Backend

• Data Processing

• Command and Control

• Any functional or event

based system

Page 73: Getting Started with Serverless Architectures

Tips and Tricks

• Limit your function size (JVM

startup time especially)

• Remember execution is async

• Don’t assume function container

reuse but take advantage of it

Page 74: Getting Started with Serverless Architectures

Tips and Tricks

• Remember the 500MB in /tmp

• Use function aliases

• Use the included logger

Page 75: Getting Started with Serverless Architectures

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.

Page 76: Getting Started with Serverless Architectures

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

Page 77: Getting Started with Serverless Architectures

Store your data properly

• No local instance

access

• Store everything in

S3, DynamoDB, or

Elasticache

DynamoDB S3

Page 78: Getting Started with Serverless Architectures

• zip up with

dependencies

• roles and permissions

• dev vs prod

• aliases

Difficulties we’ve solved

Page 79: Getting Started with Serverless Architectures

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

Page 80: Getting Started with Serverless Architectures

ReleaseTestBuild

ReleaseTestBuild

ReleaseTestBuild

ReleaseTestBuild

ReleaseTestBuild

Page 81: Getting Started with Serverless Architectures
Page 82: Getting Started with Serverless Architectures
Page 83: Getting Started with Serverless Architectures
Page 84: Getting Started with Serverless Architectures
Page 85: Getting Started with Serverless Architectures
Page 86: Getting Started with Serverless Architectures

Next Steps

Page 87: Getting Started with Serverless Architectures

• 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

Page 88: Getting Started with Serverless Architectures

• 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

Page 89: Getting Started with Serverless Architectures

Testing

• You can’t 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.

Page 90: Getting Started with Serverless Architectures

Questions?

Email: [email protected]

Twitter: @jedberg

Web: www.jedberg.net

Facebook: facebook.com/jedberg

Linkedin:

www.linkedin.com/in/jedberg

Company: cloudnative.io

Page 91: Getting Started with Serverless Architectures

Thank You!