@BretMcG
Bret McGowen
Google
Developer Advocate
@BretMcG
Where to run your
code in the cloud
Serverless, containers, or
virtual machines
@BretMcG
Who are you?
Mobile? Web? Students? Enterprise? Startup? Just learning? Using any
cloud? Google Cloud? Serverless? Kubernetes?
@BretMcG
Virtual machines
Containers & Kubernetes
Platform as a Service
Serverless Functions
@BretMcG
Quiz time!
@BretMcG
Quiz time!
Cloud Functions
App Engine
Kubernetes Engine (GKE)
Compute Engine
@BretMcG
Cloud Functions
App Engine
Kubernetes Engine (GKE)
Compute Engine
event driven
web facing code
containerized
applications
existing systems, special
hardware (GPU, GPU)
tl;dr
@BretMcG
Select
IaaS
OS
Setup
Containerization
Storage
Container
Orchestration
Networking
Monitoring
Logging
Testing
Developer User
What’s so hard about app development?
@BretMcG
OS
Application
Runtime
Application
Hardware
Functions
Application
infrastructure
@BretMcG
@BretMcG
Virtual Machine
OS
Application
Runtime
Application
Hardware
Dedicated Server
OS
Application
Runtime
Application
Hardware
Containers
OS
Application
Runtime
Application
Hardware
Functions Functions Functions
Application Platform
OS
Application
Runtime
Application
Hardware
Functions
Serverless
OS
Application
Runtime
Application
Hardware
Functions
Infrastructure Container Platform Function
Compute Engine Kubernetes Engine App Engine Cloud Functions
On-Premises
Highly customizable Highly managed
@BretMcG
Don't stress about
the "wrong"
decision
@BretMcG
Virtual
Machines
Google Compute Engine
Infrastructure as a Service
// Require the Stripe library w/ secret key.
const stripe = require('stripe')('sk_key...');
// Create a payment from a test card token.
const charge = await stripe.charges.create({
amount: 2000,
currency: 'usd',
source: 'tok_amex',
description: 'My first payment'
});
@BretMcG
Virtual
Machines
Google Compute Engine
Infrastructure as a Service
@BretMcG
@BretMcG
Dedicated Server
OS
Application
Runtime
Application
Hardware
Containers
OS
Application
Runtime
Application
Hardware
Functions Functions
Application Platform
OS
Application
Runtime
Application
Hardware
Functions
Serverless
OS
Application
Runtime
Application
Hardware
Functions
Container Platform Function
Kubernetes Engine App Engine Cloud Functions
On-Premises
Virtual Machine
OS
Application
Runtime
Application
Hardware
Functions
Infrastructure
Compute Engine
Highly customizable Highly managed
@BretMcG
Virtual machines and networking
● Per VM max: 160 CPUs, 3,844 GB of RAM, 64 TB of
disk, 96 GPUs, TPUs
● Independently configurable, including disk!
● Sole tenant nodes
Start quickly, ~20 seconds to user code running
Pre-built images, or create your own
● Debian, CentOS, CoreOS, Ubuntu, RHEL, SUSE
● Windows Server Datacenter: 2008, 2012 R2, 2016
What is Compute Engine?
Run your software
@BretMcG
Disk
Persistent Disk
● Live resize
● Network based
● Configure size (to 64 TB)
● Disk or SSD
● Independent of VM
Global Snapshots
Multi-VM RO mount
● Larger disks == more throughput
Local SSD
● Lowest latency
● 375 GB per disk (up to 8)
● Tied to VM lifecycle
@BretMcG
More than just virtual machines
Can run Docker containers directly on Container Optimized OS
Managed Instance Groups
● template / image based
● autoscaling
● regional groups (multi-zone)
● rolling updates and canaries
Load Balancer --> Google Front End, 1M QPS
@BretMcG
What do you think about?
Your software
Updating your software
Operating system / disk images
CPU, RAM, Disk
Networking
● Firewall rules
● Load balancers
● VPNs
@BretMcG
Good fit? Constraints?
Good fit
Existing systems (lift and shift)
1:1 container:VM mapping
Specific OS / kernel required
License requirements
Running databases
Network protocols beyond HTTP/S
Constraints
Scaling speed floor
~20s per VM, 1000s in ~60s
Decide how to handle software
updates yourself
@BretMcG
Demo
@BretMcG
Why Compute Engine?
Consistency - ask for 10 VMs, you get 10 good VMs
Custom VMs - choose RAM and CPU, GPUs
Live disk resize - also any size disk on any machine
Billing - Sustained use discounts, preemptible VMs, per minute billing
Live migrations - your VMs stay up longer
Architecture - good fit for most existing systems
BTW, we run services on GCE, too.
@BretMcG
Learn more
cloud.google.com/compute
@BretMcG
@BretMcG
Hello
world!
Hello
world!
Hello
world!
Hello
world!Hello
world! Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Image by Connie Zhou
Hello
world!
Hello
world!
Hello
world! Hello
world!
Hello
world! Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world! Hello
world!
Hello
world! Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world!
Hello
world! Hello
world!
Hello
world! Hello
world!
Hello
world!
Hello
world!
Google
Kubernetes
Engine (GKE)
Managed Kubernetes
or Containers as a Service
@BretMcG
@BretMcG
Dedicated Server
OS
Application
Runtime
Application
Hardware
Functions
Application Platform
OS
Application
Runtime
Application
Hardware
Functions
Serverless
OS
Application
Runtime
Application
Hardware
Functions
Platform Function
App Engine Cloud Functions
On-Premises
Virtual Machine
OS
Application
Runtime
Application
Hardware
Functions
Infrastructure
Compute Engine
Containers
OS
Application
Runtime
Application
Hardware
Functions
Container
Kubernetes Engine
Highly customizable Highly managed
@BretMcG
Containers?
Kubernetes?
Kubernetes Engine?
@BretMcG
kernel
libs
app
app app
app
Shared machines
x
x
x
No isolation
Common libs
Highly coupled apps & OS
x
libs
app
kernel
libs
app
libs
app
libs
app
Containers
Isolation
No common libs
Less overhead
Less dependency on host OS
Evolution of app infrastructure
x
x
app
libs
kernel
libs
app app
kernel
app
libs
libs
kernel
kernel
Virtual Machines
Isolation
No common libs
Expensive and inefficient
Hard to manage
@BretMcG
What are containers?
Performance
Repeatability
Isolation
Portability
...and more!
A fundamentally different way of managing applications
@BretMcG
# Dockerfile
FROM python
ENV APP_HOME /app
COPY . $APP_HOME
WORKDIR $APP_HOME
RUN pip install Flask
CMD ["python", "app.py"]
@BretMcG
I've got a bunch of apps/services
running in containers. Now what?
Kubernetes is open source and the
de facto platform for running containers.
@BretMcG
Kubernetes handles...
Scheduling:
Decide where my containers should run
Lifecycle and health:
Keep my containers running despite failures
Scaling:
Make sets of containers bigger or smaller
Naming and discovery:
Find where my containers are now
Load balancing:
Distribute traffic across a set of containers
Storage volumes:
Provide data to containers
Logging and monitoring:
Track what’s happening with my containers
Debugging and introspection:
Enter or attach to containers
Identity and authorization:
Control who can do things to my containers
@BretMcG
Making your app robust
Kubernetes keeps your applications running while you're asleep.
● Container died?
○ Restart it.
● Container unhealthy?
○ Reschedule to another node.
● Container overloaded?
○ Add more replicas automatically.
@BretMcG
C
BA
D
@BretMcG
C
BA
D
@BretMcG
C
BA
D
@BretMcG
B
C
A
D
B
@BretMcG
What do you think about?
Logical infrastructure
Applications, not computers or containers
Whiteboarding view
● What programs?
● How are they connected?
● Where do they store state?
@BretMcG
Good fit? Constraints?
Good fit
Run app in multiple environments
● Clouds, hybrid, dev/test/prod
Take full advantage of containers
Have good team communication
● Between dev, ops, security, etc.
Have or want CI/CD pipeline
Network protocols beyond HTTP/S
Constraints
Must use containers
Licensing (ex: per-machine)
Some architectural constraints
@BretMcG
Kubernetes
demo
@BretMcG
Learn more
cloud.google.com/gke
@BretMcG
Developers using Kubernetes still have a lot to do
Have to do
Write code
Build docker image
Upload image to registry
Deploy service
Expose to the internet
Setup logging & monitoring
Scale workload
Want to do
Write code
@BretMcG
It's not the right abstraction for end-developer experience.
(This did not stop developers from using Kubernetes directly!)
But it's a great platform for building a PaaS on top of.
Kubernetes isn't actually for developers
@BretMcG
Developer-focused:
let's get serverless
@BretMcG
Principles of
serverless
Invisible infrastructure
Automatic scaling
No paying for unused
CPU cycles
@BretMcG
Google App
Engine
Let us run & scale your code
or Platform as a Service
@BretMcG
@BretMcG
Dedicated Server
OS
Application
Runtime
Application
Hardware
Functions
Serverless
OS
Application
Runtime
Application
Hardware
Functions
Function
Cloud Functions
On-Premises
Virtual Machine
OS
Application
Runtime
Application
Hardware
Functions
Infrastructure
Compute Engine
Containers
OS
Application
Runtime
Application
Hardware
Functions
Container
Kubernetes Engine
Application Platform
OS
Application
Runtime
Application
Hardware
Functions
Platform
App Engine
Highly customizable Highly managed
@BretMcG
What is App Engine?
App Engine goal: let developers focus on code, while we handle the rest
“Serverless” before it was cool ;)
Started in 2008, with tradeoff: write it this way, we'll scale for you
Geared toward HTTP/web-facing applications
Can scale very quickly
@BretMcG
App Engine Standard (2nd gen)
● Open-source, idiomatic experience
● Use any extension, binary, or framework
● Supported Runtimes
○ Python 3.7
○ Java 8
○ Node.js 8, and Node.js 10 (beta)
○ PHP 7.2 (beta)
○ Go 1.11
@BretMcG
App Engine
Standard (2nd gen)
● Open-source, idiomatic experience
● Use any extension, binary, or framework
● Supported Runtimes
○ Python 3.7
○ Java 8
○ Node.js 8, and Node.js 10 (beta)
○ PHP 7.2 (beta)
○ Go 1.11
App Engine
Flexible
● Runs Docker containers
● Open source runtimes for Node.js, Ruby,
Java, Python, Go, PHP, .NET
● Also, if it runs in a Docker container,
you can run it ← nearly everything
@BretMcG
App Engine runtimes
Standard Standard 2nd generation
(soon!)
Flexible
Python 2.X, Java, PHP, Go Node.js 8 & 10, Python 3.7,
Go 1.11, PHP 7.2,
Node.js, Ruby, Java, Python,
Go, PHP, .NET
& custom container images
Sandboxed processes Runs on managed VMs
GAE specific APIs + GCP APIs Use GCP APIs directly
No binary modules/libraries any extension, binary, or framework
open-source, idiomatic experience
@BretMcG
What do you think about?
Code
HTTP Requests
Versions
@BretMcG
Good fit? Constraints?
Good fit
HTTP/S request-response
Stateless serving applications
Scaling to high traffic
Constraints
Standard (1st gen)
● Runtimes for Python, Java, PHP, Go, Node
Standard (2nd gen)
● Can use use binary extensions
● Python, Node, Java, Go
Flexible runtimes
● Inherit Docker constraints
● Not best for very low traffic sites
@BretMcG
Why App Engine?
Developers focus on code, while we handle the rest
Optimized for web serving workloads
Especially great for variable load
App Engine currently serves more than 320B requests per day
@BretMcG
App Engine:
Now Serving
320 Billion
requests per day
@BretMcG
App Engine
Demo
@BretMcG
Learn more
cloud.google.com/appengine
@BretMcG
Cloud
Functions
Event-driven functions
@BretMcG
@BretMcG
Dedicated Server
OS
Application
Runtime
Application
Hardware
Functions
On-Premises
Virtual Machine
OS
Application
Runtime
Application
Hardware
Functions
Infrastructure
Compute Engine
Containers
OS
Application
Runtime
Application
Hardware
Functions
Container
Kubernetes Engine
Application Platform
OS
Application
Runtime
Application
Hardware
Functions
Platform
App Engine
Serverless
OS
Application
Runtime
Application
Hardware
Functions
Function
Cloud Functions
Highly customizable Highly managed
@BretMcG
@BretMcG
Back end code functions that automatically
run in response to a trigger event
Microservices
Cloud "glue"
Node.js, Python, Go
Cloud Functions
@BretMcG
@BretMcG
Cloud Function event triggers
Cloud storage (incl. Firebase)
Cloud Pub/Sub
HTTPS
Firebase realtime database
& the new Firestore database
Firebase authentication
Google analytics for Firebase
Firebase hosting
Firebase Crashlytics
@BretMcG
Cloud Functions?
A serverless environment to build and connect cloud services
Event driven - connect Cloud services
● Via: HTTP requests, Cloud Storage, Firestore, Firebase events, and Cloud Pub/Sub
Serverless
● Fully managed execution environment
● Pay only for what you use
● Autoscales with usage
Node.js 6, 8, Python 3.7 (beta), Go 1.11 (beta)
Serverless Containers on GCF: sign up: g.co/serverlesscontainers
@BretMcG
What do you think about?
Events
Function definitions
@BretMcG
Good fit? Constraints?
Good fit
“Serverless”
Using Pub/Sub and/or Cloud Storage
Don't want to think about runtime env
Data transformations (ETL)
Cloud-based HTTP glue
Constraints
Two runtimes today: JS on Node.js and
Python
Function level granularity
Must interact via events
@BretMcG
Why Cloud Functions?
Don't have to even think about servers
Pay only for what you use
Simple developer experience (deploy functions not apps)
@BretMcG
Cloud Storage trigger
Cloud Storage
@BretMcG
Cloud Storage Cloud Functions
Cloud Storage trigger
@BretMcG
Cloud Storage Cloud Functions Cloud Vision API
Cloud Storage trigger
@BretMcG
Cloud Storage Cloud Functions Cloud Vision API
Cloud Storage trigger
@BretMcG
Cloud
Functions
demo
@BretMcG
@BretMcG
@BretMcG
Serverless containers
Secure on gVisor
Fully managed
BYO workloads
Pay for use & stateless
Alpha invitations coming
later this year
Sign up: g.co/serverlesscontainers
New: serverless containers on GCF (EAP)
@BretMcG
Containers on
Cloud Functions
demo
@BretMcG
@BretMcG
Join the Alpha:
g.co/serverlesscontainers
@BretMcG
Learn more
cloud.google.com/functions
@BretMcG
Where should I run my code?
@BretMcG
It depends
@BretMcG
Let's help you decide
@BretMcG
Recap - what do you think about?
Events
Function definitions
Code
HTTP Requests
Applications, not computers or containers
What programs? How are they connected? State?
Your software, operating system / disk images
CPU, RAM, Disk
Networking: Firewall rules, Load balancers, VPNs
Cloud Functions
App Engine
Kubernetes Engine
Compute Engine
@BretMcG
Technical requirements pull you down the stack
GPUs, need specific kernel, Windows,
software licensing requirements, migrating
most existing systems
Hybrid, need specific OS, network protocols
beyond HTTP/S
Support any programming language, run in
containers
Cloud Functions
App Engine
Kubernetes Engine
Compute Engine
@BretMcG
Team and organization
Team is mostly dev focused
Team is mostly dev focused
Team integration: Dev, Ops, Security work together;
org is open to app architecture updates
Adaptable to various team structures and tool
preferences
Cloud Functions
App Engine
Kubernetes Engine
Compute Engine
@BretMcG
Unsure? Containers let you move between
layers
Cloud Functions
App Engine
(2nd gen & Flex)
Kubernetes Engine
Compute Engine
(soon!)
@BretMcG
Most systems use multiple services
@BretMcG
Built-in integrations
@BretMcG
Actions
on Google
@BretMcG
Kubernetes vs Cloud Functions
@BretMcG
@BretMcG
Reasons for using Kubernetes vs serverless
Reduce lock-in
Performance
Multi-cloud
Customizability
Use custom hardware (GPU, TPU, IoT, etc)
Offline/reduced connectivity
Existing on-prem infrastructure
@BretMcG
App Engine vs Cloud Functions
@BretMcG
@BretMcG
Helping you decide: monoliths vs microservices
Choose the right
primitive for the
workload, or change
the workload
My Big
Java
Monolith
My Big
Java
Monolith
No!
Maybe
My
Discrete
Services
Yes!
✓
@BretMcG
Detour: Serverless Concurrency & Billing
Two Predominant Models:
1. Functions (Single Concern)
Billed per request, independent of instance
2. Apps (Multiple Concerns)
Billed per instance, independent of request
A Function (#1) model implies single concurrent
requests per instance!
@BretMcG
Detour: Cold Start Frequency vs
Duration
ColdStartDuration
Cold Start Frequency
App
Function
@BretMcG
Detour: Single vs Multi-purpose
App Function
Multi Purpose
Some Shared State
Multi-concurrent
Single Purpose
No Shared State
Single-concurrent
@BretMcG
Lifecycle: Compute Time & Threads
The App model bills for the lifetime of an instance,
handles concurrent requests and accommodates
for compute time outside the scope of a request
The Function model bills for the lifetime of a
request, handles a single concurrent request and
assumes a freeze/thaw model where compute time
is not available outside the scope of the request
@BretMcG
Why not add one more option?
@BretMcG
Kubernetes
• Powerful
• Can be Scary
Serverless
• Higher-level abstraction
• Similar in concept, but a lot
friendlier and easier to manage
Kubernetes
and Serverless
@BretMcG
● OSS project on GitHub, Apache 2 license
● Set of primitives (Build, Events, Serving)
● Solves for modern development patterns
● Implements learnings from Google, partners
● In collaboration with OSS FaaS frameworks
● github.com/knative
Kubernetes-based
platform to build,
deploy, and manage
modern serverless
workloads
Bonus: Introducing Knative
@BretMcG
SO WHAT SHOULD I CHOOSE?
@BretMcG
WELL IT DEPENDS ON YOUR APP
@BretMcG
SERIOUSLY IT DEPENDS
@BretMcG
JUST RECOMMEND SOMETHING
ALREADY
@BretMcG
OK FINE. Start with App Engine Standard (2nd gen)
Web apps or APIs
Idiomatic for each language
Stateless
Scales to zero
Scales up very quickly
Node 8, 10
Python 3.7
Go 1.11
Java 8
PHP 7.2
@BretMcG
Thank you
Bret McGowen
@BretMcG
cloud.google.com/compute
cloud.google.com/gke
cloud.google.com/appengine
cloud.google.com/functions
g.co/serverlesscontainers

Where should I run my code? Serverless, Containers, Virtual Machines and more