Google Cloud Platform Services and Architecture Questions
Google Cloud Platform's core services and architecture: Compute Engine, Cloud Run, GKE, Cloud Storage, VPC, managed databases (Cloud SQL, Spanner, Firestore, Bigtable), and BigQuery-adjacent data services. Covers GCP service selection, networking, IAM and security specifics, cost and quota management, and reference patterns for building on the platform. For provider-agnostic compute, storage, or networking concepts, see the cross-cloud entries.
Design a scalable web application architecture on GCP to serve about 1 million monthly active users with peak concurrent traffic of 10,000 requests per second. Which services would you use for compute, load balancing, caching, session state, and the database, and how would you balance availability against cost?
Sample Answer
Direct answer
A global external Application Load Balancer with Cloud CDN (content delivery network) in front of a stateless compute tier, Memorystore for Redis handling both caching and session state rather than sticky sessions on the app tier (pinning a given user's repeat requests to one specific backend instance so it can keep their session in local memory), and a managed relational database with read replicas for anything needing strong consistency. Size the compute tier off the stated 10,000 requests per second (RPS) peak, not the 1 million monthly active users (MAU) headline figure, since those two numbers imply very different things about actual concurrent load.
Architecture
flowchart LR
C[Client] --> CDN[Cloud CDN]
CDN --> LB[Global external Application Load Balancer]
LB --> MIG[Compute tier: Cloud Run or GKE]
MIG --> CACHE[Memorystore for Redis: sessions and cache]
MIG --> DB[Primary database: Cloud SQL or Spanner]
DB --> REPLICA[Read replicas]
MIG -.metrics.-> MON[Cloud Monitoring]
- Compute. Cloud Run as the default for a request-driven web workload at this scale: it scales to zero between peaks, which matters because 1 million MAU very likely means far less than 10,000 RPS most of the day, only at peak. GKE (Google Kubernetes Engine) is the flip if the team already runs Kubernetes elsewhere or needs long-lived connections and custom autoscaling signals Cloud Run does not expose.
- Load balancing and CDN. The global load balancer terminates TLS and fans requests out by region; Cloud CDN caches static assets and cacheable API responses at Google's edge, which directly reduces the RPS the origin actually has to serve, worth stating explicitly since the 10,000 figure should be read as origin load after CDN offload, not before it.
- Caching and session state. Memorystore for Redis holds both the application cache and session state in one place, so any replica can serve any user's request without sticky sessions at the load balancer, which keeps autoscaling and failover simple.
- Database. Cloud SQL (managed Postgres or MySQL) with read replicas covers the typical read-heavy access pattern of a web application; Cloud Spanner is the right flip only once write throughput or dataset size genuinely outgrows what a single Cloud SQL primary can sustain, not adopted preemptively "just in case."
Worked capacity example
As an explicit assumption to validate with a real load test before launch, not a measured benchmark: if a single e2-standard-4 (a 4 vCPU Compute Engine machine type) application replica sustainably serves roughly 500 RPS for a lightweight JSON API, then 10,000 RPS divided by 500 RPS per replica is 20 replicas needed at peak. Provision the autoscaler with headroom above that, 25 to 30 replicas as a ceiling rather than exactly 20, to absorb one zone briefly losing capacity during a rolling update or a zonal disruption. The 500 RPS-per-replica figure is the first number to re-measure once real traffic exists, since it depends entirely on what a request actually does: one that hits the database on every call behaves very differently from one served mostly out of cache.
Balancing availability against cost
The single biggest availability-versus-cost decision here is regional scope. A multi-zone deployment within one region (multiple zones behind the regional backend, a Cloud SQL primary with a same-region standby for automatic failover) survives a zone outage at a modest cost premium over a single-zone design, roughly the cost of running enough replicas to tolerate losing one zone's worth of capacity, and is the right default at this scale. A full multi-region active-active design survives an entire region going down, but it roughly doubles infrastructure cost and adds real complexity keeping the database consistent across regions (cross-region replication lag, or a much more expensive globally-consistent option like Spanner in multi-region mode). For 1 million MAU with a 10,000 RPS peak, I would default to multi-zone within one region and treat full multi-region as something to add only once a specific SLA (service-level agreement) or regulatory requirement demands surviving a whole-region outage, since that jump in cost is large relative to the incremental availability it buys at this traffic level.
Trade-offs and pitfalls
Cloud Run's scale-to-zero is a double-edged default at this scale: a genuine cold start on the first request after an idle period adds latency exactly when a user is least tolerant of it, mitigated by setting a minimum instance count sized off historical trough traffic, not zero. Putting session state in Memorystore means a Memorystore outage takes down active sessions fleet-wide, a single point of failure traded for architectural simplicity, worth pairing with a Memorystore high-availability replica. Read replicas only help a read-heavy pattern; if the 10,000 RPS peak is actually write-heavy, an ingestion API rather than a typical read-mostly web app, the compute sizing above is optimistic and Spanner or a sharded design becomes relevant much sooner than the numbers here suggest. The most common wrong turn is sizing compute off the 1 million MAU headline instead of the stated 10,000 RPS peak; those two figures imply very different average concurrency depending on session length and usage pattern, and sizing off the wrong one either wastes budget or under-provisions for the load that actually matters.
Pub/Sub offers at-least-once delivery by default. What does that actually mean in practice for a consumer, and how would you design your consumer so that a redelivered message does not cause a duplicate side effect?
Sample Answer
Direct answer
At-least-once means Pub/Sub guarantees your subscriber will see every published message at least one time, but makes no promise against seeing the same message more than once: a slow ack, a subscriber crash between processing and acknowledging, or a lease expiring under load can all trigger a redelivery of a message you already handled. In practice this means every consumer has to be written as if duplicates are a normal, expected input, not an edge case, by making the operation the message triggers idempotent: processing the same message twice must produce the same end state as processing it once.
Structured elaboration
Why redelivery happens at all. A subscriber has a limited window (the ack deadline, configurable up to 600 seconds) to acknowledge a message after receiving it. If your processing takes longer than that window, if the process crashes after doing the work but before sending the ack, or if a network blip loses the ack in flight, Pub/Sub has no way to know the work was actually done, so it does the only safe thing: redeliver. This is a deliberate design choice (favoring "definitely processed, maybe twice" over "maybe never processed"), not a bug to work around.
Designing for idempotency, concretely:
- Deduplicate on a business key, not the Pub/Sub message ID. If the message represents "charge order 12345," check whether order 12345 has already been charged before charging it again, using your own datastore as the source of truth, not Pub/Sub's delivery bookkeeping (which only protects against the platform redelivering the identical message, not a publisher that legitimately sends a second, distinct message for the same logical event).
- Use a unique constraint as the actual enforcement mechanism, not just an application-level check-then-act. A database unique constraint on
order_idfor the charges table (or an equivalent conditional write) turns "check if already processed, then act" into an atomic operation, closing the race condition where two redelivered copies of the same message are processed concurrently by two workers and both pass the check before either writes. - Make the side effect itself naturally idempotent where possible. A
SET status = 'shipped'is idempotent by construction (running it twice leaves the same end state); anINSERTwithout a uniqueness constraint, or anincrement balance by X, is not, and needs the explicit dedup key above. - Layer Pub/Sub's exactly-once delivery feature on top, as defense in depth, not a substitute. It prevents the service from redelivering a message it already recorded as successfully acked, which reduces how often you hit the duplicate path in practice, but it doesn't protect against a publisher-side retry sending a second, distinct message for the same event, so the idempotency design above is still required regardless.
Worked example
An inventory service consumes a "reduce stock by 1" message per sale. A naive consumer runs UPDATE inventory SET stock = stock - 1 WHERE product_id = X, which is not idempotent: two deliveries of the same message reduce stock by 2 for one actual sale. The idempotent version tracks a processed-message table keyed by the order's business ID: INSERT INTO processed_orders (order_id) VALUES (X) ON CONFLICT DO NOTHING, checking the row count affected; only if the insert actually happened (meaning this order hasn't been processed before) does the consumer also run the stock decrement, wrapped in the same transaction so both writes commit or neither does. A redelivered duplicate then hits the ON CONFLICT DO NOTHING branch, skips the decrement entirely, and the stock count stays correct regardless of how many times Pub/Sub redelivers that message.
Trade-offs & pitfalls
- A check-then-act pattern without an atomic uniqueness guarantee (checking "have I seen this order?" in one query, then acting in a separate step) still has a race condition under concurrent redelivery; the dedup check and the side effect need to be atomic together, not sequential.
- Tracking every processed message ID forever grows the dedup table unbounded; scope it with a retention window matched to your maximum plausible redelivery delay (informed by your ack deadline and retry policy), and expire old entries rather than keeping them indefinitely.
- Relying solely on Pub/Sub's exactly-once delivery feature without also handling business-key-level duplicates is a common mistake, since it only closes the platform-redelivery gap, not the "the publisher legitimately sent this twice" gap that a retrying producer, a duplicate webhook trigger, or a replayed batch job can all cause.
Create a Terraform module skeleton that provisions a Cloud Storage bucket with versioning enabled, a lifecycle rule that deletes noncurrent object versions after 30 days, and customer-managed encryption keys. What inputs and outputs would the module expose, and what would you do about state management if many teams reuse it?
Sample Answer
Approach
Build a small, reusable Terraform module around one google_storage_bucket resource: versioning enabled, a lifecycle rule that deletes noncurrent object versions after a configurable number of days (30 by default), and a customer-managed encryption key (CMEK, a Cloud KMS key you control the lifecycle of, instead of Google's default encryption key) applied via the bucket's encryption block.
Terraform (HCL)
terraform {
required_version = ">= 1.5"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 8.0"
}
}
}
variable "project" {
description = "GCP project ID that owns the bucket"
type = string
}
variable "name" {
description = "Globally unique bucket name"
type = string
}
variable "location" {
description = "Bucket location, e.g. US, EU, or a region like us-central1"
type = string
default = "US"
}
variable "kms_key_name" {
description = "Fully qualified self link of the Cloud KMS CryptoKey used as the customer-managed encryption key (CMEK). The GCS service agent must already hold roles/cloudkms.cryptoKeyEncrypterDecrypter on this key."
type = string
}
variable "noncurrent_version_ttl_days" {
description = "Days to retain a noncurrent object version before it is deleted"
type = number
default = 30
}
resource "google_storage_bucket" "this" {
project = var.project
name = var.name
location = var.location
uniform_bucket_level_access = true
force_destroy = false
versioning {
enabled = true
}
lifecycle_rule {
condition {
days_since_noncurrent_time = var.noncurrent_version_ttl_days
}
action {
type = "Delete"
}
}
encryption {
default_kms_key_name = var.kms_key_name
}
}
output "bucket_name" {
description = "Name of the created bucket"
value = google_storage_bucket.this.name
}
output "bucket_url" {
description = "gs:// URL of the bucket"
value = google_storage_bucket.this.url
}
output "bucket_self_link" {
description = "Terraform/API self link of the bucket, for cross-module references"
value = google_storage_bucket.this.self_link
}
Verified with terraform init, terraform fmt -check, and terraform validate against the hashicorp/google provider; no cloud credentials are available in this environment, so this confirms the configuration is structurally valid, not that an apply would succeed against a real project.
Inputs and outputs
Inputs: project, name (must be globally unique across all of Cloud Storage, not just this project), location, kms_key_name, and noncurrent_version_ttl_days with a sensible default so most callers never need to set it. Outputs: the bucket's name, its gs:// url for referencing in application config, and its self_link so other modules (an IAM binding module, for instance) can depend on this bucket without re-deriving its identifier.
State management for multi-team reuse
Use a remote backend for the module's state, a GCS backend is the natural choice here, with versioning enabled on the state bucket itself and a distinct object prefix per calling team or bucket instance, for example prefix = "buckets/${var.name}". Never let multiple teams share one state file for this module: a single bad apply from one team locking or corrupting shared state blocks everyone else. Publish the module from a versioned source, a Git tag or a private Terraform Registry module version, rather than a mutable branch reference, so teams pin a version and upgrade deliberately instead of inheriting an unreviewed change on their next apply. One state file per bucket instance, one root module invocation per team, keeps the blast radius of any mistake limited to that one bucket.
Trade-offs and pitfalls
uniform_bucket_level_access = true disables legacy per-object ACLs in favor of IAM-only access control, the secure default, but it means any workflow relying on per-object ACLs has to migrate to IAM conditions instead. days_since_noncurrent_time counts from the moment a version becomes noncurrent, not from when the object was originally created; turning on versioning for the first time on an already-old bucket means existing objects have no noncurrent history yet, so the rule only starts working going forward, which is an easy thing to misread as "broken" when it is actually working exactly as designed. The single most common way this exact module fails on its first apply is forgetting the Cloud Storage service agent's own IAM grant on the KMS key (roles/cloudkms.cryptoKeyEncrypterDecrypter); without it, every write to the bucket fails with a permissions error that has nothing obviously to do with the bucket configuration itself.
You need to propose a migration plan for an on-prem OLTP MySQL database to GCP. What target options would you consider (Cloud SQL, Spanner, or self-managed MySQL on a VM), what migration methods are available, and how would you tailor the recommendation for a typical enterprise-sized database?
Sample Answer
Direct answer
For most on-prem transactional (OLTP, online transaction processing) MySQL migrations, the default target is Cloud SQL for MySQL, because it keeps the same engine, drivers, and application code path and mainly removes the operational burden of running the database yourself. Reach for Spanner only when the actual pain point is horizontal write scale or multi-region strong consistency that a single-writer MySQL topology genuinely cannot provide, and reach for self-managed MySQL on a Compute Engine virtual machine only when there is a specific, named capability (a storage engine plugin, an unsupported extension, a licensing constraint) that Cloud SQL's managed surface cannot accommodate.
What actually decides between the three targets
| Target | Choose when | What you give up |
|---|---|---|
| Cloud SQL for MySQL | Same engine, want managed backups, HA, and patching, vertical scale is enough | Some MySQL flags and plugins aren't exposed; a single-region-primary write ceiling |
| Cloud Spanner | Need horizontal write scale, multi-region strong consistency, a very high service-level agreement (SLA, the uptime guarantee a vendor commits to) tier | Different query dialect and consistency model; effectively an application rewrite, not a drop-in MySQL replacement |
| Self-managed MySQL on Compute Engine | Need a specific engine version, plugin, or extension Cloud SQL doesn't expose | You own patching, backups, HA, and failover yourself, all of it |
Migration methods per target
For a Cloud SQL target, Database Migration Service (DMS) gives continuous, binary-log-based replication for minimal-downtime migration, or a logical dump and restore for smaller, simpler databases where a short maintenance window is acceptable. For a Spanner target, this is a re-platform, not a lift-and-shift, tooling can convert schema and replicate changes, but application code touching joins, transactions, or auto-increment keys needs rework because Spanner's data model and consistency guarantees differ from MySQL's. For a self-managed VM target, DMS's Cloud SQL-specific tooling does not apply the same way, since the destination isn't a Cloud SQL API, this becomes native MySQL replication or a backup-and-restore, the same approach as any on-prem-to-on-prem move.
Tailoring for a typical enterprise-sized database
For an enterprise-sized OLTP database (tens of gigabytes to low terabytes, steady transactional load, application code already written against MySQL, a team that would rather not run database infrastructure), Cloud SQL for MySQL via DMS is the right recommendation in the large majority of cases. The bar for recommending Spanner instead is a demonstrated scaling ceiling, write throughput or dataset growth a single Cloud SQL primary genuinely cannot absorb even with a larger machine type and read replicas, not "it's Google's flagship database." The bar for self-managed is a specific named incompatibility with Cloud SQL, not general discomfort with managed services.
Worked example
A retailer's 800GB on-prem order-processing database runs roughly 2,000 write transactions per minute at peak, which works out to about 33 transactions per second. A right-sized Cloud SQL for MySQL instance with a read replica for reporting comfortably absorbs that load, there is no scaling signal here that justifies Spanner's re-platforming cost. If instead this were a global ledger needing consistent reads across three continents at ten times that write rate, the calculus flips toward Spanner despite the application rewrite, because no single-writer MySQL topology, managed or not, solves that problem.
Trade-offs and pitfalls
A common pitfall is recommending Spanner because it is technically impressive in the abstract while ignoring that migrating to it is a genuinely different data model, that rewrite cost has to be justified by an actual scaling need, not by reputation. A second pitfall is recommending self-managed MySQL on a VM "for control" without naming the specific capability Cloud SQL lacks, this just re-creates the operational burden the customer was trying to escape in the first place. A third pitfall is treating "enterprise" as a synonym for "needs Spanner," database size and the word "enterprise" do not by themselves correlate with a genuine write-scaling ceiling.
You have 20 minutes to demonstrate migrating a monolithic Java web app to Cloud Run. Outline the demo architecture, what you'd do live versus pre-provision, the minimal changes needed to containerize the app, and how you'd handle data connectivity.
Sample Answer
Direct answer
A 20-minute demo has to separate what proves the migration story from what would just burn the clock rebuilding infrastructure on stage: containerize and deploy the app live to show how little changes, but pre-provision anything that takes real wall-clock time to create, the database, the container registry, a warm base image, well before the demo starts.
Decision framework
- Pre-provision before the demo: an Artifact Registry repository (Google's container image storage) to push into, a Cloud SQL instance already running with schema and sample data loaded, the GCP project and any needed IAM (Identity and Access Management) permissions, and a first successful container build cached locally so the live build only re-layers a small change instead of pulling every base layer from scratch. None of this demonstrates the migration story; it's setup latency to hide.
- Do live: writing or revealing the Dockerfile and explaining it line by line, running the container build, deploying with a single
gcloud run deploycommand, hitting the live Cloud Run URL to show the app working, then a short burst of requests to show autoscaling. This is the part that proves the migration is real, not slides. - Minimal changes to containerize a monolithic Java web app: package the existing WAR or JAR (Java's packaged-application file formats: a WAR bundles a web app for a servlet container, a JAR is Java's general-purpose archive format) into a small base image with an entrypoint that starts it, and make sure the app listens on the port Cloud Run provides via the PORT environment variable (Cloud Run injects this at runtime, defaulting to 8080 if unset) rather than a hardcoded port. If the app relies on sticky, in-memory HTTP sessions, that's the one change that can't be skipped even for a demo: Cloud Run can run multiple instances and recycle a given instance between bursts, so session state needs to move to something external, a database table or Memorystore, or the demo will visibly break the moment it scales past one instance.
- Data connectivity: for Cloud SQL specifically, Cloud Run has built-in support for a Cloud SQL connection, configured with a flag pointing at the instance, that secures the connection over a Unix socket with no separate proxy sidecar and no VPC connector needed, the simplest and fastest thing to show live. Reaching anything else on a private network (an on-prem system, a VM without Cloud SQL's built-in integration) needs a Serverless VPC Access connector, which is exactly the kind of infrastructure setup to provision ahead of time rather than live, since it has no interesting migration story to tell.
Worked example
A concrete 20-minute run: minutes 0 to 2 show the existing monolith running on the old VM as the "before" state; minutes 2 to 8 walk through the already-written Dockerfile line by line and run the container build against a pre-warmed local cache so it finishes in well under a minute instead of pulling every layer fresh; minutes 8 to 12 run gcloud run deploy against the pre-provisioned Artifact Registry repo and project, pointing at the pre-existing Cloud SQL instance via the built-in connection flag; minutes 12 to 16 hit the live Cloud Run URL, show a real request round-trip including a database read, and generate a short burst of concurrent requests to show new instances spinning up; minutes 16 to 20 recap what changed in the source, little to nothing, versus what changed in how it deploys and scales, a lot, and take questions. The exact timings are illustrative for planning the segments, not a claim about how fast any specific command runs on the day.
Trade-offs and pitfalls
- Building the container image live from a completely cold cache is the single most common way a 20-minute demo runs over time; always pre-pull base layers and do a full build ahead of time so the live build is fast and its outcome is known.
- Skipping the session-state check because it's just a demo is a real risk if anyone asks to see it handle real concurrent load: a monolith with in-memory sticky sessions will visibly misbehave, users bounced between instances losing their session, the moment more than one instance is serving traffic, likely to happen on stage precisely because the demo is showing autoscaling.
- Relying on the built-in Cloud SQL connection without testing IAM permissions ahead of time, the service account Cloud Run runs as needs the Cloud SQL Client role at minimum, is a common last-minute failure; verify the full path once, in advance, exactly as it will run live.
- Treating "minimal changes to containerize" as "zero changes" oversells the migration story; removing hardcoded ports, externalizing session state if present, and reviewing local filesystem writes for persistence assumptions are real, if usually small, changes.
Unlock Full Question Bank
Get access to all Google Cloud Platform Services and Architecture interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.