Data Storage
Choosing and configuring the right GCP storage service for structured, semi-structured, and unstructured data workloads.
Cloud Storage (GCS)
GCS is GCP's unified object storage service. Understanding storage classes and lifecycle management is heavily tested on the exam.
Storage Classes
- Standard: Highest availability, no minimum storage duration. Best for frequently accessed ("hot") data.
- Nearline: Low-cost for data accessed at most once per month. 30-day minimum storage duration. ~$0.01/GB/month retrieval.
- Coldline: Very low-cost for data accessed at most once per quarter. 90-day minimum. ~$0.02/GB/month retrieval.
- Archive: Lowest cost for long-term archival (accessed less than once per year). 365-day minimum. ~$0.05/GB/month retrieval.
Lifecycle Management
Lifecycle rules automatically transition objects between classes or delete them after conditions are met. Common conditions: age (days since creation), numNewerVersions, isLive. Common actions: SetStorageClass, Delete.
Retention Policies & Object Lock
Retention policies prevent object deletion before a minimum age. Object Lock (Bucket Lock) enforces WORM (Write Once, Read Many) compliance — once locked, the policy cannot be reduced or removed. Used for regulated data like financial records.
Cloud Bigtable
Bigtable is a fully managed, petabyte-scale NoSQL wide-column store optimized for high-throughput, low-latency workloads. It is not a relational database — there is no SQL support and no cross-row transactions.
When to Use Bigtable
- Time-series data (IoT sensor readings, financial tick data)
- Analytical workloads requiring millions of reads/writes per second
- Data that doesn't require joins or complex queries
- Wide rows with hundreds to thousands of columns per row
Row Key Design
Row key design is the most critical Bigtable decision. Data is stored sorted lexicographically by row key and distributed across tablets. Poor key design causes hotspotting.
- Avoid: Sequential numeric IDs, timestamps as key prefix (recent writes all hit one tablet)
- Use: Hash-prefixed keys, reversed timestamps (
MAX_TIMESTAMP - event_time), composite keys that distribute writes - Pattern:
hash(entity_id)#entity_id#reverse_timestampfor per-entity time-series with even distribution
Cloud SQL
Cloud SQL is GCP's managed relational database service supporting MySQL, PostgreSQL, and SQL Server. It is designed for OLTP workloads, not large-scale analytics.
Key Features for the Exam
- High Availability (HA): Synchronous replication to a standby in a different zone. Automatic failover with ~60 second downtime.
- Read replicas: Asynchronous cross-region replicas for scaling reads and disaster recovery. Not automatic failover targets.
- Automatic storage increase: Cloud SQL can auto-grow storage but cannot shrink it — plan initial sizing carefully.
- Private IP + VPC peering: Best practice for production. Cloud SQL Auth Proxy handles encryption and IAM auth without VPN.
- Backups: Automated daily backups + point-in-time recovery (PITR) using binary log. PITR requires binary logging to be enabled.
Cloud Spanner
Spanner is GCP's globally distributed, horizontally scalable, strongly consistent relational database. It combines the SQL semantics of a relational database with the horizontal scale of NoSQL.
Core Differentiators
- External consistency: Stronger than serializable — every transaction appears to execute at a globally consistent timestamp. Enabled by TrueTime (atomic clocks + GPS).
- Automatic sharding: Spanner splits and rebalances data across splits automatically. Row key design still matters to avoid hotspots.
- Interleaving: Parent-child table rows stored physically together on disk for efficient joins. Use
INTERLEAVE IN PARENTfor one-to-many relationships with frequent co-reads. - Stale reads: Read at a past timestamp (e.g., 15 seconds ago) for lower latency and cost. Use when strong consistency is not required.
Firestore
Firestore is GCP's serverless, horizontally scaling document database. It is designed for mobile/web backends requiring real-time sync and offline support.
Datastore Mode vs. Native Mode
- Native mode: Supports real-time listeners, mobile/web SDKs, and offline sync. Cannot use Datastore API.
- Datastore mode: Backwards compatible with Cloud Datastore API. Does not support real-time listeners or mobile SDKs. Better for server-side workloads.
Choosing the Right Storage Service
📝 Practice Questions — Data Storage
symbol#timestamp. You're observing hotspotting on the most active symbols. What's the best row key redesign?
timestamp#symbol so rows are ordered by time globallyshard_id#symbol#reverse_timestamp where shard_id = hash(symbol) % 10, querying all shards for a symbol's range scanshard_id#symbol#reverse_timestamp) distributes writes for hot symbols across multiple tablets. Using reverse_timestamp means the most recent ticks sort first. You query all 10 shards for a symbol in parallel and merge results — a common Bigtable scatter-gather pattern. Option A creates write hotspots on the current timestamp. Option C (UUID) makes range scans by symbol impossible. Option D (padding) doesn't address the distribution problem.