Skip to content
SeeItFlow
Interactive guide · 7 chapters · ~18 min read

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.

Mangesh MandlikLast updated: How lessons are made
01 · Design decision

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.)

02 · Trade-off

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.

03 · Comparison

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.

04 · Performance 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.

05 · Anti-patterns

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.

06 · FAQ

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.

07 · In practice

Real-world Architectures

A few architecture shapes recur across almost every serious Postgres deployment.

Key takeaways
  1. 01Primary + N read replicas behind a router, with Patroni/repmgr for automated failover.
  2. 02PgBouncer (transaction pooling) in front of every application tier, sized well under max_connections.
  3. 03Redis as a cache in front of hot read paths, with Postgres remaining the source of truth.
  4. 04Range partitioning by time for append-heavy event/log tables, with old partitions dropped or archived.
  5. 05pg_stat_statements + a dashboard (Datadog, Grafana) watching replication lag, connection count, and dead tuple ratios continuously.