Microservices require both synchronous request/response and asynchronous event-driven communication.
→Use gRPC or HTTP for synchronous calls. Use Pub/Sub for asynchronous eventing and fan-out.
Why: Pub/Sub fully decouples services for reliability and independent scaling. Direct calls provide low-latency synchronous responses.
Reference↗
A stateless compute service (Cloud Run, Cloud Functions) needs to process temporary files.
→Use Cloud Storage for all temporary file I/O.
Why: The local filesystem of serverless platforms is ephemeral, in-memory, and not shared. Cloud Storage provides durable, scalable storage accessible by all instances.
Manage environment-specific configuration and secrets for GKE workloads following 12-factor principles.
→Use K8s ConfigMaps for non-sensitive config. Use Secret Manager for sensitive values, accessed securely via Workload Identity.
Why: Secret Manager is a more secure, managed, and auditable solution than K8s Secrets. Workload Identity avoids managing and distributing service account keys.
Reference↗
Application has extreme traffic peaks but long idle periods where cost must be minimized.
→Use Cloud Run with `min-instances` set to 0.
Why: Cloud Run can scale down to zero, eliminating all compute costs during idle periods. GKE and Compute Engine require minimum running nodes/instances.
Implement retries, circuit breakers, and mTLS consistently across microservices without application code changes.
→Deploy a service mesh (Anthos Service Mesh) on GKE.
Why: A service mesh injects resilience, security, and observability at the platform level, keeping application code clean and ensuring consistent behavior.
Expose backend services to external partners or mobile apps with rate limiting, API keys, and usage analytics.
→Use API Gateway in front of backend services (e.g., Cloud Run, GKE).
Why: API Gateway provides a fully managed solution for API lifecycle concerns (security, monitoring, versioning), offloading them from the backend service.
Reference↗
Select a durable, scalable, and strongly consistent store for an append-only log of events.
→Use Cloud Spanner for the event store.
Why: Spanner provides horizontal scalability with strong global consistency, crucial for maintaining the integrity of an event log at scale.
An API for a long-running job must respond immediately while processing continues in the background.
→API endpoint enqueues a task in Pub/Sub or Cloud Tasks and returns a 202 Accepted with a job ID. A separate worker (Cloud Run, Cloud Function) processes the task.
Why: This decouples the user-facing response time from the backend processing time, improving UX and system reliability. Use Cloud Storage for status updates.
Maintain data consistency across multiple microservices without a shared database.
→Implement the Saga pattern using an orchestrator (Cloud Workflows) or choreography (Pub/Sub events) with compensating transactions.
Why: Avoids complex and locking-prone two-phase commits, favoring eventual consistency which is a better fit for distributed systems.
Application calls a rate-limited third-party API where data changes infrequently.
→Use Memorystore for Redis as a distributed cache. Implement cache-aside pattern with TTL. Use a distributed lock (e.g., Redis SETNX) to prevent cache stampedes.
Why: A distributed cache shares data across all app instances, drastically reducing calls to the external API, improving latency and respecting rate limits.
A development team needs consistent, pre-configured, secure development environments with access to private VPC resources.
→Use Cloud Workstations.
Why: Cloud Workstations provides managed, container-based development environments with integrated security and VPC access, solving the "it works on my machine" problem.
Reference↗
A SaaS application requires tenants to have completely isolated data, encryption keys, and data residency.
→Use a project-per-tenant model. Manage provisioning and configuration centrally using IaC (Terraform).
Why: Provides the highest level of isolation for IAM, billing, quotas, networking, and data location, often required by enterprise or regulated customers.