Where does your data live?

Data Architecture course · Intro session · student notes (30-minute talk)

By the end of this session you should be able to look at a data problem and say which store fits, why, and roughly what it costs. These notes cover every slide, the numbers we measured in the live demo, the demo queries so you can re-run them, and a self-check quiz.

1. The map: the whole data architecture

Data flows left to right through six layers. Five concerns cut across every layer. This course has one or more sessions on each box.

LayerWhat it doesTypical toolsCourse sessions
SourcesWhere data is bornApp databases, SaaS APIs, event streams, filesS10 Data contracts
IngestionMoves data inBatch ELT, log-based CDC, KafkaS11, S12
Storage (today)Keeps data cheap and durableS3/GCS, Parquet/ORC/Avro, Iceberg/DeltaS1, S2, S4
Compute & modelingShapes data for useSnowflake, BigQuery, Spark, DuckDB, dbtS3, S5-S8
ServingMakes data fast to askRedis, ClickHouse/Pinot, semantic layer, reverse ETLS13-S15
ConsumptionUses the dataBI, apps, ML, RAG/vector searchS21

Cross-cutting: Orchestration (S9) · Governance & security (S19) · Observability (S20) · FinOps (S18) · CI/CD and Infrastructure-as-Code (S16, S17).
Capstone: S22 design the whole architecture, S23 review cost and governance, S24 defend it.

2. The four stores we compare

StoreWhat it isGreat atWeak atTypical use
RedisIn-memory key → value storeSub-millisecond reads, key expiry (TTL), countersRAM is expensive; no ad-hoc queriesSessions, caches, rate limits, leaderboards
PostgresRow-oriented relational database (OLTP)ACID transactions, indexes, fast updatesScanning wide tables for analyticsSystem of record, app backends, orders, profiles
DuckDB / OLAPColumnar analytical engineScans, aggregations, compression, SQL directly on filesSingle-row updates, many small writesAnalytics, BI, warehouses, embedded/laptop
S3 + ParquetObject storage holding open columnar filesCheapest durable bytes, infinite scale, decoupled computeHigh first-byte latency, immutable filesData lake, landing zone, archives, history

The same data can live in all four. Each answers a different question well.

3. Which store? Speed vs cost

Every store trades speed against cost. Fast and cheap do not coexist, so architecture means putting each dataset on the cheapest tier that still meets its latency need. Order-of-magnitude figures (storage only, us-east-1-style list prices; they change over time, so re-check before relying on them):

StoreSimple-read latencyStorage cost
Redis (RAM)~0.2 ms~$10,000 per TB-month
Postgres (SSD)~2 ms~$110 per TB-month
DuckDB / OLAP~10 ms~$80 per TB-month plus compute
S3 + Parquet~80 ms first byte~$23 per TB-month

Check yourself: four scenarios

ScenarioBest storeWhy
Shopping-cart sessions that expire in 30 minutes, read on every page viewRedisIn-memory with native TTL: sub-ms reads and automatic expiry
Customer profiles edited by the app, read by ID, must never lose a writePostgresACID, all fields of a row stored together, indexed by key
5 years of orders; finance asks a new SUM / GROUP BY every weekDuckDB / columnar OLAPReads only the columns the query needs and compresses them
50 TB of raw clickstream logs queried maybe once a monthS3 + ParquetCheapest durable bytes; start an engine only when needed

"Just use Postgres" would have been wrong three times out of four.

4. Deep dive (Session 2): file formats & storage strategy

4.1 Row store vs column store

The same logical table can be laid out on disk two ways. A row store keeps each record's values together. A column store keeps each column's values together.

4.2 Anatomy of a Parquet file

A Parquet file is split into row groups (about 120,000 rows each in our file). Inside each row group, every column is stored as its own column chunk. At the end of the file a footer stores the schema, the min and max of every chunk, and offsets. An engine reads the footer first, then decides which chunks it can skip.

Footer of the real 5M-row file used in the demo (41 row groups):

Row groupColumnMinMaxBytes (zstd)
0order_id1122,880162,139
0statuscancelledshipped26,173
1order_id122,881245,760124,817

order_id ranges never overlap, so whole row groups can be skipped. status has the same min/max everywhere, so it is useless for skipping.

4.3 Skipping data (predicate pushdown)

4.4 Partitioning

Folder names carry partition values, e.g. orders_by_month/order_year=2025/order_month=6/part.parquet. A query filtering on year and month opens 1 of 24 files; with no filter it opens all 24. The cheapest query is the one that never touches the data.

Partition keyVerdictWhy
order_year / order_monthGood24 folders, matches the filter, similar sizes
customer_idBad200,000 folders of ~25 rows: the small-files problem; listing and opening files costs more than reading data
countryCarefulSkew: IN holds 17% of rows, BR only 5%, so one partition is ~3x its peers and one worker stays busy while others idle

Rule of thumb: partition on low-cardinality columns you always filter by (date, region); never on ids.

4.5 File formats at a glance

ParquetORCAvro
LayoutColumnarColumnarRow
Best forAnalytics, data lakesHive / HadoopStreaming, Kafka

5. Live demo: same 5,000,000 orders in four engines

One synthetic orders table (5M rows, 13 columns, 2024-2025) loaded into: Redis (the hot last 300k orders as hashes, plus a hand-built per-customer index and one precomputed aggregate), Postgres (row store with a primary key and a customer index), DuckDB (native columnar file), and S3-compatible storage holding zstd Parquet queried in place by DuckDB.

5.1 Storage footprint

FormatSize
CSV export1.00 GB
Postgres table + indexes1.29 GB
DuckDB native file108 MB
Parquet (snappy)190 MB
Parquet (zstd)116 MB
Redis, hot 300k rows only272 MB
Redis, if all 5M rows lived in RAM (estimate)~4.5 GB

Postgres vs zstd Parquet is about 11x larger for the same rows.

5.2 The race: typical results (local laptop, warm; yours will vary)

WorkloadRedisPostgresDuckDBS3 + ParquetLesson
1. Fetch one order by id~0.4-1 ms~0.7-2 ms~2-3 ms~30 msRAM and row stores win. DuckDB/Parquet manage only because ids are sorted (min/max skipping).
2. All orders of one customer~1.5 ms (partial)~1.2 ms~4 ms~26 msPostgres wins with its index. Redis holds only the hot 300k orders, so its answer is partial.
3. Revenue per category (5M rows)~0.8 ms (precomputed)~270 ms~3-4 ms~15-19 msColumnar wins the real computation, ~50-80x faster than Postgres. Redis only answers questions someone precomputed.
4. A brand-new question (refund value by country)~1.8 s (app-side scan)~130 ms~3 ms~19 msRedis cannot answer unplanned questions. Postgres' gap grows linearly with data size.
5. Insert one order~1 ms~2.6 ms~5.6 ms~21 msOn S3 every write is a new object; writing row by row creates tiny files.
6. Change one value~0.5 ms~2.3 ms~3 ms~118 msParquet is immutable: S3 rewrote ~205,000 rows to change one. This is why table formats (Iceberg, Delta) exist (Session 4).

Honest caveats: S3 is a local S3-compatible server, so real S3 adds roughly 20-100 ms per request. Redis holds only the hot 300k rows. The DuckDB file cache is disabled so every S3 run really hits object storage. Timings vary run to run.

5.3 Demo queries (run them yourself)

The SQL below runs unchanged on Postgres, DuckDB (native table orders) and Parquet (a view named orders over s3://lake/orders/orders.parquet).

-- 1. Point lookup
SELECT * FROM orders WHERE order_id = 4800000;

-- 2. One customer's orders
SELECT order_id, customer_id, category, amount, status
FROM orders WHERE customer_id = 2 ORDER BY order_id;

-- 3. Revenue by category
SELECT category, round(sum(amount),2) AS revenue
FROM orders GROUP BY 1 ORDER BY 2 DESC;

-- 4. A brand-new question
SELECT country, round(avg(amount),2) AS avg_order_value, count(*) AS orders
FROM orders
WHERE status = 'refunded' AND created_at >= '2025-01-01'
GROUP BY 1 ORDER BY 2 DESC;

Redis equivalents: HGETALL order:4800000, SMEMBERS cust:2, HGETALL agg:revenue_by_category.

Parquet X-ray (DuckDB on object storage):

-- Footer: min/max per row group
SELECT row_group_id AS rg, path_in_schema AS col,
       stats_min_value AS min, stats_max_value AS max,
       total_compressed_size AS bytes
FROM parquet_metadata('s3://lake/orders/orders.parquet')
WHERE path_in_schema IN ('order_id','status') AND row_group_id < 3
ORDER BY 1, 2;

-- Partition pruning: 1 file vs 24
SELECT count(*) AS orders, count(DISTINCT filename) AS files_read
FROM read_parquet('s3://lake/orders_by_month/*/*/*.parquet',
                  hive_partitioning=true, filename=true)
WHERE order_year = 2025 AND order_month = 6;

6. Cheat-sheet: pick the store by access pattern

I need…RedisPostgresDuckDB / OLAPS3 + Parquet
Sub-millisecond reads by keyBestGoodPainfulPainful
ACID transactions & integrityPainfulBestPainfulWrong tool
Frequent single-row updatesBestBestPainfulWrong tool
Big scans & aggregationsWrong toolPainfulBestGood
Unplanned, ad-hoc questionsWrong toolGoodBestGood
Cheap long-term retentionWrong toolPainfulGoodBest

Real systems use several together: Postgres is the source of truth, Redis caches the hot path, events land in S3 as Parquet, and DuckDB or a warehouse answers analytics. That chain is the architecture from section 1.

7. Self-check quiz (answers at the end of each question)

  1. A login service stores 1M sessions that each expire after 30 minutes and are read on every request. Best fit?
    Answer: Redis with a TTL. In-memory, sub-millisecond, native key expiry.
  2. Why is SELECT SUM(amount) faster on a columnar file than on a row store?
    Answer: it reads only the amount column, and that column compresses well.
  3. You must change ONE value inside a 200 MB Parquet file on S3. What happens?
    Answer: the file is rewritten (or replaced by a new file). Objects and Parquet files are immutable; Iceberg/Delta add metadata so a change becomes a new file plus a pointer swap.
  4. You partition 5M orders by customer_id (200k distinct values). Result?
    Answer: 200,000 tiny files, the small-files problem.
  5. Why does WHERE order_id = 4200000 on sorted Parquet read almost nothing?
    Answer: min/max statistics in the footer let the engine skip row groups. On an unsorted column the ranges overlap and nothing is skipped.
  6. 7 years of audit logs, almost never read, must be cheap and durable. Where?
    Answer: object storage (Parquet) with a lifecycle policy to a colder tier.

8. Three things to remember

  1. Layout is architecture. Row vs column, sort order and partitioning decide speed and cost before any tuning.
  2. One store never fits all. Hot → RAM, transactional → row store, analytical → columnar, everything else → cheap object storage.
  3. The cheapest query touches the least data. Skip with stats, prune with partitions, project only the columns you need.

9. Glossary

OLTP / OLAPTransaction processing (many small reads/writes) vs analytical processing (few big scans).
ACIDAtomicity, Consistency, Isolation, Durability: the guarantees of a transactional database.
TTLTime to live: a key that deletes itself after a set time.
Row group / column chunkThe two levels a Parquet file is chopped into.
Predicate pushdownUsing filters plus min/max stats to avoid reading data at all.
Partition pruningSkipping whole folders/files because their path value cannot match the filter.
Small-files problemToo many tiny files make listing and opening cost more than reading.
SkewUneven data distribution that leaves one worker or partition doing most of the work.
Decoupled storage and computeData sits in cheap object storage; engines are started only when needed.

10. Next steps