Documentation Index
Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
Use this file to discover all available pages before exploring further.
Database Engineering Mastery
A comprehensive curriculum designed for engineers aiming for senior/staff roles and those interested in contributing to PostgreSQL. This isn’t another SQL tutorial — it’s a deep dive into how databases really work.Target Outcome: Senior Database Engineer / PostgreSQL Contributor
Prerequisites: Basic programming, some SQL exposure
Primary Focus: PostgreSQL (with universal RDBMS concepts)
Why This Course?
Senior Interview Ready
OSS Contribution Path
Production Battle-Tested
Internals-First Approach
Course Structure
The curriculum is organized into 4 tracks progressing from foundations to contribution-ready expertise:How to Use This Course
Treat this as a 12-16 week roadmap rather than a reference you skim once. The most common mistake learners make is trying to rush through the material without hands-on practice. Database engineering is a craft — you develop intuition by running queries, breaking things, and observing the results yourself.- Step 1 — Foundations first: Complete SQL Foundations, Database Design, and Transactions & Concurrency before touching performance or internals. These three modules build the mental model that everything else depends on. Skipping them is like trying to debug a distributed system without understanding networking.
- Step 2 — Parallel practice: For each concept, run the commands yourself on a local PostgreSQL instance (Docker is fine) and tweak examples until you can predict the outcome. If you can predict what
EXPLAIN ANALYZEwill show before you run it, you have internalized the concept. - Step 3 — Performance & internals: Once you’re comfortable writing queries, move into Indexing, Query Optimization, Performance Tuning, and the Internals track. This is where you transition from “developer who uses a database” to “engineer who understands databases.”
- Step 4 — Production systems: Finish with Replication, Scaling, Operational Excellence, and Case Studies; apply them to a project at work or a personal side project. Real production experience, even on a small scale, is worth more than reading about it.
- Step 5 — Interview & OSS: Use the Interview Prep, Source Code, and Contributing modules in the last 2-3 weeks to polish your narrative and ship at least one small contribution (docs patch, bug report, or extension experiment).
Track 1: Foundations
Build unshakeable fundamentals that senior engineers rely on.Module 1: SQL Mastery
Module 1: SQL Mastery
- Query execution order (FROM → WHERE → GROUP BY → SELECT → ORDER BY)
- JOIN algorithms: Nested Loop, Hash Join, Merge Join
- Subqueries vs CTEs vs derived tables — when to use each
- Window functions for analytics and running calculations
- Advanced: Recursive CTEs, LATERAL joins, JSON operations
Module 2: Database Design & Modeling
Module 2: Database Design & Modeling
- Logical vs physical data modeling
- Normalization theory (1NF through BCNF) — and when to break rules
- Temporal data patterns (SCD Type 1, 2, 3)
- Polymorphic associations and inheritance strategies
- Schema evolution: migrations, backward compatibility, zero-downtime changes
Module 3: Transactions & Concurrency
Module 3: Transactions & Concurrency
- ACID deep dive: what each property really guarantees
- Isolation levels: Read phenomena, snapshot isolation, serializable
- PostgreSQL’s MVCC implementation details
- Locking: row-level, table-level, advisory locks
- Deadlock detection and prevention strategies
- Optimistic vs pessimistic concurrency control
Track 2: Performance
The skills that differentiate senior from mid-level engineers.Module 4: Indexing Deep Dive
Module 4: Indexing Deep Dive
- B-Tree internals: structure, splits, fill factor
- Hash indexes: when they outperform B-Trees
- GIN indexes for full-text and JSONB
- GiST and SP-GiST for geometric and range data
- BRIN for time-series and append-only tables
- Index-only scans and covering indexes
- Partial indexes and expression indexes
- Index bloat, reindexing, and maintenance
Module 5: Query Optimization
Module 5: Query Optimization
- EXPLAIN ANALYZE mastery: reading every field
- Query planner internals: cost estimation, cardinality
- Statistics: pg_statistic, extended statistics, manual adjustment
- Common anti-patterns: implicit casts, functions on columns, OR chains
- Join order optimization
- Parallel query execution
- Query plan caching and prepared statements
Module 6: Performance Tuning
Module 6: Performance Tuning
- Memory configuration: shared_buffers, work_mem, maintenance_work_mem
- Checkpoint tuning and WAL configuration
- Connection management and pooling strategies
- Identifying bottlenecks: CPU, I/O, locks, network
- Benchmarking methodology: pgbench, custom workloads
- Performance regression testing
Track 3: Internals
Understand how PostgreSQL actually works — essential for senior roles and OSS contribution.Module 7: Storage Engine
Module 7: Storage Engine
- Page layout: header, line pointers, tuples
- Heap files and TOAST (oversized attributes)
- Tuple structure: system columns, null bitmap, alignment
- Free Space Map (FSM) and Visibility Map (VM)
- Tablespaces and file organization
- Heap-only tuples (HOT) optimization
Module 8: Query Processing Pipeline
Module 8: Query Processing Pipeline
- Parser: lexical analysis, syntax tree
- Analyzer: semantic analysis, name resolution
- Rewriter: rule system, view expansion
- Planner: path generation, cost estimation, plan selection
- Executor: node types, pipeline execution
- Expression evaluation and JIT compilation
Module 9: PostgreSQL Architecture
Module 9: PostgreSQL Architecture
- Process model: postmaster, backends, auxiliary processes
- Shared memory architecture
- Buffer pool management and replacement algorithms
- WAL: structure, write-ahead logging protocol
- Checkpoint process and recovery
- Background writer and checkpointer
- Autovacuum subsystem
Advanced Internals Deep Dives
For engineers targeting staff+ roles or PostgreSQL contributions, these modules provide production-grade depth:Lock Manager Deep Dive
Buffer Manager Deep Dive
Memory Management
Catalog System
Extension Development
Source Code Navigation
Track 4: Production & Open Source
Real-world operations and contribution skills.Module 10: Replication & High Availability
Module 10: Replication & High Availability
- Physical replication: streaming, WAL shipping
- Replication slots and conflict handling
- Synchronous vs asynchronous trade-offs
- Logical replication: publications, subscriptions
- Failover automation: Patroni, repmgr
- Split-brain prevention
- Connection pooling: PgBouncer, Pgpool-II
Module 11: Scaling Strategies
Module 11: Scaling Strategies
- Vertical vs horizontal scaling decision framework
- Table partitioning: range, list, hash
- Partition pruning and constraint exclusion
- Sharding strategies and implementation patterns
- Citus for distributed PostgreSQL
- Read scaling with replicas
- Caching layers: application, Redis, pg_prewarm
- Multi-region architectures
Module 12: Operational Excellence
Module 12: Operational Excellence
- Monitoring: pg_stat_* views, pg_stat_statements
- Alerting strategies and runbooks
- Backup strategies: pg_dump, pg_basebackup, pgBackRest
- Point-in-time recovery (PITR)
- Upgrade strategies: pg_upgrade, logical replication
- Security: roles, RLS, SSL, audit logging
- Disaster recovery planning and testing
Module 13: PostgreSQL Source Code
Module 13: PostgreSQL Source Code
- Repository structure and build system
- Code style and conventions
- Key data structures: List, Node, Plan, Path
- Memory contexts and palloc
- Error handling and elog/ereport
- Catalog tables and system catalogs
- Extension API and hooks
- Reading existing patches
Module 14: Contributing to PostgreSQL
Module 14: Contributing to PostgreSQL
- Development workflow: mailing lists, commitfest
- Finding contribution opportunities
- Writing quality patches
- Documentation contributions
- Bug reporting and triage
- Code review process
- Community interaction etiquette
- Building your contributor reputation
Capstone: Senior Interview Preparation
Module 15: Senior Interview Mastery
Module 15: Senior Interview Mastery
- “Explain MVCC and its trade-offs”
- “How would you debug a slow query in production?”
- “Describe B-Tree internals”
- “What happens when you run a SELECT query?”
- Database selection for different use cases
- Scaling strategies and trade-offs
- Consistency vs availability decisions
- Data modeling for complex domains
- “Tell me about a database issue you solved”
- “How do you make decisions about denormalization?”
- “Describe a time you optimized a critical query”
Module 16: System Design Case Studies
Module 16: System Design Case Studies
- E-Commerce Platform: inventory, orders, payments
- Social Media Feed: fan-out, timeline assembly
- Real-Time Analytics: time-series, aggregations
- Multi-Tenant SaaS: isolation, noisy neighbor
- Event Sourcing System: append-only, projections
- Global Application: multi-region, conflict resolution
Learning Outcomes
After Completing This Course, You Will:
Senior-Level Technical Skills
Interview Confidence
OSS Contribution Ready
Who Should Take This Course?
| Profile | What You’ll Gain |
|---|---|
| Mid-Level Engineers | Skills to reach senior level |
| Senior Engineers | Depth for staff/principal roles |
| Backend Developers | Database expertise that stands out |
| Platform Engineers | Production PostgreSQL mastery |
| OSS Enthusiasts | Path to PostgreSQL contribution |
| Interview Candidates | Deep dive preparation |
Course Materials
Video Lessons
Hands-On Labs
Source Code Walkthroughs
Interview Question Bank
Cheat Sheets
Community Access
Start Your Journey
Track 1: Foundations
Track 3: Internals
Interview Deep-Dive
You are designing the data layer for a new product from scratch. Walk me through how you decide between PostgreSQL, MySQL, and a distributed NewSQL database like CockroachDB.
You are designing the data layer for a new product from scratch. Walk me through how you decide between PostgreSQL, MySQL, and a distributed NewSQL database like CockroachDB.
- The first question is the expected write throughput and data volume at maturity. If the dataset will comfortably fit on a single powerful node for the foreseeable future (say, under 2-5 TB with moderate write rates), PostgreSQL is almost always the right starting point. Its ecosystem, tooling, extension model (PostGIS, pg_trgm, pgvector), and MVCC implementation are battle-tested for OLTP workloads. MySQL is a reasonable alternative if the team already has deep MySQL operational expertise, but PostgreSQL wins on standards compliance, JSON support, and advanced features like partial indexes and CTEs.
- CockroachDB or similar distributed SQL enters the picture when you have a hard requirement for multi-region writes with strong consistency, or when your write volume will exceed what a single node can handle even after vertical scaling. The cost is real: higher write latency due to Raft consensus, operational complexity of a distributed cluster, and the inability to use many PostgreSQL-specific features.
- The decision framework I use: (1) Can a single PostgreSQL node handle this for the next 2-3 years? If yes, start there. (2) Do I need multi-region active-active writes? If yes, CockroachDB or Spanner. (3) Is this a read-heavy workload that can tolerate slight staleness? PostgreSQL with read replicas. The worst decision is premature distribution — you pay the complexity tax on day one but only need the scalability on day 500.
An interviewer asks: what are the most common mistakes you see teams make when they first adopt PostgreSQL for a production workload?
An interviewer asks: what are the most common mistakes you see teams make when they first adopt PostgreSQL for a production workload?
- Not tuning default configuration. PostgreSQL ships with conservative defaults designed to run on a Raspberry Pi. A team deploying on a 64GB server with default shared_buffers of 128MB is leaving 95% of their hardware on the table. At minimum, set shared_buffers to 25% of RAM, effective_cache_size to 75%, and random_page_cost to 1.1 for SSDs.
- Ignoring connection management. Each PostgreSQL connection spawns an OS process consuming 5-10MB. Teams running 500 direct connections from microservices will hit memory walls fast. PgBouncer in transaction mode should be deployed from day one.
- Not monitoring autovacuum. Teams assume it “just works” and then discover their 50GB table has bloated to 200GB because autovacuum could not keep up with the default scale factor of 0.2 on a high-churn table. Per-table autovacuum tuning is not optional for tables with heavy UPDATE/DELETE patterns.
- Treating PostgreSQL like an application datastore only. Teams miss that PostgreSQL is also a job queue (SELECT FOR UPDATE SKIP LOCKED), a pub/sub system (LISTEN/NOTIFY), and a full-text search engine (tsvector/tsquery). Using Redis or Elasticsearch for capabilities PostgreSQL already provides adds unnecessary infrastructure.
- Schema migrations without considering locks. Running ALTER TABLE ADD COLUMN with a DEFAULT on a 100M-row table in PostgreSQL versions before 11 would rewrite the entire table under an exclusive lock. Even in modern versions, adding a NOT NULL constraint without VALID requires a full table scan lock.
Explain the CAP theorem and why it matters for database selection in a system design interview.
Explain the CAP theorem and why it matters for database selection in a system design interview.
- The CAP theorem states that in the presence of a network partition, a distributed system must choose between consistency (every read returns the most recent write) and availability (every request receives a response). You cannot have both simultaneously when nodes cannot communicate.
- The practical implication is not really “pick 2 of 3” — network partitions are not optional, they will happen. So the real choice is CP (consistent but some requests fail during partition) versus AP (available but some reads may return stale data during partition).
- PostgreSQL with synchronous streaming replication is a CP system: during a network partition, the primary refuses to commit if the synchronous standby is unreachable, preserving consistency at the cost of availability. With asynchronous replication, it behaves more like a single-node system that is not distributed at all — the standby may lag, so reads from replicas are eventually consistent.
- CockroachDB and Spanner are CP: they will reject writes to ranges whose Raft groups cannot achieve quorum. Cassandra and DynamoDB are AP: they continue accepting writes during partitions and resolve conflicts later via last-write-wins or vector clocks.
- In system design interviews, I frame this as: “For financial data, I choose CP because showing stale account balances is unacceptable. For a social media feed, AP is fine because a user seeing a post 2 seconds late is tolerable, and feed unavailability is not.”