PostgreSQL Engineering Insights
Postgres's strict schema and MVCC model trade write-time flexibility for read-time guarantees — a trade-off that shows up directly in migration strategy, lock behavior, and vacuum tuning. This section covers the design decisions, trade-offs, and mistakes that come up most often once a Postgres schema has to survive real traffic.
Why PostgreSQL Uses MVCC
The alternative to MVCC is lock-based concurrency — readers and writers taking turns. Postgres chose to never make an ordinary reader wait on a writer.
A lock-based database can serialize readers behind writers (or vice versa), which collapses throughput under mixed read/write load. Postgres' designers instead chose to let every transaction see a private, consistent snapshot of the database — an ordinary SELECT never blocks writers and writers never block it. (Locking reads such as SELECT FOR UPDATE, and DDL that needs an ACCESS EXCLUSIVE lock, still participate in normal lock conflicts — see Fundamentals, Chapter 8.)
PostgreSQL Index Types and Their Trade-offs
Every index is a bet: faster reads on some queries, in exchange for slower writes on every insert/update/delete that touches the indexed columns.
PostgreSQL ships several index types: B-tree (the default, for equality and range queries), Hash (equality only), GiST and SP-GiST (geometric and other specialized data), GIN (multi-valued data such as jsonb and arrays), and BRIN (compact indexes for very large, naturally ordered tables). Whichever type you pick, the trade-off below is the same.
A table with 15 indexes might serve reads beautifully but grind writes to a halt, because every INSERT has to update 15 separate B-Trees. The right number of indexes is the smallest set that covers your actual query patterns — not the union of every column someone might filter on someday.
PostgreSQL vs MySQL
Both are mature, open-source, ACID-compliant relational databases — the differences show up in extensibility, standards compliance, and default storage engine behavior.
Extensibility
Postgres supports custom types, operators, and extensions (PostGIS, pgvector, TimescaleDB) as first-class citizens. MySQL's plugin architecture is more limited by comparison.
Standards compliance
Postgres tracks the SQL standard more closely — window functions, CTEs, and full outer joins arrived earlier and more completely than in MySQL.
Storage engines
MySQL historically offered pluggable storage engines (InnoDB, MyISAM); Postgres has one, deeply integrated storage layer, which simplifies operations at the cost of that flexibility.
Replication
Both support async and sync replication; MySQL's ecosystem (Group Replication, Galera) leans more toward multi-primary setups than Postgres' primary/replica model.
Read vs Write Performance
Reads and writes pull a Postgres schema in opposite directions — indexes, denormalization, and caching all trade one for the other.
A read-heavy workload wants more indexes, more denormalized/materialized data, and read replicas. A write-heavy workload wants fewer indexes, more normalized data (less to keep in sync), and careful autovacuum tuning. Most real systems are a mix, which is why schema and index decisions should be driven by measured query patterns, not a-priori guesses.
Common Mistakes
The same handful of mistakes account for most avoidable Postgres pain.
SELECT * in production code
Fetches columns you don't need, defeats index-only scans, and breaks silently when someone adds a column.
No connection pooling
Every app instance opening its own pool of raw connections exhausts max_connections far sooner than expected.
Ignoring autovacuum tuning on hot tables
Default thresholds are fine for most tables and wrong for your busiest one.
Storing large blobs inline
Large JSON/text values bloat pages and slow down every scan of a table, even for queries that don't need that column — use TOAST-friendly design or a separate table.
Frequently Asked Questions
Does Postgres support JSON?
Yes — jsonb is a first-class binary JSON type with indexing (GIN) support, letting you mix relational and document-style data in one database.
Can Postgres scale horizontally?
Not natively for writes — a single primary accepts all writes. Horizontal write scaling requires sharding (e.g. Citus) or partitioning + application-level routing.
Is Postgres good for time-series data?
With extensions like TimescaleDB, yes — but vanilla Postgres with range partitioning by time handles moderate time-series workloads well too.
Real-world Architectures
A few architecture shapes recur across almost every serious Postgres deployment.
- 01Primary + N read replicas behind a router, with Patroni/repmgr for automated failover.
- 02PgBouncer (transaction pooling) in front of every application tier, sized well under max_connections.
- 03Redis as a cache in front of hot read paths, with Postgres remaining the source of truth.
- 04Range partitioning by time for append-heavy event/log tables, with old partitions dropped or archived.
- 05pg_stat_statements + a dashboard (Datadog, Grafana) watching replication lag, connection count, and dead tuple ratios continuously.