The market offers a range of solutions to run stateless applications. One of the many perks is the scalability of such code. Learn from this talk how to come from Functions (do one thing) to the broad world of Cloud Run (do *anything*). Prepare your containers, the demos are about to start!
The Ultimate Guide to Choosing WordPress Pros and Cons
Serverless and you - where do i run my stateless code
1. Serverless and you
Where do I run my stateless code?
@gabidavila
gabi.dev
Gabi D'Ávila Ferrara
Developer Advocate - Google Cloud
2. 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
5. "It works on my machine"
- Every technical practitioner ever
@gabidavila
6. 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
7. 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
18. 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']
)
19. App Engine Standard
19
• Deploy an App
• Choose between 6 popular platforms
• Scale from 0 to "planet scale"
• Fully managed
App Engine
@gabidavila
20. 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. 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
24. 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
27. 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
36. 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
37. Concurrency Requests
• 1 request/instance:
• Cloud Functions
• Multiple requests/instance
• App Engine standard
• Cloud Run
• Cloud Run for Anthos
37@gabidavila