Slide 1

Slide 1 text

Why the fuzz about serverless?

Slide 2

Slide 2 text

1. What is serverless and why you should care 2. Who’s using serverless? 3. Serverless- fi rst, not serverless-only 4. Patterns & Anti-Patterns 5. The case for GraphQL & AppSync 6. Q&A

Slide 3

Slide 3 text

Yan Cui http://theburningmonk.com @theburningmonk AWS user since 2010

Slide 4

Slide 4 text

Yan Cui http://theburningmonk.com @theburningmonk running serverless in production since 2016

Slide 5

Slide 5 text

Yan Cui http://theburningmonk.com @theburningmonk independent consultant

Slide 6

Slide 6 text

“What is serverless?”

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Gojko Adzic It is serverless the same way WiFi is wireless. http://bit.ly/2yQgwwb

Slide 9

Slide 9 text

Serverless means… don’t need to worry about scaling don’t need to provision and manage servers

Slide 10

Slide 10 text

Serverless means… don’t need to worry about scaling don’t need to provision and manage servers don’t pay for it if no-one uses it

Slide 11

Slide 11 text

Lambda

Slide 12

Slide 12 text

Lambda S3 DynamoDB

Slide 13

Slide 13 text

Lambda S3 API Gateway DynamoDB AppSync

Slide 14

Slide 14 text

Lambda S3 API Gateway DynamoDB AppSync Cognito

Slide 15

Slide 15 text

Lambda S3 SQS SNS API Gateway DynamoDB AppSync EventBridge Cognito

Slide 16

Slide 16 text

Lambda S3 SQS SNS Step Functions API Gateway DynamoDB AppSync EventBridge Cognito

Slide 17

Slide 17 text

Lambda S3 SQS SNS Step Functions API Gateway DynamoDB AppSync Kinesis EventBridge Cognito

Slide 18

Slide 18 text

Lambda S3 SQS SNS Step Functions API Gateway DynamoDB AppSync Kinesis EventBridge Cognito You can build pretty much everything with serverless.

Slide 19

Slide 19 text

SCALABLE

Slide 20

Slide 20 text

https://www.vladionescu.me/posts/scaling-containers-on-aws-in-2022 Lambda

Slide 21

Slide 21 text

https://www.vladionescu.me/posts/scaling-containers-on-aws-in-2022 Lambda OUT-DATED!

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Every function can scale by 1,000 concurrent executions every 10 seconds, independently of each other.

Slide 24

Slide 24 text

RESILIENT

Slide 25

Slide 25 text

DynamoDB replicates data to 3 AZs

Slide 26

Slide 26 text

S3 has 99.999999999% (11 9s) durability

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Lambda, API Gateway, AppSync, etc. all provide built-in multi-AZ redundancy out-of-the-box

Slide 29

Slide 29 text

Lambda Workers (microVMs) don’t share memory

Slide 30

Slide 30 text

Lambda Workers (microVMs) process one invocation request at a time

Slide 31

Slide 31 text

Lambda Failures are isolated, no more system crash!

Slide 32

Slide 32 text

Lambda Workers are garbage collected every x hours

Slide 33

Slide 33 text

Lambda No more memory leaks and memory fragmentation issues

Slide 34

Slide 34 text

SECURE

Slide 35

Slide 35 text

Lambda Your code Your dependencies The OS EC2 instance Networking Physical infrastructure

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

COST-EFFICIENT

Slide 38

Slide 38 text

User Tra ff i c Cost Serverless Cost per transaction is highly predictable Cost tracks usage closely

Slide 39

Slide 39 text

WASTE User Tra ff i c Cost Serverless Serverful Cost can be predictable, but you overpay Cost per transaction is highly predictable Cost tracks usage closely

Slide 40

Slide 40 text

aws.amazon.com/solutions/case-studies/finra-data-validation

Slide 41

Slide 41 text

“FinDev”

Slide 42

Slide 42 text

$0.0000035 $0.0000004083 $0.00000125 cost per transaction: $0.0000051583 Lambda API Gateway DynamoDB

Slide 43

Slide 43 text

Donald Knuth We should forget about small ef fi ciencies, say about 97% of the time: premature optimization is the root of all evil.

Slide 44

Slide 44 text

input output engineering time lower operational cost

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

cost of the conversation: ~$50 per dev per hour x 8 = $400 potential saving: $10/month

Slide 47

Slide 47 text

cost of the conversation: ~$50 per dev per hour x 8 = $400 potential saving: $10/month break-even time for conversation: $400 ÷ $10/month = 40 months!!!

Slide 48

Slide 48 text

Donald Knuth We should forget about small ef fi ciencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

this is pretty $$$ input output engineering time lower operational cost

Slide 51

Slide 51 text

Knowing the cost of individual functions lets us optimise the right parts of our application

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

“I just want to get from A to B I don’t care how ”

Slide 57

Slide 57 text

Ownership Fuel Navigate To get there! Focus on getting there! uber

Slide 58

Slide 58 text

HW Ownership OS Runtime & Scale Code Physical Servers

Slide 59

Slide 59 text

HW Ownership OS Runtime & Scale Code Physical Servers Virtual Machines

Slide 60

Slide 60 text

HW Ownership OS Runtime & Scale Code Physical Servers Virtual Machines Containers

Slide 61

Slide 61 text

HW Ownership OS Runtime & Scale Code Focus on getting there! Physical Servers Virtual Machines Containers Serverless

Slide 62

Slide 62 text

leverage: do more with less

Slide 63

Slide 63 text

https://bit.ly/2Im61VK “Unless you’re an infrastructure company, infrastructure is basically overhead.” Matt Klein

Slide 64

Slide 64 text

bit.ly/social-network-in-4-weeks

Slide 65

Slide 65 text

leverage: do more with less

Slide 66

Slide 66 text

“Is serverless right for { insert industry }?”

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Streaming live sporting events 2 million+ concurrent users at peak

Slide 69

Slide 69 text

Streaming live sporting events 2 million+ concurrent users at peak Mix of containers and serverless Serverless for APIs, event processing, etc.

Slide 70

Slide 70 text

www.youtube.com/watch?v=C0pA5eZkmFk

Slide 71

Slide 71 text

aws.amazon.com/solutions/case-studies/bustle

Slide 72

Slide 72 text

twitter.com/ben11kehoe/status/1187027628152115200

Slide 73

Slide 73 text

https://www.infoq.com/news/2021/01/bbc-serverless-scale

Slide 74

Slide 74 text

Workloads transcend industry boundaries

Slide 75

Slide 75 text

“Serverless-First”

Slide 76

Slide 76 text

Start with serverless Move to container when it makes more sense

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

“Amazon has abandoned serverless!”

Slide 79

Slide 79 text

“Amazon has abandoned serverless!” It’s one service, by one team, within one business area…

Slide 80

Slide 80 text

Evolution Architecture "an approach to building software that's designed to evolve over time as business priorities change, customer demands shift, and new technologies emerge."

Slide 81

Slide 81 text

serverless Fast time-to-market

Slide 82

Slide 82 text

serverless Fast time-to-market Gains traction

Slide 83

Slide 83 text

Gains traction serverless Fast time-to-market Optimize for efficiency

Slide 84

Slide 84 text

services that charge by uptime are order of magnitude cheaper when running at scale

Slide 85

Slide 85 text

container Optimize for efficiency Gains traction serverless Fast time-to-market

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

“We can solve any problem by introducing an extra level of indirection.” Fundamental Theorem of Software Engineering

Slide 88

Slide 88 text

Anti-Patterns Patterns &

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

Synchronous Lambda-to-Lambda are almost always a sign of bad design.

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

Service Boundary

Slide 96

Slide 96 text

Service Boundary

Slide 97

Slide 97 text

Service Boundary

Slide 98

Slide 98 text

AWS Lambda function !== lambda function in programming

Slide 99

Slide 99 text

?

Slide 100

Slide 100 text

? ?

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

Service Boundary Service Boundary

Slide 105

Slide 105 text

Service Boundary Service Boundary

Slide 106

Slide 106 text

Implementation detail Service Boundary Service Boundary

Slide 107

Slide 107 text

Not a stable interface Service Boundary Service Boundary Implementation detail

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

container Optimize for efficiency Gains traction serverless Fast time-to-market

Slide 110

Slide 110 text

container Optimize for efficiency Gains traction serverless Fast time-to-market Caller shouldn’t have to rewrite their app when you change an implementation detail

Slide 111

Slide 111 text

Service Boundary Service Boundary

Slide 112

Slide 112 text

Service Boundary Service Boundary

Slide 113

Slide 113 text

Service Boundary Service Boundary

Slide 114

Slide 114 text

“Use Lambda functions to transform data, NOT transport data.”

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

Basic CRUD operation No business logic

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

“But why you go functionless?”

Slide 120

Slide 120 text

No Lambda = no cold starts

Slide 121

Slide 121 text

No Lambda = no Lambda-related costs

Slide 122

Slide 122 text

EventBridge Pipes

Slide 123

Slide 123 text

EventBridge Pipes

Slide 124

Slide 124 text

3rd party API EventBridge Pipes

Slide 125

Slide 125 text

3rd party API EventBridge Pipes Transform

Slide 126

Slide 126 text

OpenSearch

Slide 127

Slide 127 text

No-Code ETL OpenSearch

Slide 128

Slide 128 text

AppSync EventBridge OpenSearch

Slide 129

Slide 129 text

Step Functions EventBridge OpenSearch

Slide 130

Slide 130 text

Consider the ROI on every moving part in your architecture

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

?

Slide 134

Slide 134 text

?

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

Function URL

Slide 137

Slide 137 text

Function URL Lambdalith

Slide 138

Slide 138 text

“Lambdalith”

Slide 139

Slide 139 text

Lambdalith: run web app (e.g. express.js) inside Lambda

Slide 140

Slide 140 text

https://github.com/awslabs/aws-lambda-web-adapter

Slide 141

Slide 141 text

https://github.com/CodeGenieApp/serverless-express

Slide 142

Slide 142 text

https://bref.sh

Slide 143

Slide 143 text

https://github.com/zappa/Zappa

Slide 144

Slide 144 text

“Is it a good idea?”

Slide 145

Slide 145 text

If you’re not using API Gateway features (e.g. Cognito authoriser, request models, direct integration)

Slide 146

Slide 146 text

or, if you’re facing API Gateway limits (e.g. 29s timeout, no response streaming)

Slide 147

Slide 147 text

No API Gateway = no API Gateway costs

Slide 148

Slide 148 text

No API Gateway = no API Gateway latency overhead

Slide 149

Slide 149 text

Lambdalith Pros & Cons

Slide 150

Slide 150 text

Lambdalith Pros & Cons Familiar web framework

Slide 151

Slide 151 text

Lambdalith Pros & Cons Familiar web framework Testing is easier

Slide 152

Slide 152 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert

Slide 153

Slide 153 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control

Slide 154

Slide 154 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control Limited auth support

Slide 155

Slide 155 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control Limited auth support Large frameworks affect performance

Slide 156

Slide 156 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control Limited auth support Large frameworks affect performance Custom app metric with EMF

Slide 157

Slide 157 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control Limited auth support Large frameworks affect performance Custom app metric with EMF In-function authentication

Slide 158

Slide 158 text

No content

Slide 159

Slide 159 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control No per-endpoint auth Large frameworks affect performance Custom app metric with EMF In-function authentication YOU pay for unauthorised requests

Slide 160

Slide 160 text

Knowing the cost of individual functions lets us optimise the right parts of our application

Slide 161

Slide 161 text

Lambdalith Pros & Cons Familiar web framework Testing is easier No per-endpoint metric & alert Less fine-grained access control No per-endpoint auth Large frameworks affect performance Harder to tune performance & cost

Slide 162

Slide 162 text

“Is it a good idea?”

Slide 163

Slide 163 text

Consider the trade-offs before you go Lambdalith

Slide 164

Slide 164 text

Caching

Slide 165

Slide 165 text

Caching is a cheat code

Slide 166

Slide 166 text

Route53 CloudFront API Gateway Lambda DynamoDB

Slide 167

Slide 167 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching

Slide 168

Slide 168 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching

Slide 169

Slide 169 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching application-level caching

Slide 170

Slide 170 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching application-level caching ElastiCache

Slide 171

Slide 171 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching application-level caching Momento

Slide 172

Slide 172 text

bit.ly/social-network-in-4-weeks

Slide 173

Slide 173 text

average 99% cache hit rate

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

Lambda DynamoDB AppSync

Slide 176

Slide 176 text

A Query Language for your APIs + runtime for fulfilling queries with your data

Slide 177

Slide 177 text

schema

Slide 178

Slide 178 text

schema server AppSync

Slide 179

Slide 179 text

Client Server

Slide 180

Slide 180 text

Client Server Validates the request

Slide 181

Slide 181 text

schema { query: Query mutation: Mutation }

Slide 182

Slide 182 text

schema { query: Query mutation: Mutation } type Query { getProfile(id: ID!): Profile }

Slide 183

Slide 183 text

schema { query: Query mutation: Mutation } type Query { getProfile(id: ID!): Profile } ! = required ID is a built-in type

Slide 184

Slide 184 text

Profile is a type schema { query: Query mutation: Mutation } type Query { getProfile(id: ID!): Profile }

Slide 185

Slide 185 text

schema { query: Query mutation: Mutation } type Query { getProfile(id: ID!): Profile } type Profile { id: ID! firstName: String! lastName: String! }

Slide 186

Slide 186 text

schema { query: Query mutation: Mutation } type Query { getProfile(id: ID!): Profile @aws_lambda } type Profile { id: ID! firstName: String! lastName: String! } type Mutation { createProfile( firstName: String! lastName: String! ): Profile }

Slide 187

Slide 187 text

schema server AppSync

Slide 188

Slide 188 text

schema server data sources DynamoDB RDS ElasticSearch AppSync

Slide 189

Slide 189 text

GET https://myapp.com/user/1234 REST API { “id”: “1234”, “firstName”: “Yan”, “lastName”: “Cui”, “dob”: “…”, … }

Slide 190

Slide 190 text

GET https://myapp.com/user/1234 REST API { “id”: “1234”, “firstName”: “Yan”, “lastName”: “Cui”, “dob”: “…”, … } Returns data we don’t need

Slide 191

Slide 191 text

GET https://myapp.com/user/1234 REST API { “id”: “1234”, “firstName”: “Yan”, “lastName”: “Cui”, “dob”: “…”, … } Returns data we don’t need Overfetching

Slide 192

Slide 192 text

GET https://myapp.com/user/1234 REST API { “id”: “1234”, “firstName”: “Yan”, “lastName”: “Cui”, “dob”: “…”, … } Doesn’t have everything we need

Slide 193

Slide 193 text

GET https://myapp.com/sports/football GET https://myapp.com/sports/squash … GET https://myapp.com/user/1234/activities REST API GET https://myapp.com/user/1234

Slide 194

Slide 194 text

GET https://myapp.com/sports/football GET https://myapp.com/sports/squash GET https://myapp.com/user/1234/activities REST API GET https://myapp.com/user/1234 …

Slide 195

Slide 195 text

n+1 requests GET https://myapp.com/sports/football GET https://myapp.com/sports/squash GET https://myapp.com/user/1234/activities REST API GET https://myapp.com/user/1234 Underfetching …

Slide 196

Slide 196 text

GraphQL API POST https://myapp.com/graphql { getProfile (id: “1234”) { firstName lastName } }

Slide 197

Slide 197 text

GraphQL API POST https://myapp.com/graphql { getProfile (id: “1234”) { firstName lastName } } { “firstName”: “Yan”, “lastName”: “Cui” }

Slide 198

Slide 198 text

GraphQL API POST https://myapp.com/graphql { getProfile (id: “1234”) { friends { firstName lastName } } } { “friends”: [{ “firstName”: “Gerard”, “lastName”: “Sans” }, { “firstName”: “Ant”, “lastName”: “Stanley” }] }

Slide 199

Slide 199 text

GraphQL solves overfetching and underfetching

Slide 200

Slide 200 text

Strongly typed contract between client and server

Slide 201

Slide 201 text

Strongly typed contract between client and server Built-in request & response validation

Slide 202

Slide 202 text

Strongly typed contract between client and server Built-in request & response validation Mitigates data exfiltration risks

Slide 203

Slide 203 text

Implement “joins” with DynamoDB effortlessly

Slide 204

Slide 204 text

No content

Slide 205

Slide 205 text

AppSync

Slide 206

Slide 206 text

AppSync Pro fi le

Slide 207

Slide 207 text

AppSync Pro fi le

Slide 208

Slide 208 text

Pro fi le

Slide 209

Slide 209 text

Pro fi le Sport

Slide 210

Slide 210 text

Pro fi le Sport

Slide 211

Slide 211 text

AppSync Pro fi le Sport

Slide 212

Slide 212 text

AppSync Pro fi le Sport

Slide 213

Slide 213 text

Activity

Slide 214

Slide 214 text

Activity

Slide 215

Slide 215 text

AppSync Pro fi le Sport Activity

Slide 216

Slide 216 text

Enables rapid product iterations on the frontend

Slide 217

Slide 217 text

AppSync has built-in caching support

Slide 218

Slide 218 text

aws.amazon.com/appsync/pricing

Slide 219

Slide 219 text

AppSync full request caching

Slide 220

Slide 220 text

AppSync full request caching $context.arguments & $context.identity

Slide 221

Slide 221 text

AppSync full request caching Shared, static data are fetched multiple times $context.arguments & $context.identity

Slide 222

Slide 222 text

Full-request caching is kinda meh…

Slide 223

Slide 223 text

AppSync per-resolver caching

Slide 224

Slide 224 text

AppSync per-resolver caching Shared data is fetched once and cached

Slide 225

Slide 225 text

AppSync per-resolver caching Can specify different TTL & cache key for each resolver Shared data is fetched once and cached

Slide 226

Slide 226 text

average 99% cache hit rate

Slide 227

Slide 227 text

average p99 latency of < 250ms

Slide 228

Slide 228 text

Caching is a cheat code!

Slide 229

Slide 229 text

AppSync Subscriptions simplifies real-time applications

Slide 230

Slide 230 text

No content

Slide 231

Slide 231 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! }

Slide 232

Slide 232 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost: Post @aws_subscribe(mutations: [“addPost"]) }

Slide 233

Slide 233 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost: Post @aws_subscribe(mutations: [“addPost“]) }

Slide 234

Slide 234 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost: Post @aws_subscribe(mutations: [“addPost“]) } subscriber publisher subscriber subscriber

Slide 235

Slide 235 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost: Post @aws_subscribe(mutations: [“addPost“]) } publisher subscriber subscriber subscriber

Slide 236

Slide 236 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost: Post @aws_subscribe(mutations: [“addPost“]) } publisher subscriber subscriber subscriber

Slide 237

Slide 237 text

No content

Slide 238

Slide 238 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost(author: String, title: String, publishYear: Int, publishMonth: Int) : Post @aws_subscribe(mutations: [“addPost“]) }

Slide 239

Slide 239 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost(author: String, title: String, publishYear: Int, publishMonth: Int) : Post @aws_subscribe(mutations: [“addPost“]) } subscriber subscriber subscriber

Slide 240

Slide 240 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost(author: String, title: String, publishYear: Int, publishMonth: Int) : Post @aws_subscribe(mutations: [“addPost“]) } subscriber publisher subscriber subscriber

Slide 241

Slide 241 text

type Mutation { addPost(id: ID! author: String! title: String content: String url: String): Post! } type Subscription { addedPost(author: String, title: String, publishYear: Int, publishMonth: Int) : Post @aws_subscribe(mutations: [“addPost“]) } subscriber publisher subscriber subscriber

Slide 242

Slide 242 text

AppSync + Lambda + DynamoDB is the most efficient way to build data-driven applications

Slide 243

Slide 243 text

Summary

Slide 244

Slide 244 text

Synchronous Lambda-to-Lambda calls

Slide 245

Slide 245 text

🤔 Synchronous Lambda-to-Lambda calls Lambdalith

Slide 246

Slide 246 text

🤔 Synchronous Lambda-to-Lambda calls Lambdalith Functionless

Slide 247

Slide 247 text

🤔 Synchronous Lambda-to-Lambda calls Lambdalith Functionless GraphQL & AppSync

Slide 248

Slide 248 text

🤔 Synchronous Lambda-to-Lambda calls Lambdalith Functionless GraphQL & AppSync Caching

Slide 249

Slide 249 text

Questions?