9οΈβ£ Databases - Overview¶
Learn database options on Google Cloud Platform.
π Table of Contents¶
- Introduction
- Database Types
- Database Services Comparison
- Decision Framework
- Architecture Patterns
- Cost Comparison
- Quick Reference
Introduction¶
GCP offers multiple database options for different use cases, from traditional relational databases to NoSQL and caching solutions.
Database Spectrum¶
Relational NoSQL Wide-Column In-Memory
| | | |
v v v v
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β Cloud β βFirestore β β Bigtable β βMemorystoreβ
β SQL β β(Document)β β (NoSQL) β β (Cache) β
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
ββββββββββββ
β Cloud β
β Spanner β
β(Global) β
ββββββββββββ
Database Types¶
1. Relational Databases¶
Cloud SQL - Managed MySQL, PostgreSQL, SQL Server
βββββββββββββββββββββββββββββββββββββββ
β Cloud SQL Instance β
βββββββββββββββββββββββββββββββββββββββ€
β Database Engine β
β - MySQL 5.7, 8.0 β
β - PostgreSQL 12, 13, 14, 15 β
β - SQL Server 2017, 2019, 2022 β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β - Automatic backups β
β - High availability β
β - Read replicas β
β - Point-in-time recovery β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - ACID transactions - SQL queries - Structured data - Up to 64 TB storage - Vertical scaling - Read replicas
Use Cases: - Web applications - E-commerce - CRM systems - ERP systems - Traditional applications
2. Globally Distributed Database¶
Cloud Spanner - Horizontally scalable relational database
βββββββββββββββββββββββββββββββββββββββ
β Cloud Spanner β
βββββββββββββββββββββββββββββββββββββββ€
β Global Distribution β
β βββββββββββ βββββββββββ β
β βRegion 1 β βRegion 2 β β
β β Node 1 β β Node 3 β β
β β Node 2 β β Node 4 β β
β βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β - Strong consistency β
β - Horizontal scaling β
β - 99.999% availability β
β - Global transactions β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - ACID transactions - SQL queries - Horizontal scaling - Global distribution - Strong consistency - 99.999% availability
Use Cases: - Global applications - Financial services - Gaming leaderboards - Supply chain - Inventory management
3. Document Database¶
Firestore - Serverless NoSQL document database
βββββββββββββββββββββββββββββββββββββββ
β Firestore β
βββββββββββββββββββββββββββββββββββββββ€
β Collections & Documents β
β /users/{userId} β
β - name: "John" β
β - email: "john@example.com" β
β /orders/{orderId} β
β - items: [...] β
β - total: 100 β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β - Real-time sync β
β - Offline support β
β - Automatic scaling β
β - Mobile/web SDKs β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Document model - Real-time updates - Offline support - Automatic scaling - Mobile/web SDKs - Serverless
Use Cases: - Mobile applications - Real-time apps - User profiles - Chat applications - Collaborative apps
4. Wide-Column Database¶
Bigtable - Petabyte-scale NoSQL database
βββββββββββββββββββββββββββββββββββββββ
β Bigtable β
βββββββββββββββββββββββββββββββββββββββ€
β Row Key | Column Family β
β user#1 | profile:name β
β | profile:email β
β | activity:last_login β
β user#2 | profile:name β
β | activity:page_views β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β - Petabyte scale β
β - Low latency (<10ms) β
β - High throughput β
β - HBase compatible β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Wide-column store - Petabyte scale - Low latency - High throughput - HBase API - Time-series data
Use Cases: - Time-series data - IoT data - Analytics - Financial data - AdTech
5. In-Memory Cache¶
Memorystore - Managed Redis and Memcached
βββββββββββββββββββββββββββββββββββββββ
β Memorystore β
βββββββββββββββββββββββββββββββββββββββ€
β Redis / Memcached β
β βββββββββββββββββββββββββββββββ β
β β Key-Value Store β β
β β - session:user123 β β
β β - cache:product_list β β
β β - counter:page_views β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β - Sub-millisecond latency β
β - High availability β
β - Automatic failover β
β - Up to 300 GB β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - In-memory storage - Sub-millisecond latency - Key-value store - Pub/Sub support (Redis) - High availability - Automatic failover
Use Cases: - Session storage - Caching layer - Real-time analytics - Leaderboards - Rate limiting
Database Services Comparison¶
Feature Matrix¶
| Feature | Cloud SQL | Cloud Spanner | Firestore | Bigtable | Memorystore |
|---|---|---|---|---|---|
| Type | Relational | Relational | Document | Wide-column | Key-value |
| Model | SQL | SQL | NoSQL | NoSQL | NoSQL |
| Transactions | ACID | ACID | ACID | Single-row | No |
| Scaling | Vertical | Horizontal | Automatic | Horizontal | Vertical |
| Max Size | 64 TB | Unlimited | Unlimited | Petabytes | 300 GB |
| Latency | 5-10ms | 5-10ms | 10-20ms | <10ms | <1ms |
| Consistency | Strong | Strong | Strong | Eventual | Strong |
| Global | No | Yes | Yes | No | No |
Performance Comparison¶
| Database | Read Latency | Write Latency | Throughput | Best For |
|---|---|---|---|---|
| Cloud SQL | 5-10ms | 5-10ms | 10K QPS | Traditional apps |
| Cloud Spanner | 5-10ms | 5-10ms | 100K+ QPS | Global apps |
| Firestore | 10-20ms | 10-20ms | 10K QPS | Mobile/web apps |
| Bigtable | <10ms | <10ms | 1M+ QPS | Analytics, IoT |
| Memorystore | <1ms | <1ms | 1M+ QPS | Caching |
Decision Framework¶
Decision Tree¶
What type of data?
|
ββ> Structured + SQL needed?
| ββ> Global distribution? β Cloud Spanner
| ββ> Regional? β Cloud SQL
|
ββ> Document/JSON data?
| ββ> Mobile/web app? β Firestore
| ββ> Large scale? β Bigtable
|
ββ> Time-series/Analytics?
| ββ> Bigtable
|
ββ> Caching/Session?
ββ> Memorystore
Use Case Matrix¶
| Requirement | Recommended | Alternative |
|---|---|---|
| Web application | Cloud SQL | Cloud Spanner |
| Mobile app | Firestore | Cloud SQL |
| Global app | Cloud Spanner | Firestore |
| Analytics | Bigtable | BigQuery |
| Time-series | Bigtable | Cloud SQL |
| IoT data | Bigtable | Firestore |
| Caching | Memorystore | - |
| Session store | Memorystore | Firestore |
| E-commerce | Cloud SQL | Cloud Spanner |
| Gaming | Cloud Spanner | Firestore |
Architecture Patterns¶
Pattern 1: Traditional Web Application¶
Internet
|
v
βββββββββββββββββββββββ
β Cloud Load β
β Balancer β
ββββββββββββ¬βββββββββββ
|
ββββββββ΄βββββββ
v v
ββββββββββ ββββββββββ
β App β β App β
β Server β β Server β
ββββββ¬ββββ βββββ¬βββββ
| |
βββββββ¬ββββββ
v
ββββββββββββββββ
β Cloud SQL β
β (Primary) β
ββββββββ¬ββββββββ
|
ββββββββ΄ββββββββ
v v
βββββββββββ βββββββββββ
β Replica β β Replica β
β (Read) β β (Read) β
βββββββββββ βββββββββββ
Pattern 2: Global Application¶
βββββββββββββββββββββββββββββββββββββββ
β Cloud Spanner β
β (Multi-region, Global) β
ββββββββββββ¬βββββββββββββββββββββββββββ
|
ββββββββΌβββββββ
v v v
ββββββββββββββββββββββββ
β US ββ EU ββ Asia β
β App ββ App ββ App β
ββββββββββββββββββββββββ
Pattern 3: Mobile Application¶
Mobile Clients
|
v
βββββββββββββββββββββββ
β Firestore β
β (Real-time sync) β
ββββββββββββ¬βββββββββββ
|
ββββββββ΄βββββββ
v v
ββββββββββββ ββββββββββββ
β Cloud β β Cloud β
β Functionsβ β Run β
ββββββββββββ ββββββββββββ
Pattern 4: Analytics Pipeline¶
IoT Devices
|
v
βββββββββββββββββββββββ
β Pub/Sub β
ββββββββββββ¬βββββββββββ
v
ββββββββββββββββ
β Dataflow β
ββββββββ¬ββββββββ
v
ββββββββββββββββ
β Bigtable β
β (Hot data) β
ββββββββ¬ββββββββ
|
v (Archive)
ββββββββββββββββ
β BigQuery β
β (Analytics) β
ββββββββββββββββ
Pattern 5: Caching Layer¶
Application
|
v
βββββββββββββββββββββββ
β Memorystore β
β (Redis Cache) β
ββββββββββββ¬βββββββββββ
|
Cache Miss
v
ββββββββββββββββ
β Cloud SQL β
β (Database) β
ββββββββββββββββ
Cost Comparison¶
Monthly Cost Examples (us-central1)¶
Scenario 1: Small Web Application
| Database | Configuration | Monthly Cost |
|---|---|---|
| Cloud SQL | db-f1-micro, 10 GB | $15 |
| Cloud SQL | db-n1-standard-1, 10 GB | $50 |
| Cloud Spanner | 1 node | $730 |
| Firestore | 1 GB, 100K reads/day | $1 |
| Memorystore | 1 GB Redis | $50 |
Scenario 2: Medium Application
| Database | Configuration | Monthly Cost |
|---|---|---|
| Cloud SQL | db-n1-standard-4, 100 GB | $300 |
| Cloud Spanner | 3 nodes | $2,190 |
| Firestore | 10 GB, 1M reads/day | $10 |
| Bigtable | 3 nodes, 1 TB | $1,500 |
| Memorystore | 5 GB Redis | $250 |
Scenario 3: Large Scale Application
| Database | Configuration | Monthly Cost |
|---|---|---|
| Cloud SQL | db-n1-highmem-16, 1 TB | $2,000 |
| Cloud Spanner | 10 nodes | $7,300 |
| Bigtable | 10 nodes, 10 TB | $5,000 |
| Memorystore | 100 GB Redis | $5,000 |
Cost Optimization Strategies¶
Cloud SQL: - Use appropriate machine type - Enable automatic storage increase - Use committed use discounts - Delete unused instances - Use read replicas for read-heavy workloads
Cloud Spanner: - Use regional instead of multi-region when possible - Right-size node count - Use processing units for fine-grained scaling - Monitor and optimize queries
Firestore: - Optimize document structure - Use composite indexes efficiently - Implement caching - Batch operations - Monitor read/write operations
Bigtable: - Right-size cluster nodes - Use HDD instead of SSD when appropriate - Implement data lifecycle policies - Optimize row key design - Use replication only when needed
Memorystore: - Right-size instance - Use Basic tier for dev/test - Use Standard tier for production - Monitor memory usage - Implement eviction policies
Quick Reference¶
Cloud SQL¶
# Create instance
gcloud sql instances create my-instance \
--database-version=MYSQL_8_0 \
--tier=db-n1-standard-1 \
--region=us-central1
# Create database
gcloud sql databases create my-db --instance=my-instance
# Connect
gcloud sql connect my-instance --user=root
Cloud Spanner¶
# Create instance
gcloud spanner instances create my-instance \
--config=regional-us-central1 \
--nodes=1 \
--description="My Spanner instance"
# Create database
gcloud spanner databases create my-db \
--instance=my-instance
Firestore¶
# Initialize (via console or Firebase CLI)
firebase init firestore
# Deploy rules
firebase deploy --only firestore:rules
Bigtable¶
# Create instance
gcloud bigtable instances create my-instance \
--cluster=my-cluster \
--cluster-zone=us-central1-a \
--cluster-num-nodes=3 \
--display-name="My Bigtable instance"
Memorystore¶
# Create Redis instance
gcloud redis instances create my-redis \
--size=1 \
--region=us-central1 \
--tier=basic
Best Practices¶
General¶
β
Choose the right database for your use case
β
Implement proper indexing
β
Use connection pooling
β
Enable backups
β
Monitor performance
β
Implement security best practices
β
Use IAM for access control
β
Enable encryption at rest
β
Plan for disaster recovery
β
Regular performance testing
Performance¶
β
Optimize queries
β
Use appropriate indexes
β
Implement caching
β
Use read replicas
β
Monitor slow queries
β
Optimize data model
β
Use connection pooling
β
Implement pagination
Security¶
β
Use private IP when possible
β
Enable SSL/TLS
β
Use IAM authentication
β
Implement least privilege
β
Enable audit logging
β
Regular security audits
β
Use VPC Service Controls
β
Encrypt sensitive data
Cost Optimization¶
β
Right-size instances
β
Delete unused resources
β
Use committed use discounts
β
Monitor usage
β
Implement data lifecycle policies
β
Use appropriate storage tiers
β
Optimize queries
β
Regular cost reviews
Next Steps¶
- Cloud SQL - Managed relational databases
- Cloud Spanner - Global relational database
- Firestore - Document database
- Bigtable - Wide-column NoSQL database
- Memorystore - In-memory cache
- Database Comparison - Detailed comparison
- Best Practices - Production guidelines
Additional Resources¶
- Cloud SQL Documentation
- Cloud Spanner Documentation
- Firestore Documentation
- Bigtable Documentation
- Memorystore Documentation
- Database Pricing
Last Updated: March 2026
Status: β
Complete