Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 159/ 160
08. Transactions, Security & Production SQL Administration

Cloud SQL Databases & Analytical Engines (Snowflake, BigQuery, DuckDB)

Compare cloud OLTP and OLAP engines and when to use each SQL dialect.

IntermediateCloud OLTP · Snowflake / BigQuery3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Apps use one kind of database for quick single changes, and analysts use another kind built to add up huge amounts of data quickly.

Think of it like…

A shop's till versus its accounts office: the till (OLTP) handles one sale at a time, instantly, all day. The accounts office (the warehouse) adds up months of sales in bulk. DuckDB is a calculator on your own desk for the spreadsheets you brought home.

Where you’ve seen it

A startup's dashboards ran directly on its RDS PostgreSQL primary, and month-end reports slowed checkout. They now replicate tables to BigQuery nightly with an ELT tool, partition the events table by day and cluster it by customer_id, and point the BI tool at BigQuery. Checkout latency recovers, and a monthly report that scanned 2 TB now scans 40 GB because it filters on the partition column.

Words you’ll hear

OLTP vs OLAP
Many small reads and writes for apps vs large scans and aggregates for analysis.
Columnar storage
Stores each column separately, so queries read only the columns they use.
Separated storage and compute
Snowflake and BigQuery scale query power independently of stored data.
Partition pruning
Skipping partitions (such as days) that a filter rules out, so fewer bytes are scanned.

Visual diagram

Loading interactive diagram

Theory & example queries

Managed OLTP vs analytical engines

Managed OLTP services run the same engine you'd run yourself, so SQL, indexes and EXPLAIN work as usual; what you buy is automated backups and point-in-time restore, replicas, failover, patching and storage growth. Aurora and AlloyDB add redesigned storage layers for faster failover and more replicas. They're the right home for application data, but large analytical scans compete with user traffic for CPU, memory and I/O.

Warehouses are built the other way round. Columnar storage reads only the columns a query names and compresses them heavily; massively parallel execution splits scans across many workers. They're poor at single-row updates and high-concurrency point lookups, and excellent at "revenue by region by month over three years". Data reaches them through batch ELT tools or change data capture (CDC) from the OLTP database's log.

DuckDB querying files directlyQuery example
1Input dataStart from the source rows or state that the statement sees.
This statement works with the current schema, configuration, or database state rather than a row dataset. The command still follows the same input → query → result flow.
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  country,3  COUNT(*) AS signups4FROM5  read_parquet ('exports/users/*.parquet')6WHERE7  signup_date >= DATE '2026-01-01'8GROUP BY9  country10ORDER BY11  signups DESC;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/11
3OutputInspect the representative rows, affected-row count, plan, or command status.
Expected output3 sample rows
Expected output
countrysignups
India18420
United States12650
Germany8790

Note: Illustrative counts from the matched Parquet files; the glob and column values determine the real result.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

No server, no load step; DuckDB reads only the needed columns from the Parquet files.

Key takeaway: OLTP for the app, columnar warehouse for analytics, DuckDB for local files.

Cost models and keeping queries cheap

BigQuery on-demand pricing charges by bytes scanned (capacity pricing with slots is the alternative). SELECT * reads every column, and LIMIT doesn't reduce bytes read on an unclustered table, so select only the columns you need, partition large tables by date, cluster by common filter columns, set require_partition_filter on big tables, and check the estimate with a dry run before running. Snowflake charges credits for the time a virtual warehouse runs (per second, with a 60-second minimum); each size step up doubles credits per hour. Set auto-suspend, size warehouses to the workload, and separate ETL from BI warehouses.

Both engines cache results of identical queries for about 24 hours, so repeated dashboard refreshes can be free. Dialects differ in details: Snowflake, BigQuery and DuckDB support QUALIFY to filter window-function results directly, BigQuery quotes identifiers with backticks, and date functions vary, so keep marts simple and test queries on the target engine.

A cheaper BigQuery queryQuery example
1Input dataStart from the source rows or state that the statement sees.
orders
3 rows
orders sample rows
idcustomer_idstatusamountcoupon_code
1011paid249NULL
1022paid120WELCOME10
1031shipped89.5NULL
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  customer_id,3  SUM(amount) AS revenue4FROM5  shop.orders6WHERE7  order_date BETWEEN '2026-11-01' AND '2026-11-30'8GROUP BY9  customer_id;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/9
3OutputInspect the representative rows, affected-row count, plan, or command status.
Expected output3 sample rows
Expected output
customer_idrevenue
104224500
208718250
31149900

Note: Representative customer totals for the one-month partition pruned by the query.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

On a table partitioned by order_date, this scans one month of two columns instead of every column for all time.

Key takeaway: BigQuery: scan fewer bytes. Snowflake: run warehouses for less time.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Design

Classify the workload

Single-row reads and writes for an app → OLTP; large scans and aggregates → warehouse; files on a laptop or in CI → DuckDB.

Focus at this step

checkout = OLTP · monthly revenue = OLAP

What to watch at this step
Don't mix
on the primary
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

Cloud SQL engines fall into two families. Managed OLTP databases (Amazon RDS and Aurora, Google Cloud SQL and AlloyDB, Azure SQL, Neon, Supabase) run PostgreSQL, MySQL or SQL Server for applications, with backups and failover handled for you. Analytical engines (Snowflake, BigQuery, Redshift) store data in columns and spread queries across many machines for scans over billions of rows. DuckDB is the odd one out: an analytical engine that runs inside your process, ideal for Parquet and CSV files on a laptop or in a pipeline.

Why it matters: Most companies run both families: the app on a managed OLTP database and reporting in a warehouse, connected by an ELT or CDC pipeline. Analysts and data engineers need to know how each engine charges (by compute time or bytes scanned), how to keep queries cheap, and which engine fits a job. Interviews ask "why not just run the dashboards on Postgres?" and "how would you cut our BigQuery bill?"

When to reach for it

  • A warehouse for dashboards instead of the app's primary
  • DuckDB for exploring exports and Parquet files
  • Managed OLTP to avoid running databases yourself

When to avoid or be careful

  • Heavy reports on the OLTP primary
  • SELECT * on large BigQuery tables
  • Snowflake warehouses without auto-suspend

Managed OLTP vs cloud warehouse vs DuckDB

Managed OLTP (RDS, Cloud SQL, Aurora, Azure SQL)
Best for: Application data and transactions

Strengths: Familiar engines; managed backups, replicas and failover.

Watch out: Large analytical scans hurt app performance.

Cloud warehouse (Snowflake, BigQuery, Redshift)
Best for: Company-wide analytics over large data

Strengths: Columnar, distributed, scales on demand.

Watch out: Costs grow with careless queries; not for app transactions.

DuckDB
Best for: Local analysis, files, CI tests, small pipelines

Strengths: No server; very fast on one machine; reads Parquet and CSV directly.

Watch out: Single machine; not a shared, multi-user warehouse.

Interview signals & numbers to know

When this topic comes up

  • “Why not run analytics on our Postgres?”
  • “Our BigQuery bill doubled”
  • “Snowflake or BigQuery?”
  • OLTP vs OLAP
  • DuckDB for local analysis

Benchmarks & rules of thumb

~24 h -
result cache lifetime in Snowflake and BigQuery
60 s -
Snowflake's minimum billing per warehouse start
2× -
credits per hour for each Snowflake size step

Common mistakes & follow-ups

Common interview mistakes

  • Pointing the BI tool at the production primary, so month-end dashboards slow down checkout.
  • Running SELECT * … LIMIT 10 on a 5 TB BigQuery table and paying to scan all of it.
  • Leaving a large Snowflake warehouse running all night for a dashboard that refreshes once an hour.

Likely interviewer follow-ups

  • Why shouldn't dashboards query the application database directly?
  • How would you reduce the cost of BigQuery queries?
  • When would you use DuckDB instead of a warehouse?
Interview tip: Frame the answer by workload first (OLTP vs OLAP), then cost model (bytes scanned vs compute time). Matching engine to workload is what interviewers want to hear.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Cloud SQL Databases & Analytical Engines (Snowflake, BigQuery, DuckDB) with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
Read Replicas, High Availability & Failover Basics
Next topic
Capstone Project: Designing, Optimizing & Querying a Full E-Commerce & SaaS Analytics Warehouse