Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Serverless and you @ Women Who Code London 2020

Serverless and you @ Women Who Code London 2020

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!

Avatar for Gabriela D'Ávila Ferrara

Gabriela D'Ávila Ferrara

February 21, 2020
Tweet

More Decks by Gabriela D'Ávila Ferrara

Other Decks in Programming

Transcript

  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 3 @gabidavila
  3. 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 7 @gabidavila
  4. 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 8 @gabidavila
  5. Cloud Functions 13 • Single-purpose • Mapped to Events or

    Triggers • NodeJS - 10 / 8 / 6 (deprecated), Python, Go • Use cases: • Microservices • IoT • Data Processing / ETL • Lightweight APIs Cloud Functions @gabidavila
  6. 17 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'] )
  7. App Engine Standard 18 • Deploy an App • Choose

    between 6 popular platforms • Scale from 0 to "planet scale" • Fully managed App Engine @gabidavila
  8. 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! 19 App Engine Standard @gabidavila
  9. 20 App Engine Standard Service - dev Service - prod

    App Engine Version A Inactive Inactive Version B Inactive Inactive Version C Active @gabidavila Receives traffic Version A Active Version B Active
  10. 23 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
  11. 24 Deploying a Ruby App $ gcloud app create $

    gcloud app deploy # app.yaml runtime: ruby25 entrypoint: bundle exec rackup service: default App Engine Standard
  12. 25 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
  13. Cloud Run (beta) 26 • 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
  14. 30 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"]
  15. 31 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
  16. 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 35
  17. Concurrency Requests • 1 request/instance: • Cloud Functions • Multiple

    requests/instance • App Engine standard • Cloud Run • Cloud Run for Anthos 36 @gabidavila