Google Cloud Spanner Tutorial: Architecture, Pricing, Use Cases, and Hands-On Guide for Databases

Category

Databases

1. Introduction

Spanner is Google Cloud’s fully managed relational database designed for applications that need strong consistency, high availability, and horizontal scalability—including across regions.

In simple terms: Spanner lets you keep using familiar relational concepts (tables, SQL, indexes, transactions), while Google Cloud handles sharding, replication, failover, and operational heavy lifting so you can scale without re-architecting around database limits.

Technically: Spanner is a distributed SQL database that provides externally consistent transactions and synchronous replication across multiple zones (regional) or regions (multi-region), with automatic data partitioning and distributed query execution. It supports both GoogleSQL and a PostgreSQL interface (dialect/compatibility layer), depending on how you create the database.

The problem Spanner solves: traditional single-node or primary-replica databases often hit ceilings in throughput, availability, and operational complexity at scale. Sharding manually can be risky and expensive. Spanner provides a managed path to scale relational workloads while keeping correctness guarantees and predictable operations.

Naming note: Historically the product was marketed as Cloud Spanner. In current Google Cloud documentation and Console, it is commonly shown as Spanner. This tutorial uses Spanner as the primary service name.


2. What is Spanner?

Official purpose

Spanner is Google Cloud’s managed, distributed, relational database service for mission-critical applications that require: – SQL + relational modeling – Strong consistency and ACID transactions – High availability and high throughput – Regional or multi-region replication – Scale-out architecture (not just scale-up)

Official docs: https://cloud.google.com/spanner/docs

Core capabilities (what it can do)

  • Relational schema: tables, primary keys, secondary indexes
  • SQL querying with strong consistency (GoogleSQL or PostgreSQL interface)
  • ACID transactions across rows/tables (within the database)
  • Automatic sharding and distributed query execution
  • Synchronous replication for high availability (regional) or geo-availability (multi-region)
  • Backups and restore, and additional data protection features (verify exact availability by dialect/region in official docs)
  • Change data capture style via Change Streams (availability depends on dialect/features—verify in official docs)
  • IAM-based access control, plus database-level roles/privileges

Major components (how you interact with it)

  • Instance: the compute/serving resources and replication configuration boundary. You choose an instance configuration (regional or multi-region).
  • Database: logical database inside an instance (schema, tables, indexes).
  • Schema (DDL): defines tables, primary keys, indexes, constraints/capabilities supported by the dialect.
  • Client access: applications connect via Google Cloud client libraries, JDBC, REST/gRPC APIs, and admin tools.
  • Operations: long-running tasks like schema updates, backups/restores.

Service type

  • Fully managed database service (PaaS / managed distributed SQL).
  • You manage schema and query design; Google Cloud manages infrastructure, replication, patching, and high availability mechanics.

Scope: regional / multi-region and project-scoped

  • Spanner resources are created in a Google Cloud project.
  • An instance uses an instance configuration that is:
  • Regional (replicated across multiple zones in one region), or
  • Multi-region (replicated across multiple regions, depending on configuration).
  • Access is controlled by Google Cloud IAM at the project/instance/database level.

How Spanner fits into Google Cloud

Spanner integrates naturally with: – IAM for access control – Cloud Monitoring and Cloud Logging for observability – Cloud KMS for customer-managed encryption keys (CMEK) (verify exact support details in docs) – VPC Service Controls for service perimeter protection – Data pipelines such as Dataflow and other ingestion/streaming tooling (integration varies by feature)


3. Why use Spanner?

Business reasons

  • Reduce risk for revenue-critical systems (payments, ordering, identity, core ledgers) by using a database designed for high availability and consistency.
  • Lower operational burden compared to self-managed sharded databases.
  • Faster global expansion: multi-region configurations can reduce downtime risk and improve user experience across geographies.

Technical reasons

  • Strong consistency at scale: helps avoid subtle correctness bugs in distributed systems.
  • Relational modeling and SQL: keep joins, constraints (as supported), and transactional semantics.
  • Scale-out architecture: increase compute capacity without manual sharding in many cases.

Operational reasons

  • Managed replication, failover handling, and maintenance reduce the need for specialized database SRE staffing for the core infrastructure layer.
  • Built-in metrics and integration with Google Cloud operations tools.

Security / compliance reasons

  • IAM integration and audit logs help with governance.
  • Encryption at rest and in transit are part of the managed service design (verify compliance attestations relevant to your organization in official docs).

Scalability / performance reasons

  • Designed for high read/write throughput with scale-out compute.
  • Supports performance patterns such as:
  • read-only transactions
  • stale reads (bounded staleness) for latency reduction where acceptable
  • secondary indexes and distributed query planning

When teams should choose Spanner

Choose Spanner when you need: – High availability targets (often 99.99%+ expectations) and operational resilience – Consistent transactions plus horizontal scale – One database to serve multiple services or large workloads without complex sharding – Multi-region designs with synchronous replication (when required)

When teams should not choose Spanner

Avoid (or reconsider) Spanner when: – You only need a small single-region relational database and cost sensitivity is high (Cloud SQL may fit better). – Your workload is simple key-value at extreme scale and can be eventually consistent (Bigtable/Firestore may be better fits). – You require full PostgreSQL engine parity (extensions, superuser access, some advanced features). Spanner’s PostgreSQL interface is compatibility-focused, not identical to self-managed PostgreSQL—verify feature support. – You need heavy analytics across massive datasets (BigQuery is typically a better fit).


4. Where is Spanner used?

Industries

  • Financial services (payments, ledgers, reconciliation)
  • Retail and e-commerce (orders, inventory, pricing)
  • Gaming (player state, entitlements, matchmaking metadata)
  • Telecommunications (subscriber state, billing events)
  • SaaS and marketplaces (tenants, subscriptions, entitlements)
  • Logistics and mobility (dispatch, tracking state)
  • Healthcare and regulated workloads (where strong correctness and auditability matter)

Team types

  • Platform teams building shared data platforms
  • Product teams owning high-scale backend services
  • SRE/DevOps teams needing reliable operations
  • Data engineering teams integrating operational data streams

Workloads

  • Online transaction processing (OLTP) at high scale
  • Globally distributed user/profile stores with strong consistency needs
  • Multi-tenant SaaS metadata and entitlement systems
  • Event-driven architectures needing consistent state changes (often paired with streaming)

Architectures

  • Microservices with a shared transactional system of record
  • Event-driven systems using change capture + downstream consumers
  • Active-active-ish multi-region read patterns (depending on configuration capabilities and application design)

Production vs dev/test usage

  • Production: where Spanner shines—high availability, scale, correctness.
  • Dev/test: feasible, but costs can be higher than simpler databases. Many teams use Spanner in dev/test selectively (integration environments, performance testing) and use cheaper alternatives for unit testing or local development.

5. Top Use Cases and Scenarios

Below are realistic Spanner use cases with the problem, fit, and example scenario.

1) Global user identity and profiles

  • Problem: User profile data must be correct and available worldwide, with low downtime tolerance.
  • Why Spanner fits: Strong consistency, high availability, multi-region replication options.
  • Example: A consumer app stores user accounts, settings, and login metadata globally.

2) Orders and payments system of record

  • Problem: Orders must not double-charge or lose updates; spikes during promotions.
  • Why Spanner fits: ACID transactions, scale-out writes, operational resilience.
  • Example: An e-commerce platform processes cart checkout and order lifecycle state transitions.

3) Inventory and reservation management

  • Problem: Prevent overselling; maintain consistent stock counts across regions/services.
  • Why Spanner fits: Transactional updates and consistency.
  • Example: Inventory reservations during flash sales require correctness under extreme concurrency.

4) Multi-tenant SaaS metadata (tenants, plans, entitlements)

  • Problem: Many tenants; need isolation and consistent billing/entitlement logic.
  • Why Spanner fits: Relational modeling for complex relationships; scale-out.
  • Example: A SaaS provider stores tenants, subscription plans, feature flags, and entitlements.

5) Financial ledger and reconciliation store

  • Problem: Ledgers must be immutable/correct; auditability matters.
  • Why Spanner fits: Consistent transactions; strong correctness semantics.
  • Example: A fintech uses append-only ledger tables with transaction metadata and reconciliation jobs.

6) High-scale session and state management (consistent sessions)

  • Problem: Sessions must not conflict across a distributed system; global traffic.
  • Why Spanner fits: Strong consistency and global replication patterns.
  • Example: A gaming backend stores player session state and entitlements.

7) Product catalog with consistent writes + globally distributed reads

  • Problem: Catalog updates must be correct; reads are global and high volume.
  • Why Spanner fits: Scale-out reads, indexes, and optional stale reads for latency.
  • Example: Retailers update prices/promotions while serving global catalog queries.

8) Event-driven microservices: change streams to downstream systems

  • Problem: Downstream services need to react to database changes reliably.
  • Why Spanner fits: Change Streams can publish ordered changes per key range (feature specifics vary—verify).
  • Example: Order status changes trigger notifications, fulfillment, and analytics pipelines.

9) IoT device registry and configuration store

  • Problem: Millions of devices; configuration updates must be correct and durable.
  • Why Spanner fits: Horizontal scale with relational metadata and strong writes.
  • Example: Telecom stores device-to-customer mappings and policy configurations.

10) Airline/train booking and seat allocation

  • Problem: Prevent double-booking; handle bursty demand.
  • Why Spanner fits: Transactional allocation logic, consistent concurrency control.
  • Example: Seat inventory allocation and booking confirmation under high contention.

11) Global rate-limiting and quota tracking (consistent counters)

  • Problem: Accurate quotas across regions; avoid inconsistent enforcement.
  • Why Spanner fits: Strongly consistent transactions for counter updates (design carefully to avoid hotspots).
  • Example: API platform enforces per-tenant quotas and usage counters.

12) Reference data hub for multiple services

  • Problem: Multiple services depend on shared, consistent reference data.
  • Why Spanner fits: High availability and correctness as a shared store.
  • Example: A marketplace keeps consistent product/vendor mappings used by many services.

6. Core Features

This section focuses on important current Spanner features and the caveats that matter in real deployments. Always confirm details in the official docs because features can vary by dialect (GoogleSQL vs PostgreSQL interface) and by release stage.

1) Distributed relational database with strong consistency

  • What it does: Provides SQL-based relational storage with ACID transactions and strong consistency.
  • Why it matters: Reduces application complexity—fewer “eventual consistency” edge cases.
  • Practical benefit: Correctness for money, inventory, entitlements, and state machines.
  • Caveats: Distributed transactions have different performance characteristics than single-node databases. Schema and key design matter.

2) Regional and multi-region instance configurations

  • What it does: Lets you deploy with replication across zones (regional) or regions (multi-region configs).
  • Why it matters: High availability and disaster tolerance.
  • Practical benefit: Survive zonal failures (regional) and improve resilience (multi-region).
  • Caveats: Multi-region can increase write latency depending on replica placement and leader region behavior. Choose based on latency/SLA needs.

3) Horizontal scalability (compute + storage)

  • What it does: Scale serving resources by increasing instance compute capacity (nodes/processing units) and storage separately.
  • Why it matters: Avoid manual sharding for many use cases.
  • Practical benefit: Handle growth and spikes by scaling resources.
  • Caveats: Hotspotting can still happen if primary keys concentrate writes.

4) SQL dialect options: GoogleSQL and PostgreSQL interface

  • What it does: Supports GoogleSQL (Spanner’s SQL dialect) or a PostgreSQL-compatible interface.
  • Why it matters: PostgreSQL compatibility can reduce migration friction for some apps.
  • Practical benefit: Use familiar PostgreSQL syntax and tools (within supported subset).
  • Caveats: Not all PostgreSQL features/extensions are supported. Verify syntax, data types, and limitations in official docs.

5) Secondary indexes

  • What it does: Speeds up queries by indexing columns beyond the primary key.
  • Why it matters: Distributed databases rely heavily on correct indexing for performance.
  • Practical benefit: Faster point lookups and range queries.
  • Caveats: Indexes increase storage and write amplification; too many indexes can raise cost and reduce write throughput.

6) Read-only transactions and stale reads

  • What it does: Read-only transactions can provide a consistent snapshot; stale reads allow reading slightly older data.
  • Why it matters: Improves read scalability and latency when absolute freshness isn’t required.
  • Practical benefit: Offload read pressure and reduce tail latency for global users.
  • Caveats: Stale reads trade freshness for performance; requires application-level acceptance of bounded staleness.

7) Schema changes (DDL) as online operations

  • What it does: Many schema changes run as managed operations.
  • Why it matters: Reduces downtime during migrations.
  • Practical benefit: Evolve schemas with less disruption.
  • Caveats: Some schema changes can still take significant time on large datasets. Plan change windows and monitor operations.

8) Change Streams (change capture)

  • What it does: Produces a stream of data change records for subscribed consumers.
  • Why it matters: Enables event-driven architectures and downstream indexing/analytics.
  • Practical benefit: Build near-real-time pipelines to Pub/Sub/Dataflow or custom consumers (implementation varies).
  • Caveats: Feature availability and exact semantics depend on dialect and configuration—verify in official docs.

9) Backups and restore

  • What it does: Create backups and restore databases/instances (restore semantics vary).
  • Why it matters: Protection against accidental deletion/corruption and supports migration workflows.
  • Practical benefit: Point-in-time-ish recovery options depending on features.
  • Caveats: Backups cost storage and may have retention considerations. Confirm restore granularity and RPO/RTO needs.

10) Encryption and customer-managed keys (CMEK)

  • What it does: Encrypts data at rest; can support Cloud KMS keys for customer control (CMEK).
  • Why it matters: Compliance and key ownership requirements.
  • Practical benefit: Align with regulated security policies.
  • Caveats: CMEK introduces operational dependencies on KMS key availability and IAM.

11) IAM integration and fine-grained access (where supported)

  • What it does: Control access at instance/database levels; supports database roles/privileges for finer control.
  • Why it matters: Least privilege and auditable access.
  • Practical benefit: Separate admin duties from application runtime access.
  • Caveats: Ensure you understand the mapping between IAM permissions and in-database privileges (especially with PostgreSQL interface). Verify in docs.

12) Observability (Monitoring, Logging, Audit Logs)

  • What it does: Exposes metrics and logs for performance and operations; Cloud Audit Logs capture admin and data access events (depending on log type enabled).
  • Why it matters: Troubleshooting and capacity planning.
  • Practical benefit: SRE-grade visibility into latency, CPU, storage, and errors.
  • Caveats: Logging/audit can add cost and must be configured carefully for sensitive data.

7. Architecture and How It Works

High-level architecture

At a high level: – Your application connects to Spanner using client libraries or JDBC. – Spanner stores tables as partitions (splits) distributed across serving resources. – Replication is synchronous across zones/regions as defined by the instance configuration. – A query is planned and executed across partitions; results are aggregated and returned.

Request/data/control flow (conceptual)

  1. Client authenticates using IAM credentials (service account, user credentials, workload identity).
  2. Client sends SQL query/transaction to Spanner endpoint.
  3. Spanner routes requests to appropriate partitions based on primary key ranges.
  4. Writes are committed with strong consistency; reads can be strong or stale (if requested).
  5. Metrics and logs are emitted to Cloud Monitoring/Logging.

Integrations with related Google Cloud services

Common integrations include: – Cloud IAM: identities and permissions – Cloud Monitoring: metrics dashboards and alerting – Cloud Logging: admin logs, audit logs, and client logs – Cloud KMS: CMEK (where used) – VPC Service Controls: service perimeters – Private Service Connect: private access patterns (verify your region/support) – Dataflow: often used for Change Streams pipelines – Cloud Run / GKE / Compute Engine: common compute platforms for apps using Spanner

Dependency services (practical view)

Spanner is managed, but production deployments usually depend on: – IAM + Org Policies (governance) – Monitoring + alerting – KMS (if using CMEK) – Networking controls (PSC/VPC SC) if restricting egress/internet access – CI/CD for schema migrations

Security/authentication model

  • Auth via Google Cloud IAM:
  • users (human access)
  • service accounts (applications, automation)
  • Workload Identity Federation (recommended for external workloads)
  • Authorization via IAM roles and (optionally) database roles/privileges.
  • TLS is used for in-transit encryption.

Networking model

  • Spanner is accessed via Google-managed endpoints.
  • You can control access using:
  • IAM
  • VPC Service Controls perimeters
  • Private connectivity options such as Private Service Connect (verify support and setup steps in official docs for your environment)

Monitoring/logging/governance considerations

  • Monitor:
  • request latency (p50/p95/p99)
  • CPU utilization / serving capacity
  • storage growth
  • transaction aborts / concurrency issues
  • lock/contention indicators (as available)
  • Governance:
  • resource naming conventions
  • labels/tags for cost allocation
  • audit log retention policies

Simple architecture diagram (conceptual)

flowchart LR
  A[App on Cloud Run / GKE / VM] -->|SQL / Transactions| S[Spanner Instance]
  S --> D[(Spanner Database)]
  S --> M[Cloud Monitoring]
  S --> L[Cloud Logging / Audit Logs]

Production-style architecture diagram (more realistic)

flowchart TB
  subgraph VPC[Google Cloud Project + VPC]
    subgraph Compute[Compute Tier]
      CR[Cloud Run Services]
      GKE[GKE Workloads]
      CI[CI/CD Pipeline]
    end

    subgraph Data[Data Tier]
      SP[Spanner Instance\n(Regional or Multi-region)]
      DB[(Database + Indexes)]
      BK[Backups]
    end

    subgraph Sec[Security & Governance]
      IAM[IAM + Service Accounts]
      KMS[Cloud KMS (CMEK optional)]
      VPCSC[VPC Service Controls (optional)]
    end

    subgraph Obs[Operations]
      MON[Cloud Monitoring]
      LOG[Cloud Logging]
      ALRT[Alerting Policies]
    end

    subgraph Stream[Event/Data Pipelines]
      CS[Change Streams (optional)]
      DF[Dataflow (optional)]
      BQ[BigQuery (analytics)]
    end
  end

  CR -->|Auth via SA| IAM
  GKE -->|Auth via SA| IAM
  CI -->|DDL migrations| SP

  CR -->|SQL| SP
  GKE -->|SQL| SP
  SP --> DB
  SP --> BK

  SP --> MON
  SP --> LOG
  MON --> ALRT

  SP -->|CMEK| KMS
  SP -->|Perimeter control| VPCSC

  DB -->|Changes| CS
  CS --> DF --> BQ

8. Prerequisites

Google Cloud account and project

  • A Google Cloud billing account and a project with billing enabled.
  • Spanner API enabled in the project.

Permissions / IAM roles

For the hands-on lab, you typically need one of: – Spanner Admin permissions (e.g., roles/spanner.admin) to create instances and databases – Or a combination such as: – roles/spanner.instanceAdmin (instance) – roles/spanner.databaseAdmin (database/schema)

You also need permissions to enable APIs if not already enabled: – roles/serviceusage.serviceUsageAdmin or broader (like Project Owner)

Follow least privilege for production.

Tools

Any one of: – Cloud Shell (recommended for this tutorial; includes gcloud) – Local machine with: – Google Cloud CLI (gcloud) installed and authenticated
Install: https://cloud.google.com/sdk/docs/install – Optional for app testing: – Python 3.10+ and pip – Or Java/JDBC, Go, Node.js, etc.

Region availability

  • Spanner is available in many Google Cloud regions and multi-regions.
  • Instance configuration names vary by location (regional vs multi-region).
  • Verify supported locations and instance configs: https://cloud.google.com/spanner/docs/instance-configurations

Quotas / limits

Common constraints include: – Maximum instances per project – Minimum compute capacity per instance (nodes/processing units) – API request limits – Backup limits and retention constraints

Quotas change over time—verify in: – Google Cloud Console → IAM & Admin → Quotas – Official docs: https://cloud.google.com/spanner/quotas

Prerequisite services

  • Cloud Billing enabled
  • IAM configured (service accounts if used)
  • (Optional) Cloud Monitoring/Logging enabled (usually default)

9. Pricing / Cost

Spanner pricing is usage-based and depends on configuration choices. Because pricing varies by region, instance configuration, edition/SKUs, and time, use official sources to calculate exact costs.

Official pricing resources

  • Pricing page: https://cloud.google.com/spanner/pricing
  • Pricing calculator: https://cloud.google.com/products/calculator

Pricing dimensions (what you pay for)

Common billable dimensions include: 1. Compute capacity: provisioned as nodes or processing units (PUs) (terminology and minimums can vary by configuration). 2. Storage: – Database storage (GB-month) – Index storage (also GB-month) 3. Backups storage (GB-month) and possibly backup operations (check pricing details). 4. Network egress: – Data leaving Google Cloud (internet or cross-region) may incur costs. – Replication traffic is part of the service design; pricing specifics are accounted for in Spanner’s pricing model (verify details on pricing page). 5. Optional features: – Some advanced capabilities may have distinct SKUs or edition-based pricing (verify in official pricing docs).

Free tier

  • Google Cloud offers a general Free Trial (credits for new accounts): https://cloud.google.com/free
  • Spanner does not generally behave like an “always-free micro database.” Treat it as a production-grade paid service unless official docs explicitly describe a free tier for your region/config.

Cost drivers (what makes costs go up)

  • Over-provisioned compute (too many nodes/PUs for the workload)
  • Write-heavy workloads with many indexes (higher write amplification)
  • Large datasets (base + index + backup storage)
  • Multi-region configs (often higher cost than regional; check SKUs)
  • High QPS and expensive queries (distributed scans, poor indexing)
  • High audit/log volume (Cloud Logging and Audit Logs can add cost)

Hidden or indirect costs

  • Cloud Logging ingestion and retention if you export or retain large volumes
  • Dataflow / Pub/Sub costs if you build pipelines from Change Streams
  • BigQuery storage/query costs for analytics
  • Cross-region egress for consumers outside the region

Network/data transfer implications

  • Keep app compute (Cloud Run/GKE/VMs) in the same region as your primary Spanner configuration for latency and cost.
  • For multi-region, consider where your clients are and whether you’ll do stale reads from closer replicas (requires careful design and correct config).

How to optimize cost (practical checklist)

  • Start with the smallest supported compute capacity for dev/test.
  • Use autoscaling (where supported) for variable workloads; set sensible min/max.
  • Design primary keys to avoid hotspots, which can force you to scale compute unnecessarily.
  • Minimize unnecessary indexes; add only what queries need.
  • Avoid full table scans; use selective queries and indexes.
  • Use stale reads only when business logic allows; it can reduce load/latency.
  • Use labels for chargeback and enforce budgets/alerts.

Example low-cost starter estimate (method, not fabricated numbers)

A realistic “starter” Spanner environment is typically dominated by the minimum compute for an instance plus some storage.

Estimate method: 1. Choose a regional instance configuration (cheaper than multi-region in many cases). 2. Set compute to the minimum supported (often expressed as 100 processing units or 1 node, depending on UI/CLI; verify current minimum). 3. Assume small storage (e.g., a few GB) and no/limited backups. 4. Use the calculator to get a monthly estimate in your currency.

Because minimums and per-unit prices change by region/config, do the calculation here: – https://cloud.google.com/products/calculator

Example production cost considerations (what to model)

For production planning, model: – Peak and average QPS, read/write ratio – Dataset size growth + index growth – Backup retention policy – Multi-region requirements (SLA, failover, regulatory) – Additional pipeline costs (Change Streams → Dataflow → analytics) – Logging/Audit retention requirements

A practical approach: – Run a load test on a staging instance. – Observe CPU utilization, latency, and throughput. – Adjust capacity and re-run until you hit SLOs with headroom. – Convert that capacity into monthly cost using the pricing calculator.


10. Step-by-Step Hands-On Tutorial

Objective

Create a Spanner regional instance, create a database, define a simple schema, insert/query data, add an index, observe basic operations, and clean up—using low-risk defaults.

Lab Overview

You will: 1. Enable the Spanner API. 2. Create a Spanner instance (regional). 3. Create a database using GoogleSQL. 4. Create tables and an index. 5. Insert and query sample data using gcloud. 6. (Optional) Run a small Python script to query Spanner. 7. Validate results. 8. Clean up to avoid ongoing charges.

This lab uses Cloud Shell and gcloud. It avoids advanced features to keep it beginner-friendly and executable.


Step 1: Set up your environment (project, API, and gcloud)

1) Open Cloud Shell in the Google Cloud Console.

2) Set your project:

gcloud config set project PROJECT_ID

Replace PROJECT_ID with your project.

3) Enable the Spanner API:

gcloud services enable spanner.googleapis.com

Expected outcome: The API enablement command returns successfully.

4) (Optional) Confirm:

gcloud services list --enabled --filter="name:spanner.googleapis.com"

Step 2: Choose a regional instance configuration

List available instance configurations:

gcloud spanner instance-configs list

Pick a regional config near you, such as: – regional-us-central1regional-europe-west1regional-asia-east1

Instance config names vary—use the list output.

Set environment variables:

export SPANNER_CONFIG="regional-us-central1"
export SPANNER_INSTANCE="spanner-lab-instance"
export SPANNER_DB="appdb"

Expected outcome: You’ve chosen an instance config that exists in your project’s accessible locations.


Step 3: Create a Spanner instance (regional)

Create an instance using processing units (PUs) if supported by your gcloud version and configuration. Many environments use 100 processing units as a minimum starting point (verify current minimums and flags in official docs if your command fails).

gcloud spanner instances create "${SPANNER_INSTANCE}" \
  --config="${SPANNER_CONFIG}" \
  --description="Spanner hands-on lab instance" \
  --processing-units=100

If your environment requires nodes instead of PUs, use:

gcloud spanner instances create "${SPANNER_INSTANCE}" \
  --config="${SPANNER_CONFIG}" \
  --description="Spanner hands-on lab instance" \
  --nodes=1

Expected outcome: The instance is created.

Verify:

gcloud spanner instances describe "${SPANNER_INSTANCE}"

Step 4: Create a database (GoogleSQL)

Create a database. By default, Spanner uses GoogleSQL unless you explicitly create a PostgreSQL-interface database (workflow differs). For this lab, we use GoogleSQL.

gcloud spanner databases create "${SPANNER_DB}" --instance="${SPANNER_INSTANCE}"

Expected outcome: Database appdb is created.

Verify:

gcloud spanner databases list --instance="${SPANNER_INSTANCE}"

Step 5: Create tables (DDL)

We’ll create two tables: – CustomersOrders

Notes: – Primary keys are mandatory. – Primary key design matters for performance and hotspots; this lab uses a simple pattern for learning.

Create a DDL file:

cat > schema.sql <<'SQL'
CREATE TABLE Customers (
  CustomerId STRING(36) NOT NULL,
  Name STRING(200) NOT NULL,
  Email STRING(320),
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp=true)
) PRIMARY KEY (CustomerId);

CREATE TABLE Orders (
  OrderId STRING(36) NOT NULL,
  CustomerId STRING(36) NOT NULL,
  OrderStatus STRING(30) NOT NULL,
  Amount NUMERIC NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp=true)
) PRIMARY KEY (CustomerId, OrderId);

CREATE INDEX OrdersByStatus ON Orders(OrderStatus);
SQL

Apply the DDL:

gcloud spanner databases ddl update "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --ddl="$(cat schema.sql)"

Expected outcome: DDL update operation completes successfully.

Verify tables via information schema (query):

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="SELECT table_name FROM information_schema.tables WHERE table_schema = ''"

Step 6: Insert sample data

Insert a customer and a couple orders. We’ll use commit timestamps for CreatedAt.

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="INSERT INTO Customers (CustomerId, Name, Email, CreatedAt)
         VALUES ('c-001', 'A. Example', 'a@example.com', PENDING_COMMIT_TIMESTAMP())"

Insert orders:

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="INSERT INTO Orders (OrderId, CustomerId, OrderStatus, Amount, CreatedAt)
         VALUES ('o-1001', 'c-001', 'CREATED', 19.99, PENDING_COMMIT_TIMESTAMP())"
gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="INSERT INTO Orders (OrderId, CustomerId, OrderStatus, Amount, CreatedAt)
         VALUES ('o-1002', 'c-001', 'PAID', 49.50, PENDING_COMMIT_TIMESTAMP())"

Expected outcome: Each insert returns success (no rows returned for INSERT).


Step 7: Query data (basic queries and an index query)

Query customers:

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="SELECT CustomerId, Name, Email, CreatedAt FROM Customers"

Query orders for a customer (uses primary key prefix CustomerId):

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="SELECT OrderId, OrderStatus, Amount, CreatedAt
         FROM Orders
         WHERE CustomerId='c-001'
         ORDER BY CreatedAt DESC"

Query by status (can use the secondary index OrdersByStatus):

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="SELECT CustomerId, OrderId, OrderStatus, Amount
         FROM Orders
         WHERE OrderStatus='PAID'"

Expected outcome: You should see your inserted rows.


Step 8 (Optional): Query Spanner using Python

This optional step shows how applications typically connect.

1) Install the library in Cloud Shell:

pip3 install --user google-cloud-spanner

2) Create a small script:

cat > spanner_query.py <<'PY'
from google.cloud import spanner

project_id = None  # uses default project from environment
instance_id = "spanner-lab-instance"
database_id = "appdb"

spanner_client = spanner.Client(project=project_id)
instance = spanner_client.instance(instance_id)
database = instance.database(database_id)

with database.snapshot() as snapshot:
    results = snapshot.execute_sql(
        "SELECT CustomerId, Name, Email FROM Customers"
    )
    for row in results:
        print(row)
PY

3) Run it:

python3 spanner_query.py

Expected outcome: Printed rows similar to ('c-001', 'A. Example', 'a@example.com').

If you run this outside Cloud Shell, configure credentials (Application Default Credentials) and permissions: – https://cloud.google.com/docs/authentication/provide-credentials-adc


Validation

Run these checks:

1) Confirm instance exists:

gcloud spanner instances list --filter="name:${SPANNER_INSTANCE}"

2) Confirm database exists:

gcloud spanner databases list --instance="${SPANNER_INSTANCE}" --filter="name:${SPANNER_DB}"

3) Confirm data exists:

gcloud spanner databases execute-sql "${SPANNER_DB}" \
  --instance="${SPANNER_INSTANCE}" \
  --sql="SELECT COUNT(*) AS CustomerCount FROM Customers"

You should get 1.


Troubleshooting

Common issues and fixes:

1) Permission denied / not authorized – Symptom: PERMISSION_DENIED errors during instance/database creation. – Fix: Ensure your user/service account has roles/spanner.admin (or appropriate instance/database roles) and that billing is enabled.

2) Invalid instance config – Symptom: NOT_FOUND: Instance config ... – Fix: Run gcloud spanner instance-configs list and pick a valid regional config.

3) DDL errors – Symptom: Syntax errors or unsupported features. – Fix: Ensure you created a GoogleSQL database and used valid GoogleSQL DDL. For PostgreSQL interface databases, DDL syntax differs.

4) gcloud flag differences (processing units vs nodes) – Symptom: unrecognized arguments: --processing-units – Fix: Use --nodes=1 or update gcloud components. In Cloud Shell, it’s usually current. Verify with: bash gcloud version

5) Python auth failures – Symptom: ADC or credentials errors. – Fix: In Cloud Shell, ADC is usually configured. Else follow ADC docs and ensure IAM roles allow database access.


Cleanup

To avoid ongoing charges, delete the instance (deleting the instance deletes databases inside it):

gcloud spanner instances delete "${SPANNER_INSTANCE}"

Confirm deletion:

gcloud spanner instances list --filter="name:${SPANNER_INSTANCE}"

11. Best Practices

Architecture best practices

  • Choose the right configuration:
  • Regional for most single-region apps needing HA across zones.
  • Multi-region only when you truly need cross-region resilience and/or global read patterns.
  • Design primary keys to avoid hotspots:
  • Avoid monotonically increasing keys (e.g., timestamps) as the leading key part for heavy write tables.
  • Consider key-salting or hashing patterns for high-write entities (validate with load tests).
  • Model for access patterns:
  • Use secondary indexes deliberately.
  • Prefer queries that use primary key or indexed columns to avoid distributed scans.

IAM/security best practices

  • Use dedicated service accounts per application/service.
  • Grant least privilege:
  • human admins: admin roles
  • apps: database user roles + minimal IAM
  • Separate duties: schema migrations via CI/CD identity, not app runtime identity.
  • Use VPC Service Controls where you need strict data exfiltration controls (org-wide planning required).

Cost best practices

  • Start small, then load test and scale.
  • Remove unused indexes.
  • Set budgets and alerts in Cloud Billing.
  • Use labels for chargeback (env=dev, team=payments, cost-center=...).
  • Prefer regional for dev/test when multi-region isn’t needed.

Performance best practices

  • Keep transactions short; avoid user-driven long transactions.
  • Use read-only transactions for consistent reads without locking overhead (as applicable).
  • Batch writes when possible, but don’t create large contention hotspots.
  • Watch query plans and add indexes to match query patterns (verify available tooling like query insights/plan explain in docs).

Reliability best practices

  • Define SLOs for latency/error rate and alert on symptoms (p95 latency, error spikes, CPU saturation).
  • Keep schema changes controlled via CI/CD with rollback plans.
  • Use backups and test restores periodically.

Operations best practices

  • Create dashboards for:
  • CPU/utilization vs latency
  • storage growth
  • transaction abort rates
  • Set up alerts before production launch.
  • Establish an incident playbook: scaling steps, query kill/mitigation, rollback.

Governance/tagging/naming best practices

  • Naming:
  • spanner-<app>-<env>-<region>
  • Example: spanner-orders-prod-uscentral1
  • Labels:
  • env, app, owner, cost_center, data_classification
  • Enforce org policies where appropriate (CMEK requirements, restricted services, etc.).

12. Security Considerations

Identity and access model

  • IAM controls who can administer instances/databases and who can connect.
  • Use:
  • roles/spanner.viewer for read-only visibility
  • roles/spanner.databaseUser for application read/write access (verify the exact role names/permissions needed)
  • roles/spanner.databaseAdmin for schema changes
  • roles/spanner.admin for full control

Prefer: – Service accounts for apps – Workload Identity on GKE, and service identity on Cloud Run where possible

Encryption

  • Encryption in transit: TLS.
  • Encryption at rest: enabled as part of managed service.
  • CMEK (Cloud KMS keys): use when required by policy; confirm configuration steps and limitations:
  • https://cloud.google.com/spanner/docs/cmek

Network exposure

  • By default, access is controlled by IAM and the service endpoint.
  • For stricter network controls:
  • Use VPC Service Controls to reduce exfiltration risks.
  • Consider Private Service Connect for private connectivity patterns (verify exact setup and regional support).

Secrets handling

  • Don’t embed service account keys in code.
  • Prefer:
  • Workload Identity / metadata-based credentials
  • Secret Manager for any required secrets (API keys for other systems)
  • If you must use keys (not recommended), rotate and restrict them tightly.

Audit/logging

  • Use Cloud Audit Logs:
  • Admin activity logs are typically enabled by default.
  • Data access logs may need explicit enabling and can generate high volume/cost—plan carefully.
  • Export logs securely (to BigQuery or Cloud Storage) if required by compliance.

Compliance considerations

  • Validate compliance needs (data residency, encryption controls, audit requirements).
  • Use organization policy constraints and IAM Conditions for governance.

Common security mistakes

  • Granting roles/spanner.admin to application runtime identities.
  • Using user credentials for production workloads.
  • Not enabling/monitoring audit logs for sensitive admin actions.
  • No controls on data exfiltration pathways (lack of VPC Service Controls where needed).

Secure deployment recommendations

  • Separate projects/environments (dev/test/prod).
  • Use least privilege and dedicated service accounts.
  • Adopt infrastructure-as-code for repeatable setup.
  • Establish key management and logging retention policies.

13. Limitations and Gotchas

Spanner is highly capable, but it has important practical constraints.

Known limitations (verify details in official docs)

  • PostgreSQL interface is not full PostgreSQL: extensions, superuser capabilities, and some behaviors differ.
  • Some features may be dialect-specific (GoogleSQL vs PostgreSQL interface).
  • Some schema patterns from traditional RDBMSs may require redesign for distributed performance.

Quotas

  • Instance/database limits, schema limits, API limits, and throughput constraints exist.
  • Check:
  • https://cloud.google.com/spanner/quotas

Regional constraints

  • Not all regions support every instance configuration.
  • Multi-region choices are limited to defined configurations.

Pricing surprises

  • Minimum provisioned compute can be higher than expected for small workloads.
  • Index-heavy designs increase storage and write costs.
  • Backup retention and logging volume can add up.

Compatibility issues

  • Migrating from MySQL/PostgreSQL/Oracle may require:
  • SQL dialect adjustments
  • transaction semantic checks
  • redesigning keys/indexes to avoid hotspots

Operational gotchas

  • “It’s SQL” does not mean you can ignore distributed system realities:
  • poor key design can cause hotspots
  • full scans can be expensive
  • long transactions can increase aborts and latency
  • Schema changes can take time on large datasets—plan and monitor.

Migration challenges

  • Data type mapping and SQL compatibility
  • Rewriting stored procedures/triggers (Spanner has different capabilities; verify what’s supported)
  • Rethinking constraints and application-side enforcement patterns if needed

Vendor-specific nuances

  • Spanner’s consistency and replication model is not identical to traditional primary/replica setups; understand leader/replica behavior for your configuration.

14. Comparison with Alternatives

Spanner is one option in Google Cloud Databases and among cross-cloud choices. The best option depends on consistency requirements, scale, operational needs, and budget.

Comparison table

Option Best For Strengths Weaknesses When to Choose
Spanner (Google Cloud) High-scale relational OLTP with strong consistency and high availability Horizontal scale, managed replication, strong consistency, SQL Can be costly for small workloads; requires careful key/index design; PostgreSQL interface not full parity When correctness + scale + availability matter more than lowest cost
Cloud SQL (Google Cloud) Traditional relational workloads (PostgreSQL/MySQL/SQL Server) Familiar engines, lower cost for small/medium apps, simpler migrations Scale is more vertical; HA/read replicas but not the same scale-out model When you need standard engines and moderate scale
AlloyDB for PostgreSQL (Google Cloud) High-performance PostgreSQL-compatible workloads Strong PostgreSQL compatibility and performance characteristics (verify current capabilities) Not designed like Spanner for global synchronous replication When you want PostgreSQL performance/compatibility in Google Cloud
Firestore (Google Cloud) Document apps, mobile/web sync, flexible schema Serverless scaling, realtime sync patterns Document model, different query patterns, eventual consistency options When document model fits and you want serverless simplicity
Bigtable (Google Cloud) Massive scale key-value/wide-column, time-series Very high throughput, low-latency key access Not relational; limited transactions When you need wide-column at huge scale
BigQuery (Google Cloud) Analytics/OLAP Serverless analytics, huge scale SQL Not OLTP; query costs; latency not for per-request transactions When you need analytics and reporting, not transactional serving
Amazon Aurora (AWS) Managed relational (MySQL/PostgreSQL) Familiar engines, strong ecosystem Not the same global-consistent scale-out model When in AWS and you need managed relational at moderate scale
Azure Cosmos DB (Azure) Globally distributed NoSQL / multi-model Global distribution, multiple consistency models Not relational in the Spanner sense; query/model differences When you want multi-model NoSQL with tunable consistency
CockroachDB (self-managed or managed) Distributed SQL with PostgreSQL-ish semantics Scale-out SQL, portability Ops complexity if self-managed; cost for managed; feature differences When you want cloud portability and distributed SQL
YugabyteDB (self-managed or managed) Distributed SQL (PostgreSQL-compatible layer) Horizontal scale, PG compatibility goals Operational overhead and compatibility differences When you need distributed SQL with PG compatibility focus

15. Real-World Example

Enterprise example: Global order management and inventory

  • Problem: A global retailer needs an always-on order management system with consistent inventory reservations. Outages during regional incidents are unacceptable, and traffic spikes during promotions are extreme.
  • Proposed architecture:
  • Spanner multi-region instance for orders/inventory state
  • Cloud Run services for checkout, payment orchestration, fulfillment
  • Change Streams → Dataflow → BigQuery for near-real-time analytics and fraud signals (verify feature applicability)
  • Cloud Monitoring + alerting + on-call runbooks
  • CMEK + VPC Service Controls for compliance (where required)
  • Why Spanner was chosen:
  • Strong consistency to prevent oversell/double charge
  • Scale-out to handle peak promotions
  • Managed replication and high availability to reduce operational risk
  • Expected outcomes:
  • Improved availability posture and simpler failover handling
  • Better consistency guarantees across microservices
  • Predictable scaling playbooks (capacity increases rather than sharding projects)

Startup/small-team example: Multi-tenant SaaS billing + entitlements

  • Problem: A small SaaS team needs reliable billing and entitlements for thousands of tenants. They want to avoid complex sharding and want a clear path to scale while staying lean operationally.
  • Proposed architecture:
  • Regional Spanner instance for tenant metadata, subscriptions, entitlements
  • Cloud Run for APIs
  • Scheduled jobs for invoicing and lifecycle updates
  • Backups with tested restore procedure
  • Why Spanner was chosen:
  • Relational modeling for subscriptions/entitlements relationships
  • Strong consistency for billing-critical updates
  • Reduced operational burden vs self-managed sharding
  • Expected outcomes:
  • Fewer production incidents related to data correctness
  • Clear scaling path as tenant count grows
  • Strong auditability for billing events (with careful logging/audit configuration)

16. FAQ

1) Is Spanner a relational database?
Yes. Spanner is a managed relational database with SQL querying, schemas, indexes, and ACID transactions, implemented as a distributed system.

2) Is Spanner strongly consistent?
Spanner is designed to provide strong consistency for transactions and reads by default. It also offers read options (like stale reads) for performance when your application can tolerate bounded staleness.

3) What’s the difference between a Spanner instance and a database?
An instance is the capacity and replication configuration boundary. A database is a logical container inside an instance that holds schema and data.

4) Should I choose GoogleSQL or PostgreSQL interface?
Choose based on application compatibility needs and feature support. GoogleSQL is native; PostgreSQL interface can reduce migration friction but isn’t identical to full PostgreSQL. Verify required features in official docs.

5) Does Spanner support joins?
Yes, Spanner supports SQL joins, but performance depends heavily on indexing, query patterns, and distributed execution characteristics.

6) How do I scale Spanner?
You scale by increasing serving capacity (nodes/processing units) and managing schema/index design. Autoscaling may be available depending on configuration—verify current capabilities in docs.

7) Do I need to shard my data manually?
Spanner automatically shards/partitions data. However, you must design primary keys to distribute load and avoid hotspots.

8) What is a hotspot and why is it bad?
A hotspot occurs when many writes target the same key range (e.g., sequential IDs). It overloads a subset of partitions, increasing latency and reducing throughput.

9) Does Spanner support foreign keys and constraints?
Constraint support depends on dialect and current product capabilities. Verify the exact constraint features you need in official docs for GoogleSQL or PostgreSQL interface.

10) How are backups handled?
Spanner supports backups and restore workflows. Costs and retention details apply. Test restores periodically and confirm RPO/RTO.

11) How do I connect securely from Cloud Run or GKE?
Use service accounts and Application Default Credentials (ADC). Prefer Workload Identity on GKE and avoid long-lived service account keys.

12) Can I put Spanner behind a private endpoint?
Private access patterns are possible using Google Cloud networking options (for example, Private Service Connect in supported scenarios). Verify current setup guidance in official docs.

13) Is Spanner good for analytics?
Spanner is primarily an OLTP database. For large-scale analytics, export/stream data into BigQuery or a dedicated analytics system.

14) How do I monitor performance?
Use Cloud Monitoring metrics (CPU/utilization, latency) and Cloud Logging/Audit Logs. Build dashboards and alerting for SLO symptoms.

15) What’s a safe way to start in production?
Start with a regional instance, load test with realistic traffic, validate schema and key design, set alerts and backups, then scale with measured increments.

16) Can I migrate from PostgreSQL/MySQL?
Yes, but expect SQL/data type changes and a redesign for distributed performance. Validate transaction semantics and query patterns; use official migration guidance where available.

17) How do I control costs?
Right-size compute, remove unused indexes, avoid expensive scans, use budgets/alerts, and keep dev/test footprints small.


17. Top Online Resources to Learn Spanner

Resource Type Name Why It Is Useful
Official documentation Spanner docs — https://cloud.google.com/spanner/docs Authoritative feature descriptions, APIs, concepts, and operational guidance
Official pricing Spanner pricing — https://cloud.google.com/spanner/pricing Current SKUs and pricing dimensions
Pricing calculator Google Cloud Pricing Calculator — https://cloud.google.com/products/calculator Region-specific cost estimation
Instance configurations Instance configurations — https://cloud.google.com/spanner/docs/instance-configurations Explains regional vs multi-region configs and location options
Quotas/limits Spanner quotas — https://cloud.google.com/spanner/quotas Current quotas and operational limits
Client libraries Spanner client libraries — https://cloud.google.com/spanner/docs/reference/libraries Language-specific best practices and samples
Authentication ADC docs — https://cloud.google.com/docs/authentication/provide-credentials-adc Secure, recommended ways to authenticate applications
Samples (official) GoogleCloudPlatform Spanner samples (GitHub) — https://github.com/GoogleCloudPlatform/cloud-spanner-samples Practical code examples and patterns (verify repo contents and freshness)
Architecture guidance Google Cloud Architecture Center — https://cloud.google.com/architecture Broader reference architectures and best practices that complement Spanner designs
Video learning Google Cloud Tech (YouTube) — https://www.youtube.com/@googlecloudtech Official talks, demos, and deep dives (search within channel for Spanner)

18. Training and Certification Providers

Institute Suitable Audience Likely Learning Focus Mode Website URL
DevOpsSchool.com Engineers, DevOps/SRE, architects Cloud/DevOps training that may include Google Cloud databases and operations Check website https://www.devopsschool.com/
ScmGalaxy.com Beginners to intermediate DevOps, SCM, automation concepts that support cloud delivery of database-backed apps Check website https://www.scmgalaxy.com/
CLoudOpsNow.in Cloud ops practitioners Cloud operations practices; may include monitoring, cost, and reliability topics Check website https://www.cloudopsnow.in/
SreSchool.com SREs, platform teams Reliability engineering practices applicable to running Spanner-backed services Check website https://www.sreschool.com/
AiOpsSchool.com Ops and platform teams AIOps concepts; monitoring/automation patterns relevant to production operations Check website https://www.aiopsschool.com/

19. Top Trainers

Platform/Site Likely Specialization Suitable Audience Website URL
RajeshKumar.xyz Cloud/DevOps training content (verify current offerings) Engineers and architects seeking guided learning https://rajeshkumar.xyz/
devopstrainer.in DevOps and cloud training (verify current offerings) Beginners to intermediate engineers https://www.devopstrainer.in/
devopsfreelancer.com Freelance DevOps support/training platform (verify services) Teams needing hands-on guidance https://www.devopsfreelancer.com/
devopssupport.in DevOps support/training (verify services) Ops teams and engineers https://www.devopssupport.in/

20. Top Consulting Companies

Company Name Likely Service Area Where They May Help Consulting Use Case Examples Website URL
cotocus.com Cloud/DevOps/engineering consulting (verify offerings) Architecture, implementation support, operational improvements Spanner adoption planning, migration approach review, CI/CD + monitoring setup https://cotocus.com/
DevOpsSchool.com Training + consulting (verify offerings) Enablement, platform practices, DevOps transformations Spanner operational readiness, SRE practices, cost optimization workshops https://www.devopsschool.com/
DEVOPSCONSULTING.IN DevOps consulting services (verify offerings) Delivery pipelines, operations, cloud adoption Spanner-backed microservices deployment patterns, observability and incident response setup https://www.devopsconsulting.in/

21. Career and Learning Roadmap

What to learn before Spanner

  • SQL fundamentals: joins, indexes, transactions, isolation concepts
  • Relational schema design and normalization basics
  • Google Cloud fundamentals:
  • projects, IAM, service accounts
  • VPC basics and service connectivity
  • Cloud Monitoring/Logging basics
  • Distributed systems basics:
  • consistency models
  • latency vs throughput tradeoffs

What to learn after Spanner

  • Advanced schema and performance design:
  • key distribution patterns
  • indexing strategies at scale
  • query tuning and plan analysis (as supported)
  • High availability and resilience:
  • multi-region architecture design
  • disaster recovery planning and game days
  • Data pipelines:
  • change capture patterns
  • Dataflow/BigQuery analytics integration
  • Security hardening:
  • CMEK, VPC Service Controls, audit strategies

Job roles that use Spanner

  • Cloud Solutions Architect
  • Backend Engineer (platform or product)
  • Site Reliability Engineer (SRE)
  • Platform Engineer
  • Database Reliability Engineer
  • Cloud Security Engineer (governance, IAM, perimeter controls)
  • Data Engineer (operational-to-analytics pipelines)

Certification path (Google Cloud)

Google Cloud certifications change over time; there isn’t always a Spanner-only certification. Common relevant certifications include: – Professional Cloud Architect – Professional Cloud Developer – Professional Cloud DevOps Engineer – Associate Cloud Engineer

Verify current certifications: https://cloud.google.com/learn/certification

Project ideas for practice

  • Build an order API (Cloud Run) backed by Spanner with:
  • idempotent order creation
  • transactional inventory reservation
  • secondary index queries for order status
  • Implement a multi-tenant SaaS entitlement store:
  • tenants, plans, entitlements, audit trail
  • Create a pipeline:
  • Spanner changes → (Change Streams) → Dataflow → BigQuery (verify feature availability and exact setup)

22. Glossary

  • ACID: Transaction properties—Atomicity, Consistency, Isolation, Durability.
  • Autoscaling: Automatically adjusting compute capacity based on load (availability depends on configuration and feature support).
  • Backup: A stored copy of database state used for restoration.
  • Bounded staleness: Reading data that may be slightly old (within a specified time bound) to improve latency/availability.
  • CMEK: Customer-Managed Encryption Keys—keys you manage in Cloud KMS for encrypting data at rest.
  • Database (Spanner): A logical schema and data container within a Spanner instance.
  • DDL: Data Definition Language—SQL statements that define schema (tables, indexes).
  • Dialect: SQL syntax and behavior variants. Spanner supports GoogleSQL and a PostgreSQL interface.
  • Hotspot: Concentrated reads/writes on a small key range that causes uneven load and performance issues.
  • IAM: Identity and Access Management in Google Cloud.
  • Index: Data structure to speed up queries; costs storage and write amplification.
  • Instance (Spanner): Capacity + replication configuration boundary hosting one or more databases.
  • Multi-region configuration: Deployment option with replicas across multiple regions for resilience and geo-availability.
  • Processing Unit (PU): A unit of Spanner compute capacity (billing/provisioning unit in many configs).
  • Regional configuration: Deployment option with replicas across multiple zones within one region.
  • Schema migration: Controlled changes to database schema over time.
  • SLO/SLA: Service Level Objective/Agreement—reliability targets and commitments.
  • Strong consistency: Reads reflect the most recent successful write (within defined consistency model).
  • Transaction abort: A transaction that must be retried due to concurrency control conflicts.

23. Summary

Spanner is Google Cloud’s managed distributed relational database for high-scale, mission-critical OLTP systems that need SQL, ACID transactions, strong consistency, and high availability—with regional or multi-region replication options.

It matters because it helps teams avoid painful manual sharding and complex correctness issues, while providing an operationally mature database foundation for global products. In the Google Cloud Databases portfolio, Spanner sits above traditional managed RDBMS offerings when you need scale-out and resilience with strong correctness guarantees.

Cost and security are central: – Costs are driven mainly by provisioned compute capacity (nodes/processing units), plus storage, backups, and any pipeline/logging add-ons. – Security is best handled with least-privilege IAM, service accounts/workload identity, audit logging, and (when required) CMEK and VPC Service Controls.

Use Spanner when correctness, availability, and scale are top priorities. Choose simpler databases when your workload is small or when full PostgreSQL engine parity is required.

Next step: re-run the hands-on lab, then practice schema/key design with a workload simulation and validate cost/performance using the official pricing calculator and Monitoring dashboards.