GCP - Professional Cloud Developer Study Guide

    4: Integrating applications with Google Cloud services

    This chapter wires the deployed Cloud Run revisions and GKE workloads from earlier chapters into the data plane, the Google Cloud API surface, and the observability stack. It covers connection management against Cloud SQL, Firestore, Cloud Storage, and Pub/Sub; the four ways an application calls a Google Cloud API and the retry, pagination, and field-projection patterns that keep those calls cheap and reliable; and the OpenTelemetry-driven instrumentation that produces metrics, logs, and traces in Cloud Observability, including Error Reporting and Gemini-assisted root-cause analysis.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Manage connections to Cloud SQL, Firestore, and Cloud Storage from Cloud Run and GKE workloads using the recommended connector and Auth Proxy patterns.
    • Read from and write to Cloud SQL, Firestore, and Cloud Storage with the correct SDK shape for streaming, transactional, and batch workloads.
    • Publish and consume messages with Pub/Sub from inside an application service using the publisher batching, ordering-key, and streaming-pull receiver patterns.
    • Enable Google Cloud services through the Service Usage API and call those services through Cloud Client Libraries, REST, gRPC, or the API Explorer.
    • Apply field projection, pagination, batching, caching, and exponential backoff to Google Cloud API calls.
    • Use service accounts (and impersonation chains) to authenticate API calls from local development, Cloud Run, GKE, and external systems.
    • Instrument application code with metrics, logs, and traces through Google Cloud Observability and propagate trace context across service boundaries.
    • Diagnose application failures with Error Reporting, Cloud Trace, and Gemini-assisted observability.

    Executive Summary

    • Database connections from serverless and managed Kubernetes runtimes go through either the Cloud SQL Auth Proxy (or AlloyDB Auth Proxy) as a local sidecar, the language-specific Cloud SQL connector library, or the built-in Cloud Run + Cloud SQL connection over Unix socket; the right choice depends on the runtime, the IAM identity, and whether the workload owns its own VPC.
    • Cloud Storage and Firestore client libraries hide the HTTP and gRPC transport, but the developer still chooses streaming versus resumable uploads, transaction versus batched write, and snapshot listener versus one-shot read; the wrong choice is a frequent exam trap.
    • Pub/Sub publishers batch on three axes (element count, byte size, wait latency) and consumers pick between StreamingPull (long-lived bidirectional stream) and synchronous Pull; ordering keys force serial delivery on a single subscriber but limit horizontal scale.
    • Google Cloud APIs are reachable through four interfaces: Cloud Client Libraries (idiomatic, gRPC-first), Google API Client Libraries (auto-generated, REST), raw REST + JSON, and gRPC stubs; field masks, page tokens, and exponential backoff with jitter are the cross-cutting reliability patterns.
    • Application Default Credentials resolve identity in a fixed order (env var, gcloud user creds, attached service account); attached service accounts plus Workload Identity Federation are the production path, and JSON keys are an anti-pattern.
    • Cloud Observability is a Stackdriver-rebranded stack covering Cloud Logging, Cloud Monitoring, Cloud Trace, Cloud Profiler, and Error Reporting; OpenTelemetry is the canonical SDK, W3C Trace Context propagation correlates spans across services, and Gemini-assisted features summarize traces and surface log anomalies.

    Assumptions

    • All examples use the chapter-1 service-account model (dedicated user-managed service account per workload, attached at deploy time) and the chapter-2 image pipeline (Cloud Build, Artifact Registry, Binary Authorization). Terms defined in chapters 1 through 3 are reused without re-definition.
    • Code samples target Python 3.11 and Go 1.22 unless noted; concepts apply to Java and Node clients without change.
    • All resources live in a single billing-enabled project unless a snippet names a different project explicitly.
    • The chapter avoids version numbers for API surfaces that float; verify against the live client-library release notes for the exact constant names.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account