Google Cloud application architecture
Start from the workload, not the resource list
A fictional inventory application accepts authenticated internal requests, stores product records in PostgreSQL and publishes stock-change events. Choose Cloud Run for an HTTP container with variable demand; a Compute Engine VM gives more control of the guest OS, and GKE is useful when Kubernetes orchestration is actually needed. These are alternatives, not three mandatory deployments. A load balancer can add routing, TLS termination and health handling when required, but choose its scheme and supported backend based on the intended ingress. A private endpoint does not by itself authenticate the caller.
Authenticated internal caller -> Cloud Run catalog (regional, restricted ingress + IAM) -> Direct VPC egress -> private Cloud SQL endpoint -> Cloud Storage (private IAM) -> Pub/Sub topic -> authorized subscriber -> Secret Manager (runtime identity)Network owner: platform team; data owner: database team.Alternative compute: private Compute Engine VM or GKE workload.In the sketch, arrows show intended communication, not verified reachability. An internal load balancer or other supported internal caller path could be reviewed separately. No public bucket or unauthenticated service is needed.
Define the network boundary
A conventional Google Cloud VPC is global, while its ordinary subnets are regional. A VM has a zonal placement and uses a subnet in the containing region; Cloud Run is regional. Verify any specialized regional network variant separately. Use non-overlapping address ranges, explicit region choices and narrowly scoped firewall rules for allowed flows. Network policy and IAM answer different questions: a packet may reach a service without its caller being authorized.
# Static fragment; not an approved deployable configuration.resource "google_compute_network" "catalog" { project = "example-catalog-dev" name = "catalog-net" auto_create_subnetworks = false}resource "google_compute_subnetwork" "app" { project = "example-catalog-dev" name = "catalog-app" region = "us-central1" ip_cidr_range = "10.20.0.0/24" network = google_compute_network.catalog.id}The subnet references the network ID, giving Terraform a dependency. This fragment needs approved provider configuration, project and API prerequisites. A custom network is not an automatic guarantee of isolation: review inherited firewall policies, routes, DNS, access to Google APIs and any NAT or load balancer requirements. For VMs without external IP addresses, plan approved egress separately. For GKE, review node and control-plane access, Pod and Service address planning, network policies and workload identity.
Compose modules around explicit contracts
Keep network, application, and data lifecycle boundaries explicit. A network module exports identifiers; a service module receives them instead of creating a second network. A database module can expose a private connection identifier, not credentials. The caller chooses the intended project and location. Avoid circular module dependencies: foundational network and identity contracts should not depend on the application that consumes them.
# Illustrative module interfaces; module sources are not supplied.module "network" { source = "./modules/network" project_id = var.project_id region = var.region}module "catalog" { source = "./modules/catalog" project_id = var.project_id region = var.region network_id = module.network.network_id subnet_id = module.network.subnet_id}The modules here are interfaces only; no source is supplied and the fragment is not runnable. A module boundary is not a state or security boundary by itself. Separate root configurations and protected state where ownership or release cadence demands it. Avoid sharing broad state access simply to communicate a small output.
Connect the application and protect the data
Use a private Cloud SQL address with an approved private connectivity design (for example private services access where appropriate). Direct VPC egress gives Cloud Run a path into the network; database login, connection encryption, IAM where applicable, DNS, and firewall rules must also be verified. For the inbound service, restrict ingress and retain the intended authentication checks; egress configuration does not restrict inbound traffic.
# Static illustration; missing approved identity, image and prerequisites.resource "google_cloud_run_v2_service" "catalog" { name = "catalog" project = "example-catalog-dev" location = "us-central1" ingress = "INGRESS_TRAFFIC_INTERNAL_ONLY" template { service_account = var.approved_runtime_service_account containers { image = var.reviewed_image_digest } vpc_access { egress = "PRIVATE_RANGES_ONLY" network_interfaces { network = var.network_id subnetwork = var.subnet_id } } }}The snippet deliberately omits an actual image and service account. Neither the network nor an identity is created here. Provisioning identities and runtime identities should be separate; grant the runtime only the required secret-level access, storage permissions and messaging permissions. A secret reference is preferable to putting secret bytes in Terraform variables or state. Review API enablement and service-agent readiness as separate bootstrap responsibilities; a graph dependency does not guarantee immediate IAM propagation.
Design for retries and review before deployment
Pub/Sub normally permits message redelivery; make the consumer idempotent by recording the application event ID with its durable update. Acknowledge only after successful processing. Exactly-once options have scope and prerequisites and do not automatically make business effects exactly once. For this lesson assume the event sequence below and a transactional deduplication store.
event-7: reserve 1 itemevent-7: redelivery, no second reservationevent-8: reserve 2 itemsExpected total reservation: 3 itemsBefore a real plan, verify pinned schemas, images, identities, authorized project, service quotas, ingress/egress, failure tests and costs. All HCL in this lesson is static; the provider 7.25.0 and CLI 1.14.8 pins are provisional from previous chapters. Current Registry excerpts support resource names but exact schemas were not fully verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Google Cloud application architecture — knowledge check
Review private architecture, resource ownership and cost.
Which resource has regional scope in the conventional VPC model?
Which module input creates a direct dependency on the network module?
What does Direct VPC egress configure?
What should a subscriber do on duplicate delivery?
Who should have secret access for a running service?