Document, Cache and Choosing the Right GCP Database: Firestore, Memorystore, BigQuery and a Decision Guide
Firestore
- A serverless NoSQL document database: data in documents (JSON-like) inside collections
- Automatic scaling, multi-region replication, offline sync for mobile and web, real-time listeners
- Supports ACID transactions, indexes (automatic single-field, custom composite) and security rules for direct client access
- Great for user profiles, carts, chat, app settings, game state
python
from google.cloud import firestore
db = firestore.Client()
db.collection("users").document("asha").set({"name": "Asha", "city": "Pune", "points": 120})
doc = db.collection("users").document("asha").get()
print(doc.to_dict())
for u in db.collection("users").where("city", "==", "Pune").stream():
print(u.id, u.to_dict())
- Model data around how you read it. Avoid deep joins. Duplicate small pieces if needed
- Watch hot documents (very frequent writes to one document)
- Choose Native mode for new projects
Memorystore
- Managed in-memory stores: Redis (including Redis Cluster), Valkey and Memcached
- Sub-millisecond reads. Use it as a cache, session store, rate limiter, leaderboard or queue
- Has standard tier with replica and automatic failover for availability
- Reached by private IP in your VPC
text
Cache-aside pattern
1. App asks cache for key "product:42"
2. Hit → return it
3. Miss → read the database, store in cache with a TTL (for example 5 minutes), return it
bash
gcloud redis instances create session-cache --region=asia-south1 --tier=STANDARD --size=2 --network=prod-vpc
gcloud redis instances describe session-cache --region=asia-south1 --format="get(host,port)"
BigQuery Is Also a Database
- BigQuery is the analytics data warehouse (next section). Use it for large analytical queries, not for many small transactions
The Big Decision Table
| Need | Choose |
|---|---|
| Standard relational app, MySQL/PostgreSQL/SQL Server | Cloud SQL |
| High-performance PostgreSQL, transactions and analytics together | AlloyDB |
| Global relational, unlimited scale, strong consistency | Spanner |
| Massive time series, IoT, key-based lookups | Bigtable |
| Mobile and web app documents, real-time sync | Firestore |
| Sub-millisecond cache or sessions | Memorystore |
| Analytics and reporting on huge data | BigQuery |
| Files, images, backups | Cloud Storage |
| Graph relationships | Spanner Graph or a partner graph database |
| Vector search for AI | AlloyDB, Cloud SQL, Spanner or BigQuery vector search |
Scenarios
| Scenario | Answer and reason |
|---|---|
| Global gaming leaderboard with strict ranking and payments | Spanner for payments and Memorystore for fast leaderboard |
| Mobile chat app with offline mode | Firestore for sync and offline support |
| Millions of sensors writing every second | Bigtable for throughput, BigQuery for analysis |
| Lift-and-shift of a MySQL web app | Cloud SQL with HA and replicas |
| Product catalog search page needs speed | Cloud SQL or Firestore plus Memorystore cache |
| Daily sales reports for executives | BigQuery with Looker dashboards |
Practice
- Write a Firestore document for a user and a query by city
- Draw the cache-aside flow for a product page
- Choose a database for five more scenarios you invent
- List three ways to migrate a MySQL database to Cloud SQL
Conclusion
Pick databases by data model, scale and access pattern: Cloud SQL and AlloyDB for relational apps, Spanner for global scale, Bigtable for key-based huge throughput, Firestore for documents, Memorystore for cache and BigQuery for analytics. Many systems use several together.
Quick Summary: Firestore; Memorystore; BigQuery; decision table; scenarios.

