Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Serverless for mere mortals
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Nikolay Sverchkov
April 22, 2019
Programming
980
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Serverless for mere mortals
Nikolay Sverchkov
April 22, 2019
More Decks by Nikolay Sverchkov
See All by Nikolay Sverchkov
Authorization in the GraphQL era
ssnickolay
0
1k
Rails 6: ActiveRecord
ssnickolay
0
51
Serverless Is Ruby Future
ssnickolay
0
870
Anything new Rails 6?
ssnickolay
1
1.4k
Evolution of Rails application architecture: 14 years in production
ssnickolay
3
1.4k
A Healthy Monolith
ssnickolay
0
1.6k
Elixir. There and Back Again
ssnickolay
0
810
Other Decks in Programming
See All in Programming
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
570
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
620
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
170
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.5k
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
160
さぁV100、メモリをお食べ・・・
nilpe
0
150
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
130
Claspは野良GASの夢をみるか
takter00
0
210
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
OSもどきOS
arkw
0
590
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
150
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
14
6.8k
Featured
See All Featured
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
470
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
A designer walks into a library…
pauljervisheath
211
24k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
From π to Pie charts
rasagy
0
220
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Become a Pro
speakerdeck
PRO
31
6k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
400
The Invisible Side of Design
smashingmag
301
52k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Transcript
SERVERLESS FOR MERE MORTALS NIKOLAY SVERCHKOV @ssnickolay
None
evilmartians.com
None
SERVERLESS FOR MERE MORTALS
OR
HOW I REDUCED COSTS BY 250 TIMES USING SERVERLESS
PAST
IN-HOUSE SERVER A LONG TIME AGO
A LONG TIME AGO MAINTAINABILITY IN-HOUSE SERVER
DEDICATED SERVER NOT SO LONG AGO ovh.com
DEDICATED SERVER NOT SO LONG AGO SCALABILITY
CLOUDS NOT SO LONG AGO
CLOUDS NOT SO LONG AGO
CLOUDS NOT SO LONG AGO
CLOUDS NOT SO LONG AGO ? CPU ? RAM ?
DISK
http://bit.ly/2X9qnp5
None
?
KANYE WEST
None
~66.500 RUB
LOAD 0 25 50 75 100 0 1 2 3
4 5 6 7
LOAD 0 25 50 75 100 0 1 2 3
4 5 6 7
CAPACITY PLANNING
None
CLOUDS NOT SO LONG AGO CAPACITY PLANNING
MORE ABSTRACTION! move away from server assessment models
None
2014
HOW IT WORKS
; ; ; AWS Lambda 1. SLEEP SOURCE_CODE.ZIP S3
AWS Lambda 1. SLEEP 2. EVENT
AWS Lambda 1. SLEEP 2. EVENT 3. HANDLE
function(event, context) { console.log(event.key1); return “Success”; }
AWS Lambda 1. SLEEP 2. EVENT 3. HANDLE 4. RESPONSE
; ; ; AWS Lambda 1. SLEEP 2. EVENT 3.
HANDLE 4. RESPONSE 5. -> 1
HTTP ❤ EVENT
BLOG + STATIC PAGES RAILS 3; DO; NGINX ASSETS PIPELINE
User Lambda Markdown -> HTML
User S3 Lambda Assets Markdown -> HTML CloudFront
User S3 Lambda Assets Markdown -> HTML + CloudFront
NOTE 1: THE RIGHT SOLUTION (JAMstack) +
NOTE 2: CAUTION OPEN FLAME
NOTE 2: CAUTION OPEN FLAME
CAUTION OPEN FLAME
⏱ DEC 2018 % +
DEC 2018 MARCH 2019 % +
VS http://bit.ly/2Dd7R7X
SERVERLESS
SERVERLESS $ serverless create !--template aws-go !!==> serverless.yml
SERVERLESS $ serverless deploy $ serverless rollback !--timestamp timestamp $
serverless invoke -f functionName $ serverless logs -f functionName $ serverless create !--template aws-go !!==> serverless.yml
SERVERLESS $ serverless deploy $ serverless rollback !--timestamp timestamp $
serverless invoke -f functionName $ serverless logs -f functionName $ serverless ???? $ serverless create !--template aws-go !!==> serverless.yml
SAM(-CLI) https://github.com/lambci/docker-lambda Docker images and test runners that replicate the
live AWS Lambda environment
TEMPLATES https://github.com/serverless/examples
serverless.yml functions: post: !<<: *default handler: bin/post events: - http:
path: blog/{slug} method: get
post.go package main import ( "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" ) func Handler(ctx
context.Context, request Request) (events.APIGatewayProxyResponse, error) { !// put code here } func main() { lambda.Start(Handler) }
post.go func Handler(_, request Request) (_, _) { var buf
bytes.Buffer var slug = request.PathParameters["slug"] … }
post.go func Handler(_, request Request) (_, _) { var buf
bytes.Buffer var slug = request.PathParameters["slug"] post !:= lib.NewPost(slug, lambdaF.Config) if err !:= post.Render(&buf, lambdaF.Renderer); err !!= nil { return events.APIGatewayProxyResponse{StatusCode: 404}, err } … }
post.go func Handler(_, request Request) (_, _) { var buf
bytes.Buffer var slug = request.PathParameters["slug"] post !:= lib.NewPost(slug, lambdaF.Config) if err !:= post.Render(&buf, lambdaF.Renderer); err !!= nil { return events.APIGatewayProxyResponse{StatusCode: 404}, err } return lambdaF.Render(&buf) }
REDUCED x250 0.02$ vs 5$
+VAT = 6$!!! REDUCED x300
SERVERLESS UNDER THE MICROSCOPE
LOG $ serverless invoke -f index -l
LOG $ serverless invoke -f index -l START RequestId: <UUID>
Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
LOG $ serverless invoke -f index -l START RequestId: <UUID>
Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
LOG $ serverless invoke -f index -l START RequestId: <UUID>
Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
WHAT ABOUT CPU?
AWS Lambda allocates CPU power proportional to the memory… (с)
Amazon Docs
AWS Lambda allocates CPU power proportional to the memory… For
example, if you allocate 256 MB memory, your Lambda function will receive twice the CPU share than if you allocated only 128 MB. (с) Amazon Docs
https://aws.amazon.com/lambda/pricing/
6$ / PRICE(100ms) = 28.8M!
MEMORY / CST http://bit.ly/2UZ7xDL Completely Fair Scheduler (CFS)
FREE!
CST https://amzn.to/2Ix2t2O
COST !!<=> LANGUAGE
$ wrk -t10 -c400 -d20s -R40000 http://endpoint.url http://github.com/ssnickolay/dump2019
$ wrk -t10 -c400 -d20s -R40000 $ curl http://endpoint.url/[ruby/go] !=>
{“success”: true} http://github.com/ssnickolay/dump2019
0 250 500 750 1000 0 1 2 4 5
MAX AVG AVG ~80ms BATTLE (128 MB)
0 250 500 750 1000 0 1 2 4 5
MAX AVG AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 BATTLE (128 MB)
0 250 500 750 1000 0 1 2 4 5
0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 BATTLE (128 MB)
0 250 500 750 1000 0 1 2 4 5
0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 W IN BATTLE (128 MB)
0 250 500 750 1000 0 1 2 4 5
0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 W IN + BATTLE (128 MB)
0 250 500 750 1000 0 1 2 4 5
0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 BATTLE (128 MB)
BATTLE (128 MB) AVG ~1.8ms AVG ~80ms “Billed Duration: 100
ms” (c) Lambda Log
COST !!<=> PACKAGE SIZE
5.4MB 140KB COST !!<=> PACKAGE SIZE MIN SIZE
Go + WRK2 Milliseconds (AVG) 1,7 1,775 1,85 1,925 2
Megabytes 6 25 150 220
5.4MB 140KB COST !!<=> PACKAGE SIZE
http://rubyonjets.com/
COST !!<=> DEPENDENCIES
MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES
MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES
MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES
WAIT A MINUTE
https://stackoverflow.com/q/54110697
When you write your Lambda function code, do not assume
that AWS Lambda automatically reuses the execution context for subsequent function invocations…. (c) AWS Docs AWS LAMBDA EXECUTION CONTEXT
func Fibonacci(n uint) uint { if n !<= 1 {
return n } return Fibonacci(n-1) + Fibonacci(n-2) } OPTION 1
func Fibonacci(n uint) uint { if n !<= 1 {
return n } return Fibonacci(n-1) + Fibonacci(n-2) } func main() { lambda.Start(Handler) } OPTION 1
func Fibonacci(n uint) uint { if n !<= 1 {
return n } return Fibonacci(n-1) + Fibonacci(n-2) } !// Handler is our lambda handler invoked by !// the `lambda.Start` function call func Handler(ctx context.Context) (Response, error) { Fib !:= Fibonacci(33) !// noise here resp !:= Response{ Body: Fib } … } func main() { lambda.Start(Handler) } OPTION 1
Milliseconds (AVG) 0 250 500 750 1000 1 2 3
4 Golang (128MB + Fib) ~ 400ms Option1
var Fib uint func Fibonacci(n uint) uint {…} func Handler(ctx
context.Context) (Response, error) { … } func init() { Fib = Fibonacci(33) !// noise here } func main() {…} OPTION 2
Milliseconds (AVG) 0 250 500 750 1000 1 2 3
4 Golang (128MB + Fib) ~ 400ms Option1 Option2
COST SPEED ⏫
0 15000 30000 45000 60000 0 1 2 4 5
50347 requests in 20.00s Requests/sec: 2517.30 LOAD !!<=> $$$
0 15000 30000 45000 60000 0 1 2 4 5
50347 requests in 20.00s Requests/sec: 2517.30 PROTECTION 1: X-API-KEY
0 15000 30000 45000 60000 0 1 2 4 5
PROTECTION 2: AWS SHIELD 50347 requests in 20.00s Requests/sec: 2517.30
0 15000 30000 45000 60000 0 1 2 4 5
50347 requests in 20.00s Requests/sec: 2517.30 62808 requests in 20.01s Non-2xx or 3xx responses: 62127 1 1000 CONCURRENCY PROTECTION 3: THROTTLING
PREDICTABLY
PREDICTABLY
PREDICTABLY
RECIPE
1. TAKE SERVERLESS
1. TAKE SERVERLESS 2. FOLLOW RULES
1. TAKE SERVERLESS 2. FOLLOW RULES 3. ????
1. TAKE SERVERLESS 2. FOLLOW RULES 3. ???? 4. PROFIT
WHAT ABOUT PRODUCTION?
WHAT ABOUT PRODUCTION? Tung Nguyen
@ssnickolay Nikolay Sverchkov @ssnickolay THANK YOU! @evilmartians http://evl.ms/blog http://evl.ms/telegram