Two of the biggest trends in applications development in recent years have been the rise of serverless and containerization. And Cloud Run has become a defacto container runtime service to production in seconds. Based on practical examples we will demonstrate how Cloud Run scores high in terms of developer experience. It differs from functions runtime as You can bring your own container, your own code, a folder, or binarys and it pairs great with the container ecosystem: Cloud Build, Cloud Code, Artifact Registry, and Docker. Each Cloud Run service gets an out-of-the-box stable HTTPS endpoint, with TLS termination handled for you. Map your services to your own domains and use either for web sites, backend APIs, workflows, invoke and connect services with the newest protocols of HTTP/2, WebSockets or gRPC (unary and streaming). Cloud Run is serverless containers, which means you don't have to fiddle with infrastructure or back-end resources to run applications.
2. ● Among the Top3 romanians on Stackoverflow 185k reputation
● Google Developer Expert on Cloud technologies
● Crafting Web/Mobile backends at REEA.net
● BigQuery + Redis database engine expert
Slideshare: martonkodok
Twitter: @martonkodok
StackOverflow: pentium10
GitHub: pentium10
Cloud Run: the rise of serverless and containerization @martonkodok
About me
3. 1. What is Serverless? What are Serverless pain points?
2. Cloud Run: Bringing serverless to containers
3. Demo
4. Best features, practical use cases
5. The rise of serverless and containerization with Cloud Run
6. Conclusions
Agenda
Cloud Run: the rise of serverless and containerization @martonkodok
4. What is Serverless
Cloud Run: the rise of serverless and containerization @martonkodok
Operational
Model
Programming
Model
No Infra Management Managed Security Pay only for usage
Service-based Event-driven Open
6. Containers
Cloud Run: the rise of serverless and containerization @martonkodok
.js .rb .go
.py .sh …
0 1 0
1 0 0
1 1 1
Any language
Any Library
Any Binary
Ecosystem of base images
8. Cloud Run
Cloud Run: the rise of serverless and containerization @martonkodok
Container to
production in
seconds
Natively
Serverless
One experience,
where you want it
9. Serverless compute options
Cloud Run: the rise of serverless and containerization @martonkodok
Serverless
functions
Source-based
HTTP and Events
Cloud
Functions
Serverless
applications
Source-based
HTTP and async
App
Engine
Serverless
HTTP workloads
Containers
HTTP and async
Cloud
Run
11. Serverless containers, where you want them
Cloud Run: the rise of serverless and containerization @martonkodok
Cloud Run (fully managed)
• Fully serverless
• No cluster to manage
• Pay for what you use
Cloud Run for Anthos
• Serverless developer experience
• Runs in your GKE cluster or on premise
12. Cloud Run: Pay-per-use
Cloud Run: the rise of serverless and containerization @martonkodok
CPU / Memory / Requests 100ms
14. Cloud Run Managed: Pricing
Cloud Run: the rise of serverless and containerization @martonkodok
15. “ Cloud Run
King of Serverless Compute?
Cloud Run: the rise of serverless and containerization @martonkodok
16. Cloud Run: King of Serverless Compute?
Cloud Run: the rise of serverless and containerization @martonkodok
Legacy FaaS solutions restricts you to use the tools provided
Flexibility to bring any dependencies/binaries to your application
Regardless of the language/runtime of your code
Eg: under a Node runtime, you can run a useful Golang binary
1/Dependencies
17. Cloud Run: King of Serverless Compute?
Cloud Run: the rise of serverless and containerization @martonkodok
Serverless tools make the promise of emulator (prod compatible environment)
Containers make the testing experience more consistent
Code and dependencies being packaged together
Eg: resulting a fewer “Works on my machine” moments
2/Testing
18. Cloud Run: King of Serverless Compute?
Cloud Run: the rise of serverless and containerization @martonkodok
Serverless tools don’t provide canary deployments (subset of traffic)
Allow traffic controls across revisions of a service
Label your services for gradual-rollout-strategy (--no-traffic, candidate, latest)
Eg: resulting an automated way to gradually roll out new versions of your Cloud Run services
3/Traffic Controls
19. Cloud Run: King of Serverless Compute?
Cloud Run: the rise of serverless and containerization @martonkodok
FaaS platforms are a vendor lock in, constraints on execution environment
Containers, containers, containers - your own environment
Ability to deploy anywhere (on premise, on VM, on Cloud Run, on Kubernetes, on GCP, AWS, Azure etc..)
Eg: resulting a service that doesn’t have a vendor lock in
4/Portability
20. Study by @BretMcG at * Serverless Days Milano 2019
Practical use cases
21. 1. Use a leaner base image (alpine, distroless, scratch for statically linked binary)
2. Use global scope (declare global variable, cache, reduce latency)
Mitigating cold starts
Cloud Run: the rise of serverless and containerization @martonkodok
3. IntroducingCloudRun:Minimuminstances
Costs: 10times less than regular price
22. gcloud beta run services update SERVICE --min-instances MIN-VALUE
gcloud beta run deploy --image IMAGE_URL --min-instances MIN-VALUE
Minimum Instances
Cloud Run: the rise of serverless and containerization @martonkodok
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/minScale: 'MIN-INSTANCE'
CLI
UI
YAML
23. 1. When no requests, scales down to 0. (costs savings)
2. Each service can scale by default to 1000 container instances (can be increased)
3. Each container instance can handle up to 250 simultaneous requests (!YAY websockets)
Note: 1000*250 => 250 000 simultaneous requests
Autoscaling
Cloud Run: the rise of serverless and containerization @martonkodok
24. 1. FaaS frameworks have fixed concurrency of 1
2. Cloud Run enables you to set concurrency (default 80, can be increased up to 250)
3. Risks! How a free trial experiment ended with a $72,000 bill overnight.
Concurrency
Cloud Run: the rise of serverless and containerization @martonkodok
Common errors:
➔ Uncontrolled retries, Loops (failing tests, missing backoff)
➔ Unwanted traffic (consider using Identity-Aware Proxy, Cloud Endpoint Service)
➔ Reduce concurrency
➔ DDOS (consider using Cloud-Armor, Load Balancer)
25. Cloud Run: Concurrency case study
Cloud Run: the rise of serverless and containerization @martonkodok
Concurrency=1 Clients: 400
Request=3
Concurrency=80 Clients: 400 Request=3
520
instances
150
instances
26. External HTTPs Load Balancer
Cloud Run: the rise of serverless and containerization @martonkodok
27. Multi-Region Load Balancing with Cloud Run
Cloud Run: the rise of serverless and containerization @martonkodok
28. WebSockets
Whiteboard demo
Demo #3
git clone https://github.com/socketio/socket.io.git
cd socket.io/examples/whiteboard/
gcloud beta run deploy whiteboard --source=.