Why PostgreSQL
This is the least controversial choice in the stack and the most consequential. PostgreSQL keeps making other infrastructure unnecessary — and every piece of infrastructure you do not run is one you never have to operate, secure, back up or explain.
1 · Correctness is the default
Databases differ most in what they do when you make a mistake. PostgreSQL's answer is consistently "refuse".
| Situation | PostgreSQL | MySQL (historically) |
|---|---|---|
| String too long for the column | Error | Truncated silently in non-strict mode |
Invalid date such as 0000-00-00 | Rejected | Accepted |
| DDL inside a transaction | Transactional — a failed migration rolls back | Implicit commit |
| Check constraints | Enforced since forever | Ignored before 8.0.16 |
| Standards compliance | Very high | Improving |
A migration that adds three columns and fails on the third leaves the database exactly as it was. On engines without it you get a half-applied schema at 3 a.m. and a manual repair.
2 · One engine instead of five services
| Requirement | The usual extra service | PostgreSQL feature |
|---|---|---|
| Document / schemaless data | MongoDB | JSONB with GIN indexes |
| Full-text search | Elasticsearch | tsvector + GIN, pg_trgm for fuzzy |
| Job queue | RabbitMQ, SQS | SELECT … FOR UPDATE SKIP LOCKED |
| Geospatial | A dedicated GIS store | PostGIS — the industry standard |
| Time series | InfluxDB | Partitioning, or TimescaleDB |
| Vector / embeddings | Pinecone, Weaviate | pgvector |
| Caching | Redis | UNLOGGED tables (for many cases) |
At sufficient scale a specialised system wins — Elasticsearch really is better at search relevance, Kafka really is a better log. The point is that PostgreSQL takes you much further than people expect, and the second system you add doubles your operational surface: another deployment, another backup policy, another failure mode, another consistency boundary.
-- each worker claims a distinct batch; no broker required
UPDATE outbox_event
SET published_at = now()
WHERE event_id IN (
SELECT event_id
FROM outbox_event
WHERE published_at IS NULL
ORDER BY event_id
FOR UPDATE SKIP LOCKED
LIMIT 100
)
RETURNING event_id, aggregate_id, type, payload;
3 · JSONB is a real data type, not a text column
ALTER TABLE customer_order ADD COLUMN metadata jsonb NOT NULL DEFAULT '{}';
CREATE INDEX idx_order_metadata ON customer_order USING gin (metadata);
-- containment, index-accelerated
SELECT * FROM customer_order
WHERE metadata @> '{"channel": "mobile", "giftWrap": true}';
-- extract a typed value
SELECT reference, (metadata ->> 'campaign') AS campaign
FROM customer_order
WHERE metadata ? 'campaign';
-- you can still enforce rules on it
ALTER TABLE customer_order ADD CONSTRAINT metadata_channel_valid
CHECK (metadata ->> 'channel' IN ('web', 'mobile', 'phone', 'partner'));
This is the pragmatic middle ground: a strict relational core for the parts of the domain you understand, and a flexible column for the parts that vary per customer — without running a second database.
4 · Analytics without an export
WITH monthly AS (
SELECT date_trunc('month', placed_at) AS month,
customer_id,
sum(total_amount) AS revenue,
count(*) FILTER (WHERE status = 'CANCELLED') AS cancellations
FROM customer_order
GROUP BY 1, 2
)
SELECT month,
customer_id,
revenue,
lag(revenue) OVER w AS previous_month,
revenue - lag(revenue) OVER w AS delta,
rank() OVER (PARTITION BY month ORDER BY revenue DESC) AS rank_in_month
FROM monthly
WINDOW w AS (PARTITION BY customer_id ORDER BY month)
ORDER BY month DESC, rank_in_month;
Most "we need a data warehouse" requirements at small and medium scale are a handful of queries like this one plus a materialised view refreshed nightly.
5 · Extensions
CREATE EXTENSION pg_stat_statements; -- which queries actually cost you time CREATE EXTENSION pg_trgm; -- fuzzy / typo-tolerant search CREATE EXTENSION citext; -- case-insensitive text, e.g. email CREATE EXTENSION uuid-ossp; -- UUID generation CREATE EXTENSION postgis; -- geospatial CREATE EXTENSION vector; -- embeddings for AI features CREATE EXTENSION pgcrypto; -- hashing and encryption in the database
pg_stat_statements alone is worth the paragraph: it ranks every query by total
time, calls and rows, which turns "the app feels slow" into a sorted list.
6 · The licence and the ecosystem
- PostgreSQL Licence — permissive, BSD-like. No open-core, no relicensing risk, no vendor able to change the terms.
- Managed everywhere — RDS and Aurora, Cloud SQL and AlloyDB, Azure Database, Neon, Supabase, Crunchy. Migration between them is realistic because they are all Postgres.
- Predictable releases — one major version a year, five years of support each.
- No single owner — a global development group, not one company's roadmap.
What it costs
| Cost | Reality |
|---|---|
| Connections are processes (~10 MB each) | Real. Use HikariCP, and PgBouncer above a few hundred connections. |
| Vacuum needs attention | Autovacuum handles most cases; long transactions cause bloat. |
| Some DDL takes locks | Modern versions avoid most rewrites; use CREATE INDEX CONCURRENTLY. |
| No built-in multi-master | Correct — that is usually a feature. Patroni or a managed service for HA. |
| Defaults are conservative | shared_buffers and work_mem need tuning; managed services do it for you. |
A team wants to add MongoDB for a flexible per-customer attributes field. What is usually the better first move?
JSONB gives document flexibility with indexing, containment queries and the option of constraints — inside the transaction that already protects the rest of the order. A second database means a second backup policy, a second failure mode and no cross-store transactions.