Recipe

GCP Cloud Functions

Deploy lightweight, single-purpose serverless functions on Google Cloud. Trigger via HTTP, Pub/Sub, Cloud Storage, or Firestore events with zero server management.

Quick Start

  1. Enable the Cloud Functions API in your GCP project.
  2. Write a handler in Node.js, Python, or Go inside a functions/ directory.
  3. Deploy with gcloud functions deploy.
  4. Access via the auto-generated HTTPS endpoint or bind to an event source.

Triggers

  • HTTP — direct request/response, ideal for webhooks and APIs.
  • Pub/Sub — asynchronous message processing at scale.
  • Cloud Storage — react to object uploads, deletes, or metadata changes.
  • Firestore — run logic on document create, update, or delete events.

Best Practices

  • Keep functions stateless and idempotent.
  • Set memory and timeout limits appropriate to the workload.
  • Use environment variables for configuration, never hard-code secrets.
  • Monitor cold starts and optimize initialization paths.