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.
Data flows left to right through six layers. Five concerns cut across every layer. This course has one or more sessions on each box.
| Layer | What it does | Typical tools | Course sessions |
|---|---|---|---|
| Sources | Where data is born | App databases, SaaS APIs, event streams, files | S10 Data contracts |
| Ingestion | Moves data in | Batch ELT, log-based CDC, Kafka | S11, S12 |
| Storage (today) | Keeps data cheap and durable | S3/GCS, Parquet/ORC/Avro, Iceberg/Delta | S1, S2, S4 |
| Compute & modeling | Shapes data for use | Snowflake, BigQuery, Spark, DuckDB, dbt | S3, S5-S8 |
| Serving | Makes data fast to ask | Redis, ClickHouse/Pinot, semantic layer, reverse ETL | S13-S15 |
| Consumption | Uses the data | BI, apps, ML, RAG/vector search | S21 |
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.
| Store | What it is | Great at | Weak at | Typical use |
|---|---|---|---|---|
| Redis | In-memory key → value store | Sub-millisecond reads, key expiry (TTL), counters | RAM is expensive; no ad-hoc queries | Sessions, caches, rate limits, leaderboards |
| Postgres | Row-oriented relational database (OLTP) | ACID transactions, indexes, fast updates | Scanning wide tables for analytics | System of record, app backends, orders, profiles |
| DuckDB / OLAP | Columnar analytical engine | Scans, aggregations, compression, SQL directly on files | Single-row updates, many small writes | Analytics, BI, warehouses, embedded/laptop |
| S3 + Parquet | Object storage holding open columnar files | Cheapest durable bytes, infinite scale, decoupled compute | High first-byte latency, immutable files | Data lake, landing zone, archives, history |
The same data can live in all four. Each answers a different question well.
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):
| Store | Simple-read latency | Storage 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 |
| Scenario | Best store | Why |
|---|---|---|
| Shopping-cart sessions that expire in 30 minutes, read on every page view | Redis | In-memory with native TTL: sub-ms reads and automatic expiry |
| Customer profiles edited by the app, read by ID, must never lose a write | Postgres | ACID, all fields of a row stored together, indexed by key |
| 5 years of orders; finance asks a new SUM / GROUP BY every week | DuckDB / columnar OLAP | Reads only the columns the query needs and compresses them |
| 50 TB of raw clickstream logs queried maybe once a month | S3 + Parquet | Cheapest durable bytes; start an engine only when needed |
"Just use Postgres" would have been wrong three times out of four.
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.
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 group | Column | Min | Max | Bytes (zstd) |
|---|---|---|---|---|
| 0 | order_id | 1 | 122,880 | 162,139 |
| 0 | status | cancelled | shipped | 26,173 |
| 1 | order_id | 122,881 | 245,760 | 124,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.
WHERE order_id = 4200000: the footer shows only one row group can contain it, so 1 of 41 is read (about 6 ms locally).WHERE customer_id = 4242: every row group's range spans 1 to 200,000, so 41 of 41 are read (about 12 ms locally).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 key | Verdict | Why |
|---|---|---|
| order_year / order_month | Good | 24 folders, matches the filter, similar sizes |
| customer_id | Bad | 200,000 folders of ~25 rows: the small-files problem; listing and opening files costs more than reading data |
| country | Careful | Skew: 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.
| Parquet | ORC | Avro | |
|---|---|---|---|
| Layout | Columnar | Columnar | Row |
| Best for | Analytics, data lakes | Hive / Hadoop | Streaming, Kafka |
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.
| Format | Size |
|---|---|
| CSV export | 1.00 GB |
| Postgres table + indexes | 1.29 GB |
| DuckDB native file | 108 MB |
| Parquet (snappy) | 190 MB |
| Parquet (zstd) | 116 MB |
| Redis, hot 300k rows only | 272 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.
| Workload | Redis | Postgres | DuckDB | S3 + Parquet | Lesson |
|---|---|---|---|---|---|
| 1. Fetch one order by id | ~0.4-1 ms | ~0.7-2 ms | ~2-3 ms | ~30 ms | RAM 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 ms | Postgres 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 ms | Columnar 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 ms | Redis cannot answer unplanned questions. Postgres' gap grows linearly with data size. |
| 5. Insert one order | ~1 ms | ~2.6 ms | ~5.6 ms | ~21 ms | On 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 ms | Parquet 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.
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;
| I need… | Redis | Postgres | DuckDB / OLAP | S3 + Parquet |
|---|---|---|---|---|
| Sub-millisecond reads by key | Best | Good | Painful | Painful |
| ACID transactions & integrity | Painful | Best | Painful | Wrong tool |
| Frequent single-row updates | Best | Best | Painful | Wrong tool |
| Big scans & aggregations | Wrong tool | Painful | Best | Good |
| Unplanned, ad-hoc questions | Wrong tool | Good | Best | Good |
| Cheap long-term retention | Wrong tool | Painful | Good | Best |
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.
| OLTP / OLAP | Transaction processing (many small reads/writes) vs analytical processing (few big scans). |
| ACID | Atomicity, Consistency, Isolation, Durability: the guarantees of a transactional database. |
| TTL | Time to live: a key that deletes itself after a set time. |
| Row group / column chunk | The two levels a Parquet file is chopped into. |
| Predicate pushdown | Using filters plus min/max stats to avoid reading data at all. |
| Partition pruning | Skipping whole folders/files because their path value cannot match the filter. |
| Small-files problem | Too many tiny files make listing and opening cost more than reading. |
| Skew | Uneven data distribution that leaves one worker or partition doing most of the work. |
| Decoupled storage and compute | Data sits in cheap object storage; engines are started only when needed. |
docker compose up --build, then open localhost:8000).