to think about runtime env Data transformations (ETL) Cloud-based HTTP glue and webhooks Constraints Runtimes: Node.js, Python, Go, Java Function level granularity Must interact via events No custom domain name Concurrency level of 1 (more cold starts) Good fit? Constraints?
in Cloud Storage, trigger a Cloud Functions instance Calling the Cloud Vision API for analysis Storing metadata in Cloud Firestore Lab 3 — Create a collage of pictures At a regular interval, with Cloud Scheduler Invoking a Cloud Run instance, to create a collage of recent pictures found in Cloud Firestore Storing collage in Cloud Storage Lab 2 — Create thumbnails Cloud Storage notifications sent to Pub/Sub Triggering a Cloud Run instance via Pub/Sub Creating a thumbnail with ImageMagick, and storing back into Cloud Storage Lab 4 — Create a web frontend Creating a web application with App Engine Listing pictures from Cloud Firestore Displaying pictures & collage from Cloud Storage g.co/codelabs/serverless-workshop
the cluster. Cloud Run on Anthos Deploy into Anthos, run serverless side-by-side with your existing workloads. Knative Everywhere Use the same APIs and tooling anywhere you run Kubernetes with Knative.
HTTP server must start < 4 min (timeout → 504) Request time < 15 min (default → 5 min) Stateless (in-memory file system, doesn’t persist) Computation only within request (No background activity)
256 MiB of memory up to a max of 4 GiB (configurable) 80 concurrent requests per container (configurable 1-80) 1000 max containers by default (configurable 1-1000) Access to a Metadata Server Sandboxed by gVisor
request-response workloads Scale: way up, down to zero, bursty Specific runtime requirements: language, dependencies, etc Constraints Must use containers Decide on build process (Cloud Build, etc)
in Cloud Storage, trigger a Cloud Functions instance Calling the Cloud Vision API for analysis Storing metadata in Cloud Firestore Lab 3 — Create a collage of pictures At a regular interval, with Cloud Scheduler Invoking a Cloud Run instance, to create a collage of recent pictures found in Cloud Firestore Storing collage in Cloud Storage Lab 2 — Create thumbnails Cloud Storage notifications sent to Pub/Sub Triggering a Cloud Run instance via Pub/Sub Creating a thumbnail with ImageMagick, and storing back into Cloud Storage Lab 4 — Create a web frontend Creating a web application with App Engine Listing pictures from Cloud Firestore Displaying pictures & collage from Cloud Storage g.co/codelabs/serverless-workshop
in Cloud Storage, trigger a Cloud Functions instance Calling the Cloud Vision API for analysis Storing metadata in Cloud Firestore Lab 3 — Create a collage of pictures At a regular interval, with Cloud Scheduler Invoking a Cloud Run instance, to create a collage of recent pictures found in Cloud Firestore Storing collage in Cloud Storage Lab 2 — Create thumbnails Cloud Storage notifications sent to Pub/Sub Triggering a Cloud Run instance via Pub/Sub Creating a thumbnail with ImageMagick, and storing back into Cloud Storage Lab 4 — Create a web frontend Creating a web application with App Engine Listing pictures from Cloud Firestore Displaying pictures & collage from Cloud Storage g.co/codelabs/serverless-workshop
app and not just single functions. App Engine goal: let developers focus on code, GCP handle the rest Can scale very quickly Open-source, idiomatic experience Use any library, extension, binary, or framework Python, Java, Node.js, PHP, Ruby, Go
Use any extension, binary, or framework • Supported Runtimes ◦ Python 3.7 (3.8 in beta) ◦ Java 11 ◦ Node.js 10 (12 in beta) ◦ PHP 7.3 ◦ Go 1.12 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 ⚠Not serverless!
traffic CDN static asset serving Constraints Standard (1st gen) • Runtimes for Python, Java, PHP, Go, Node.js Standard (2nd gen) • Can use use binary extensions • Python, Node.js, Java, Go, Ruby, PHP Flexible runtimes • Inherit Docker constraints • Not best for very low traffic sites (no scale to 0) • Slow deploy times Good fit? Constraints?
in Cloud Storage, trigger a Cloud Functions instance Calling the Cloud Vision API for analysis Storing metadata in Cloud Firestore Lab 3 — Run containers on schedule At a regular interval, with Cloud Scheduler Invoking a Cloud Run instance, to create a collage of recent pictures found in Cloud Firestore Storing collage in Cloud Storage Lab 2 — Create thumbnails Cloud Storage notifications sent to Pub/Sub Triggering a Cloud Run instance via Pub/Sub Creating a thumbnail with ImageMagick, and storing back into Cloud Storage Lab 4 — Create a web frontend Creating a web application with App Engine Listing pictures from Cloud Firestore Displaying pictures & collage from Cloud Storage g.co/codelabs/serverless-workshop
your language cloudevents.io Google Events Library Type library for CloudEvent#data Event parsing libraries HTTP POST to Cloud Run URL HTTP body is a CloudEvent with event data ("binary" CloudEvent V1) (optional) (optional) github.com/googleapis/google-cloudevents
delete notifications sent to Eventarc via Audit Logs Triggering a Cloud Run instance via Eventarc Cloud Run service deletes image thumbnails and metadata Lab 6 — Orchestration with Workflows Creating a workflow of our “business process” Reworking the services for an orchestrated architecture Triggering a Workflows from a Cloud Function g.co/codelabs/serverless-workshop
➕ Services can be changed independently ➕ Services can be scaled independently ➕ No single point of failure ➕ Events are useful to extend the system beyond the current domain Cons ➖ Difficult to monitor the whole system ➖ Errors / retries / timeouts are problematic ➖ The business flow is not captured explicitly ➖ Who ensures the whole transaction is successful?
and source controlled ➕ Each step can be monitored ➕ Errors / retries / timeouts are centralized ➕ Use simple REST, no need for events ➕ Services are still independent Cons ➖ A new orchestrator service to worry about ➖ Orchestrator could be a single point of failure ➖ Reliance on REST means more tight-coupling
Run Notify user Shipper Cloud Functions Prepare & ship items MAX: 5 times BACKOFF Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items Pager Cloud Run Escalate to support SUCCESS ERROR Configurable retries Configurable exception handling Errors and retries
ship items Pager Cloud Run Escalate to support SUCCESS ERROR Out of Stock? No Request from the supplier Yes Read inventory Inventory DB Update inventory Inventory DB Supplier API Conditionals and 3rd party calls
delete notifications sent to Eventarc via Audit Logs Triggering a Cloud Run instance via Eventarc Cloud Run service deletes image thumbnails and metadata Lab 6 — Orchestration with Workflows Creating a workflow of our “business process” Reworking the services for an orchestrated architecture Triggering a Workflows from a Cloud Function g.co/codelabs/serverless-workshop