Skip to main content

Choosing a Database

Exam guide§2.2

Choosing the right database is like choosing the right foundation for your application. With all the relational and NoSQL options available, the common first step is deciding whether your application is primarily transactional or analytical. Classify the workload first, then weigh the key factors below - data structure, consistency, scalability, query patterns, integration, and cost - to land on a specific product.

Structured or Semi-structured?Transactional workloadAnalytical workloadOnline transaction processing, OLTPUsed when fast data insertsand updates are required tobuild row-based records.Online analytical processing, OLAPUsed when entire datasetsneed to be read. Oftenrequire complex queries.SpannerGlobal scale, strong consistencyCloud SQLLower cost, less demandingBigQueryPetabyte-scale analytics
Classifying the workload is the first step in choosing a database. A transactional workload (OLTP - fast inserts and updates to row-based records) maps to relational products - Spanner for global scale and strong consistency, Cloud SQL for lower-cost general use. An analytical workload (OLAP - reading entire datasets with complex queries) maps to BigQuery for petabyte-scale analytics.

Types of workloads

Transactional workloads (OLTP)

Transactional workloads come from online transaction processing (OLTP) systems. These excel at rapidly handling large numbers of short transactions - quickly inserting, updating, or retrieving small chunks of data. E-commerce platforms and financial systems are classic examples.

Picture a clothing retailer with a global storefront: adding to cart, updating quantities, and processing payments are all transactions. For a global e-commerce platform, Spanner is ideal - it delivers high availability and strong consistency no matter where customers are based. Cloud SQL is a more budget-friendly option for businesses with less demanding requirements.

A banking app is also transactional and demands ACID guarantees, where accuracy and compliance are critical. Spanner fits here too: alongside global availability, it handles high transactional volumes with low latency, keeping bank transfers and payment processing secure, consistent, and accurate.

Exam cueTransactional signal words point to a relational database

Transactional workloads typically require a database with ACID properties.

Scenario stresses inserts/updates of small records, ACID, or financial accuracyRelational: Cloud SQL, Spanner, AlloyDB

Do not reach for an analytical warehouse like BigQuery.

Analytical workloads (OLAP)

Analytical workloads come from online analytical processing (OLAP) systems, where large datasets are examined to extract insights, patterns, and trends. They involve complex queries over large datasets and are read-heavy. Business intelligence (BI) and machine learning applications are typical examples.

Take the same e-commerce app and push it further with tailored product or content recommendations. The core of the app is still transactional, but generating those recommendations introduces an analytical workload. When that analysis spans large datasets and complex queries, BigQuery is a powerful option - Google's petabyte-scale data warehouse and data lake solution.

GotchaAn application is often both - do not force a single database

Most real apps mix workloads: the e-commerce store runs transactional checkout and analytical recommendations. You do not have to choose between a database and a data warehouse - Cloud SQL/Spanner and BigQuery work together as part of Google's Data Cloud. If a scenario describes both fast transactions and heavy reporting, the answer may be two products, not one.

Key factors for choosing a product

Knowing whether your app leans relational or non-relational is the first step. That distinction opens onto the factors that guide the final choice. Weigh each against your application's requirements - there is no one-size-fits-all answer, and the best choice depends on your specific needs and priorities.

Data structure

The key factor in the relational-vs-NoSQL decision is your data structure. If your data model benefits from a clear structure with relationships between tables (like customers, orders, and products), a relational database is a good fit - it enforces data integrity and provides powerful SQL querying. If your data is less structured, more flexible, or needs high scalability for unstructured data (like user profiles, sensor data, or social media posts), consider NoSQL. Analytical applications may involve both structured and unstructured data; BigQuery and Cloud Storage accommodate these.

Data consistency

Data consistency is critical for many transactional applications - it ensures all users see the same updated data. Cloud SQL, AlloyDB, and Spanner provide strong-consistency options. Where some temporary inconsistency (eventual consistency) is acceptable, NoSQL databases like Bigtable, Firestore, and Memorystore trade it for higher availability and scalability.

GotchaStrong vs eventual consistency is a product signal

"All users must see the same updated value immediately" points to a strong-consistency store - Cloud SQL, AlloyDB, or Spanner (Spanner keeps it even at global scale). If the workload tolerates brief staleness in exchange for higher availability and scale, a NoSQL option fits.

Scalability and performance

Very high-volume transactional applications may need to scale to peak loads while keeping latency low - Spanner excels here, scaling horizontally. If your needs are more modest or you want to get started quickly, Cloud SQL offers simple vertical scalability: increase the size of the database instance.

Query patterns

Complex analytical queries - aggregation and data analysis - need to run efficiently. BigQuery's architecture and query engine are optimized for these analytical workloads. If fast reads of individual records or documents matter most, Memorystore is an excellent choice.

Integration

Google Cloud databases integrate to varying degrees with other services. BigQuery integrates seamlessly with analytics services like Managed Service for Apache Spark and Dataflow, as well as operational databases such as Spanner and Bigtable; Firestore integrates well with Firebase and other application-development platforms.

Cost

Each database has a different pricing model - per query, per storage, or per instance - so consider which fits your use patterns. Some databases offer features like autoscaling that optimize cost based on demand, which suits spiky workloads.

Generative AI workloads

Generative AI is a distinct workload with the same key factors read through a new lens. Gen AI apps deal with unstructured data - text, images, audio, even code - and need to capture its meaning, not just store the raw bytes. That semantic representation is a vector embedding, and the database you pick has to store and search those vectors efficiently.

A vector embedding converts something (a word, sentence, or image) into a list of numbers - a point in a multi-dimensional space. The points are arranged so that distance and direction capture semantic relationships: similar things sit close together. "Find similar" then becomes "find the nearest points", which is exactly what vector search does inside the database.

nearest neighbours = most similarlarge distance → unrelatedcatliondogcartruckquery
A vector embedding turns text, an image, or audio into a point in a multi-dimensional space. Semantically similar items land near each other, so "find similar" becomes "find the nearest points" - the query vector's closest neighbours (cat, lion) are returned, distant ones (car) are not.

For example, a gen AI app answering questions about animals could store them in a relational table and filter with WHERE diet = 'carnivore' - correct, but blind to how animals relate. Embed each animal into a vector instead and "which animals are like a lion?" becomes measuring the distance between vectors - the database returns the semantically nearest animals, no explicit category column required.

All Google Cloud databases support vector embeddings, but they differ in how well they search them:

  • AlloyDB - optimized for vector search and similarity matching, with the fastest vector indexes and natural-language support. The "best vector database" answer.
  • Spanner and Cloud SQL for PostgreSQL - also optimized for vector search; pick them when you already need their relational/global traits.
  • BigQuery - vector search over large datasets with complex SQL.
  • Firestore - vectors alongside unstructured / semi-structured data, real-time updates, and offline support.

These databases integrate with the Gemini Enterprise Agent Platform (Vertex AI), so an embedding model can turn text prompts into vectors directly, without a separate serving stack.

Exam cueEvery Google DB stores vectors - AlloyDB searches them fastest

If a question asks which database to store embeddings in, several work - this is about which one searches them fastest.

Stresses fastest vector search, similarity at scale, or natural-language queriesAlloyDB

Do not default to Cloud SQL just because it also supports pgvector.

Gen AI selection factors

The same key factors above, read through a generative-AI lens:

DECISIONWhich database for a gen AI need?
Fastest vector search, natural language, high-performance queriesAlloyDB
Large-scale, globally distributed LLM dataSpanner
Document / flexible data types, real-timeFirestore
Vector search over huge analytical datasetsBigQuery
In-memory caching of frequently used dataMemorystore
Pick this when: the gen AI requirement is the deciding signal

Gen AI datasets are large, so storage cost and operational efficiency matter too: fully-managed AlloyDB and Cloud SQL minimize operational overhead and keep costs down without you running the infrastructure.

NumbersAlloyDB gen AI performance
  • Up to 4x faster transactional than standard PostgreSQL.
  • Up to 10x faster vector queries.
  • Up to 100x faster analytical queries.
  • Adds model endpoint management and secure parameterized views for hardening gen AI apps.
GotchaSecurity is table stakes, not a differentiator

AlloyDB, Cloud SQL, Spanner, and Firestore all encrypt data at rest and in transit, offer IAM access control, and keep audit logs. Don't pick a database on encryption alone - it decides nothing. AlloyDB's extra gen AI hardening (model endpoint management, parameterized views) is the only real tiebreaker here.

Recap

DECISIONTransactional or analytical?
Fast inserts/updates, short transactions, ACID (OLTP)Relational: Cloud SQL / Spanner
Global e-commerce or finance, high volume, strong consistencySpanner
Standard OLTP app, less demanding, cost-sensitiveCloud SQL
Read entire datasets, complex queries, BI/ML (OLAP)BigQuery
Pick this when: classify the workload first, then read scale signals
CompareWorkload to product at a glance
WorkloadProcessingAccess patternTypical product
TransactionalOLTPFast inserts/updates of small, row-based recordsSpanner / Cloud SQL
AnalyticalOLAPRead entire datasets with complex queriesBigQuery
DECISIONWhich key factor points where?
Structured, relationships, integrityRelational: Cloud SQL / AlloyDB / Spanner
Flexible / unstructured, high scaleNoSQL: Firestore / Bigtable
Strong consistency requiredCloud SQL / AlloyDB / Spanner
Eventual consistency acceptable for scaleBigtable / Firestore / Memorystore
Very high volume, low latency at peakSpanner (horizontal)
Modest scale, quick start, cost-sensitiveCloud SQL (vertical)
Complex analytical queries / aggregationBigQuery
Fast reads of individual recordsMemorystore
Pick this when: read the dominant requirement, then the product