Cloud Functions

Cloud Functions

Google Cloud Functions Overview

Google Cloud Functions is a serverless execution environment that allows you to run your code in response to events without provisioning or managing servers. You simply write and deploy your code β€” Google handles the rest, including infrastructure, scaling, and availability.


πŸš€ Key Concepts

  • Event-Driven: Trigger functions via events from services like Cloud Storage, Pub/Sub, Firestore, Firebase, or HTTP requests.
  • Serverless: No need to manage servers. Google takes care of the OS and runtime.
  • Scalable: Functions automatically scale up/down based on demand.
  • Pay-As-You-Go: You only pay for what you use β€” no idle time billing.
  • Stateless: Each function call is isolated. Use Cloud Storage or Firestore for persistent data.
  • Isolated Execution: Each function runs in its own secure environment.

πŸ› οΈ Features

  • Multi-language Support: Write functions in Node.js, Python, Go, Java, .NET, or use Docker-based custom runtimes.
  • HTTP Triggers: Create APIs or webhooks using standard HTTP requests.
  • Background Triggers: React to events from other Google Cloud services.
  • CloudEvent Functions: .NET support using the CloudEvents spec for event data.
  • Integrated with Google Cloud: Deep integration with services like Pub/Sub, Firestore, and Cloud Storage.
  • Automatic Scaling: Scales with traffic load automatically.
  • Resource Configuration: Set memory, CPU, and timeout per function.
  • Monitoring & Logging: Built-in integration with Cloud Logging and Monitoring.

⚑ Second Generation Enhancements

  • Based on Cloud Run & Eventarc
  • Multi-event triggers
  • Cloud Storage volume mounts
  • Traffic splitting
  • Timeouts up to 60 minutes
  • Up to 32 GiB of memory and GPU support (in select regions)

πŸ’‘ Use Cases

  • Real-time Data Processing: Handle Cloud Storage uploads, Pub/Sub messages, IoT data.
  • Webhooks & Integrations: Respond to external events or trigger workflows.
  • API Backends: Build lightweight APIs for mobile/web apps.
  • Firebase Events: React to auth, Firestore, or analytics changes.
  • Automation: Cleanup, notifications, log processing, etc.
  • IoT Backends: Scalable processing for telemetry and sensor data.
  • Media Processing: Resize images, transcode videos.
  • Data Validation: Sanitize or transform data on the fly.

πŸ’° Pricing

You’re charged for:

  • Invocations: Per call after the free tier
  • Compute Time:
    • 1st Gen: GHz-seconds
    • 2nd Gen: vCPU-seconds
  • Memory Usage: GB-seconds
  • Networking:
    • Inbound: Free
    • Internal (same region): Free
    • Outbound: Billed after free tier
  • GPU (2nd Gen only): Charged per GPU-second

πŸ‘‰ Use the Google Cloud Pricing Calculator for estimates.


πŸ†š 1st vs 2nd Gen Comparison

Feature1st Gen2nd Gen
Execution TimeShortUp to 60 minutes
Resource OptionsLimitedMore (up to 32 GiB RAM)
Event TriggersSingle sourceMulti-source supported
Storage MountsβŒβœ… Cloud Storage volumes
GPU SupportβŒβœ… (in select regions)
Use Case FitSimple automationsComplex workloads

βœ… Summary

Google Cloud Functions offers a powerful, serverless platform for running event-driven code at scale. It’s ideal for modern cloud-native development and integrates deeply with the Google Cloud and Firebase ecosystem.