1️⃣5️⃣ Architecture & Design Patterns - Overview¶
Learn system design and architecture patterns on Google Cloud Platform.
📋 Table of Contents¶
- Introduction
- Architecture Principles
- Design Patterns
- High Availability
- Disaster Recovery
- Scalability Patterns
- Security Patterns
Introduction¶
This section covers architectural patterns and best practices for building robust, scalable, and secure applications on GCP.
Architecture Pillars¶
┌─────────────────────────────────────────────────────┐
│ Well-Architected Framework │
├─────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Reliability │ │ Security │ │
│ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Performance │ │ Cost │ │
│ │ Efficiency │ │ Optimization │ │
│ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Operational │ │ Sustainability│ │
│ │ Excellence │ │ │ │
│ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────┘
Architecture Principles¶
1. Design for Failure¶
Assume everything fails
Principles:
✓ No single point of failure
✓ Graceful degradation
✓ Automatic recovery
✓ Health checks
✓ Circuit breakers
✓ Retry logic with exponential backoff
Example:
┌─────────────────────────────────────┐
│ Multi-Zone Deployment │
├─────────────────────────────────────┤
│ Region: us-central1 │
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ Zone A │ │ Zone B │ │
│ │ • App │ │ • App │ │
│ │ • DB │ │ • DB │ │
│ │ Primary │ │ Replica │ │
│ └──────────┘ └──────────┘ │
│ ▲ ▲ │
│ └──────┬──────┘ │
│ Load Balancer │
└─────────────────────────────────────┘
2. Decouple Components¶
Loose coupling for flexibility
Principles:
✓ Microservices architecture
✓ Event-driven design
✓ API-first approach
✓ Message queues
✓ Service mesh
✓ Async communication
Example:
Service A Service B
| |
v v
┌────────┐ ┌────────┐
│Publish │ │Publish │
└───┬────┘ └───┬────┘
| |
└────────┬────────┘
v
┌──────────┐
│ Pub/Sub │
└─────┬────┘
|
┌───────┼───────┐
v v v
┌────────┐┌────────┐┌────────┐
│Service ││Service ││Service │
│ C ││ D ││ E │
└────────┘└────────┘└────────┘
3. Scale Horizontally¶
Add more instances, not bigger ones
Principles:
✓ Stateless services
✓ Auto-scaling
✓ Load balancing
✓ Distributed caching
✓ Sharding
✓ Read replicas
Example:
Load Balancer
|
├─────────────────┐
v v
┌────────┐ ... ┌────────┐
│Instance│ │Instance│
│ 1 │ │ N │
└────────┘ └────────┘
| |
└────────┬────────┘
v
┌──────────┐
│ Database │
│ (Shared) │
└──────────┘
4. Implement Caching¶
Cache at every layer
Layers:
✓ CDN (Cloud CDN)
✓ Application cache (Memorystore)
✓ Database cache (query results)
✓ Browser cache
✓ API gateway cache
Example:
Client
|
v
┌─────────────┐
│ Cloud CDN │ <-- Edge cache
└──────┬──────┘
v
┌─────────────┐
│ Load Bal. │
└──────┬──────┘
v
┌─────────────┐
│ Application │
└──────┬──────┘
v
┌─────────────┐
│ Memorystore │ <-- App cache
└──────┬──────┘
v
┌─────────────┐
│ Database │
└─────────────┘
5. Security in Depth¶
Multiple layers of security
Layers:
✓ Network security (VPC, Firewall)
✓ Identity & access (IAM)
✓ Data encryption (at rest & in transit)
✓ Application security (IAP, Armor)
✓ Monitoring & logging
✓ Threat detection
Design Patterns¶
1. Microservices Architecture¶
Independent, loosely coupled services
┌─────────────────────────────────────┐
│ Microservices on GKE │
├─────────────────────────────────────┤
│ │
│ ┌──────────────────────────────┐ │
│ │ API Gateway / Ingress │ │
│ └────────────┬─────────────────┘ │
│ | │
│ ┌────────────┼────────────┐ │
│ v v v │
│ ┌────┐ ┌────┐ ┌────┐ │
│ │User│ │Order│ │Pay │ │
│ │Svc │ │ Svc │ │Svc │ │
│ └─┬──┘ └─┬──┘ └─┬──┘ │
│ | | | │
│ v v v │
│ ┌────┐ ┌────┐ ┌────┐ │
│ │ DB │ │ DB │ │ DB │ │
│ └────┘ └────┘ └────┘ │
└─────────────────────────────────────┘
Benefits: - Independent deployment - Technology diversity - Fault isolation - Scalability - Team autonomy
GCP Services: - GKE (orchestration) - Cloud Run (serverless) - Pub/Sub (messaging) - Cloud Endpoints (API management)
2. Serverless Architecture¶
No server management
┌─────────────────────────────────────┐
│ Serverless Architecture │
├─────────────────────────────────────┤
│ │
│ Client │
│ | │
│ v │
│ ┌──────────────┐ │
│ │ Cloud CDN │ │
│ └──────┬───────┘ │
│ v │
│ ┌──────────────┐ │
│ │ Cloud Run │ │
│ │ (API) │ │
│ └──────┬───────┘ │
│ | │
│ ┌────┼────┐ │
│ v v v │
│ ┌────┐┌────┐┌────┐ │
│ │Func││Func││Func│ │
│ └─┬──┘└─┬──┘└─┬──┘ │
│ v v v │
│ ┌──────────────┐ │
│ │ Firestore │ │
│ └──────────────┘ │
└─────────────────────────────────────┘
Benefits: - No infrastructure management - Auto-scaling - Pay-per-use - Fast deployment - Built-in HA
GCP Services: - Cloud Run - Cloud Functions - App Engine - Firestore - Pub/Sub
3. Event-Driven Architecture¶
React to events
┌─────────────────────────────────────┐
│ Event-Driven System │
├─────────────────────────────────────┤
│ │
│ Event Sources │
│ • Cloud Storage │
│ • Pub/Sub │
│ • Firestore │
│ • HTTP requests │
│ | │
│ v │
│ ┌──────────────┐ │
│ │ Eventarc │ │
│ └──────┬───────┘ │
│ | │
│ ┌────┼────┐ │
│ v v v │
│ ┌────────────────┐ │
│ │ Event Handlers │ │
│ │ • Cloud Run │ │
│ │ • Functions │ │
│ │ • Workflows │ │
│ └────────────────┘ │
└─────────────────────────────────────┘
Benefits: - Loose coupling - Scalability - Flexibility - Real-time processing - Async operations
GCP Services: - Eventarc - Pub/Sub - Cloud Functions - Workflows
4. CQRS (Command Query Responsibility Segregation)¶
Separate read and write operations
┌─────────────────────────────────────┐
│ CQRS Pattern │
├─────────────────────────────────────┤
│ │
│ Commands (Write) │
│ | │
│ v │
│ ┌──────────┐ │
│ │ Write DB │ │
│ │(Cloud SQL│ │
│ └────┬─────┘ │
│ | │
│ v (Events) │
│ ┌──────────┐ │
│ │ Pub/Sub │ │
│ └────┬─────┘ │
│ v │
│ ┌──────────┐ │
│ │ Read DB │ │
│ │(BigQuery)│ │
│ └────┬─────┘ │
│ | │
│ Queries (Read) │
└─────────────────────────────────────┘
Benefits: - Optimized reads and writes - Scalability - Performance - Flexibility - Complex queries
GCP Services: - Cloud SQL (writes) - BigQuery (reads) - Pub/Sub (events) - Dataflow (sync)
5. Strangler Fig Pattern¶
Gradual migration
┌─────────────────────────────────────┐
│ Strangler Fig Migration │
├─────────────────────────────────────┤
│ │
│ Phase 1: Route all to legacy │
│ ┌────────┐ │
│ │ Proxy │──────> Legacy System │
│ └────────┘ │
│ │
│ Phase 2: Route some to new │
│ ┌────────┐ │
│ │ Proxy │──────> Legacy System │
│ └───┬────┘ │
│ └──────────> New System │
│ │
│ Phase 3: Route all to new │
│ ┌────────┐ │
│ │ Proxy │──────> New System │
│ └────────┘ │
│ │
│ Phase 4: Decommission legacy │
│ ┌────────┐ │
│ │ Direct │──────> New System │
│ └────────┘ │
└─────────────────────────────────────┘
Benefits: - Gradual migration - Low risk - Continuous delivery - Rollback capability - Incremental value
GCP Services: - Cloud Load Balancing - Traffic Director - Cloud Run (new) - Compute Engine (legacy)
High Availability¶
Multi-Zone Deployment¶
99.99% availability
┌─────────────────────────────────────┐
│ Region: us-central1 │
├─────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ Zone A │ │ Zone B │ │
│ │ │ │ │ │
│ │ ┌──────┐ │ │ ┌──────┐ │ │
│ │ │ GKE │ │ │ │ GKE │ │ │
│ │ │Nodes │ │ │ │Nodes │ │ │
│ │ └──────┘ │ │ └──────┘ │ │
│ │ │ │ │ │
│ │ ┌──────┐ │ │ ┌──────┐ │ │
│ │ │Cloud │ │ │ │Cloud │ │ │
│ │ │SQL │ │ │ │SQL │ │ │
│ │ │Primary│ │ │ │Replica│ │
│ │ └──────┘ │ │ └──────┘ │ │
│ └──────────┘ └──────────┘ │
│ ▲ ▲ │
│ └──────┬──────┘ │
│ Regional Load Balancer │
└─────────────────────────────────────┘
Configuration:
# Create regional GKE cluster
gcloud container clusters create ha-cluster \
--region=us-central1 \
--num-nodes=1 \
--enable-autoscaling \
--min-nodes=1 \
--max-nodes=10
# Create HA Cloud SQL
gcloud sql instances create ha-instance \
--database-version=POSTGRES_14 \
--tier=db-n1-standard-2 \
--region=us-central1 \
--availability-type=REGIONAL
Multi-Region Deployment¶
99.99%+ availability with global reach
┌─────────────────────────────────────┐
│ Global Load Balancer │
│ (Anycast IP) │
└──────────┬──────────────────────────┘
|
┌──────┼──────┐
v v v
┌────────┐┌────────┐┌────────┐
│us-east1││eu-west1││asia-se1│
│ ││ ││ │
│ • GKE ││ • GKE ││ • GKE │
│ • SQL ││ • SQL ││ • SQL │
└────────┘└────────┘└────────┘
| | |
└─────────┼─────────┘
v
┌──────────────┐
│Cloud Spanner │
│ (Global) │
└──────────────┘
Disaster Recovery¶
RTO and RPO¶
Recovery objectives
┌─────────────────────────────────────┐
│ DR Strategies │
├─────────────────────────────────────┤
│ │
│ Strategy RTO RPO │
│ ───────────────────────────────── │
│ Backup/Restore Hours Hours │
│ Pilot Light Minutes Minutes │
│ Warm Standby Seconds Seconds │
│ Hot Standby None None │
└─────────────────────────────────────┘
Backup Strategy¶
# Automated Cloud SQL backups
gcloud sql instances patch my-instance \
--backup-start-time=03:00 \
--enable-bin-log
# GCS lifecycle for backups
gsutil lifecycle set lifecycle.json gs://backup-bucket
# lifecycle.json
{
"lifecycle": {
"rule": [
{
"action": {"type": "SetStorageClass", "storageClass": "NEARLINE"},
"condition": {"age": 30}
},
{
"action": {"type": "SetStorageClass", "storageClass": "COLDLINE"},
"condition": {"age": 90}
},
{
"action": {"type": "Delete"},
"condition": {"age": 365}
}
]
}
}
Scalability Patterns¶
Horizontal Scaling¶
┌─────────────────────────────────────┐
│ Auto-Scaling Pattern │
├─────────────────────────────────────┤
│ │
│ Load Balancer │
│ | │
│ ┌────┴────┐ │
│ v v │
│ ┌────┐ ┌────┐ │
│ │Pod │ │Pod │ <-- Min: 2 │
│ └────┘ └────┘ │
│ │
│ (Load increases) │
│ │
│ ┌────┐┌────┐┌────┐┌────┐ │
│ │Pod ││Pod ││Pod ││Pod │ <-- Max:10│
│ └────┘└────┘└────┘└────┘ │
└─────────────────────────────────────┘
Configuration:
# GKE Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Database Scaling¶
┌─────────────────────────────────────┐
│ Database Scaling │
├─────────────────────────────────────┤
│ │
│ Application │
│ | │
│ ┌────┴────┐ │
│ v v │
│ Write Read │
│ | | │
│ v v │
│ ┌────┐ ┌────┐ │
│ │Prim│ │Rep1│ │
│ │ary │──>│ │ │
│ └────┘ └────┘ │
│ | ┌────┐ │
│ └──────>│Rep2│ │
│ └────┘ │
└─────────────────────────────────────┘
Security Patterns¶
Zero Trust Architecture¶
┌─────────────────────────────────────┐
│ Zero Trust Security │
├─────────────────────────────────────┤
│ │
│ ┌──────────────────────────────┐ │
│ │ VPC Service Controls │ │
│ │ (Security Perimeter) │ │
│ └──────────────────────────────┘ │
│ │
│ ┌──────────────────────────────┐ │
│ │ Identity-Aware Proxy │ │
│ │ (Authentication) │ │
│ └──────────────────────────────┘ │
│ │
│ ┌──────────────────────────────┐ │
│ │ Workload Identity │ │
│ │ (Service-to-Service) │ │
│ └──────────────────────────────┘ │
│ │
│ ┌──────────────────────────────┐ │
│ │ Binary Authorization │ │
│ │ (Container Security) │ │
│ └──────────────────────────────┘ │
└─────────────────────────────────────┘
Best Practices¶
Architecture¶
✅ Design for failure
✅ Decouple components
✅ Scale horizontally
✅ Implement caching
✅ Use managed services
✅ Automate everything
✅ Monitor and observe
✅ Plan for disaster recovery
Performance¶
✅ Use CDN for static content
✅ Implement caching layers
✅ Optimize database queries
✅ Use appropriate instance types
✅ Enable auto-scaling
✅ Minimize latency
✅ Use regional resources
Security¶
✅ Implement defense in depth
✅ Use least privilege
✅ Encrypt data
✅ Enable audit logging
✅ Regular security reviews
✅ Implement zero trust
✅ Use private connectivity
Cost¶
✅ Right-size resources
✅ Use committed use discounts
✅ Implement auto-scaling
✅ Monitor costs
✅ Use appropriate storage tiers
✅ Delete unused resources
✅ Use preemptible instances
Next Steps¶
- High Availability - HA patterns
- Multi-Region Architecture - Global deployment
- Disaster Recovery - DR strategies
- Microservices - Microservices patterns
- Serverless Architecture - Serverless patterns
- Security Architecture - Security patterns
- Cost Optimization - Cost strategies
Additional Resources¶
- Architecture Center
- Best Practices
- Reference Architectures
- Solution Guides
- Cloud Architecture Framework
Last Updated: March 2026
Status: ✅ Complete