Serverless and you
Where do I run my stateless code?
@gabidavila
gabi.dev
Gabi D'Ávila Ferrara

Developer Advocate - Google Cloud
Serverless Definitions
Serverless:
• Focus on code
• Don't worry about infrastructure
• Auto-scaling (+ scaling to 0)
• Pay what you use
Stateless:
• Doesn't store data
• Doesn't store application state
• No persistent storage
2@gabidavila
Let's talk about servers
@gabidavila
Is serverless the new 

"Shared Hosting"?
🤔
"It works on my machine"
- Every technical practitioner ever
@gabidavila
The "good" old days
• Named servers:
• Zeus, Thor, Odin, you get the gist!
• Certificate/user management by a SysAdmin
• FTP or SCP:
• Try uploading Magento via FTP...
• SVN or CVS to deploy code (if even!)
• Almost zero automation
6@gabidavila
The "modern" approach
• Machines are a commodity
• CI/CD
• Automation: Chef, Terraform, Puppet...
• Easier to scale horizontally
• Don't forget the keywords of the moment:
• Containers, Kubernetes
7@gabidavila
Questions:
@gabidavila
Is Kubernetes serverless ?
@gabidavila
10
NO.
@gabidavila
Should I use serverless 

for Blockchain?
@gabidavila
12
NO
@gabidavila
Morecontext
Serverless on Google Cloud Platform
13
Cloud RunCloud Functions App Engine
@gabidavila
Cloud Functions
14
• Single-purpose
• Mapped to Events or Triggers
• NodeJS - 10 / 8 / 6 (deprecated), Python, Go
• Use cases:
• Microservices
• IoT
• Data Processing / ETL
• Lightweight APIsCloud Functions
@gabidavila
Accepted platforms
15
Cloud Functions
16
Cloud Functions
DEMO
fn.gabi.fyi?message=[status_id]
18
Cloud Functions
def classify(request):
request_json = request.get_json()
if request.args and 'message' in request.args:
tweet = get_tweet(request.args.get('message'))
elif request_json and 'message' in request_json:
tweet = get_tweet(request_json['message'])
else:
return u'Please inform a message'
sentiment = get_sentiment(tweet['text'])
return flask.jsonify(
text = tweet['text'],
screen_name = tweet['screen_name'],
sentiment = sentiment['sentiment'],
score = sentiment['score'],
magnitude = sentiment['magnitude']
)
App Engine Standard
19
• Deploy an App
• Choose between 6 popular platforms
• Scale from 0 to "planet scale"
• Fully managed
App Engine
@gabidavila
Services and Versions
• Create services inside of the same App Engine project
• Create different versions (and serve them!) through different services
• Use cases:
• Do A/B testing
• Create dev, test, staging and prod environments!
20
App Engine Standard
@gabidavila
21
App Engine Standard
Service - dev Service - prod
App Engine
Receives traffic
Version A
InactiveInactive
Version B
Inactive
Version A
Active
Version B
Active
Inactive
Version C
Active
@gabidavila
Runtimes
22
App Engine Standard
@gabidavila
DEMO
app.gabi.fyi/status/[status_id]
24
App Engine Standard
class App < Sinatra::Base
before do
content_type 'application/json'
end
get '/status/:id' do
twitter_client = Tweets.new
language_client = GLanguage.new
tweet_status = twitter_client.status(params[:id])
response = language_client.sentiments(tweet_status[:full_text])
response[:version] = 'v1.1'
response.to_json
end
end
25
Deploying a Ruby App
$ gcloud app create
$ gcloud app deploy
# app.yaml
runtime: ruby25
entrypoint: bundle exec rackup
service: default
App Engine Standard
26
Deploy Multiple Services
$ gcloud app deploy app.yaml dev.yaml
# app.yaml
runtime: ruby25
entrypoint: bundle exec rackup
service: default
App Engine Standard
# dev.yaml
runtime: ruby25
entrypoint: bundle exec rackup
service: dev
Cloud Run (beta)
27
• Fully Managed or on Anthos
• Container based
• Revision based
• Scale to zero or up and the amount of requests:
• requests = concurrency /instance * max instances
• Up to 2Gi of memory/revision
• Cloud Run on Anthos limits by your GKE cluster
Cloud Run
@gabidavila
Runtimes
28
Cloud Run
@gabidavila
29
Cloud Run
@gabidavila
DEMO
run.gabi.fyi/status/[status_id]
31
Deploying a Ruby App
Cloud Run
# Dockerfile
FROM ruby:2.5.0-stretch
EXPOSE 8080
RUN bundle config --global frozen 1
WORKDIR /usr/src/app
COPY src/Gemfile* ./
RUN bundle install
COPY src/ .
CMD ["rackup"]
32
Deploying a container
Cloud Run
$ gcloud builds submit --tag gcr.io/PROJECT_ID/APP_NAME
$ gcloud builds submit --tag gcr.io/automlgabi/sentiment-analyzer
Create your Cloud Run service:
$ gcloud beta run deploy --image 
--tag gcr.io/automlgabi/sentiment-analyzer 
--platform managed
@gabidavila
How to choose?
@gabidavila
34
How to choose?
35
How to choose? (cont.)
Compare
App Engine standard
environment
Cloud 

Functions
Cloud

Run (beta)1
Cloud Run for Anthos
(beta)1
Deployment artifact App Function Container Container
Scale to zero Pods2
Free tier
Websockets
Languages
Java, Node.js, Python,
Go, PHP, Ruby, .NET
Node.js, Python, Go Any Any
HTTP/2 and gRPC
Custom domain
Request timeout 1 minute3 9 minutes 15 minutes 15 minutes
GPUs and TPUs 36
Concurrency Requests
• 1 request/instance:
• Cloud Functions
• Multiple requests/instance
• App Engine standard
• Cloud Run
• Cloud Run for Anthos
37@gabidavila
Mix and Match
@gabidavila
DEMO
@gabidavila
40
Video Intelligence, GCS, Cloud Functions & App Engine
@gabidavila
41@gabidavila
Thank you.
• Twitter: @gabidavila
• Website: gabi.dev
42

Serverless and you - where do i run my stateless code