Backendcore
Database indexing
B-tree for equality and ranges, GIN for full-text and JSON, HNSW/IVFFlat for vectors — and EXPLAIN to check.
What it is and why it exists
Indexes trade write cost and storage for fast reads. B-tree serves =, <, >, ORDER BY and prefix matches on the leading columns; composite index order matters; GIN serves full-text, arrays and JSONB containment; vector indexes serve nearest-neighbour. EXPLAIN (ANALYZE) shows whether the planner uses them.
Quick prototype
No indexes until it’s slow.
In production, at scale
Indexes designed from the query patterns (tenant_id first in composite indexes), partial and covering indexes, EXPLAIN ANALYZE on slow queries, monitoring of unused indexes and bloat, and CONCURRENTLY for index builds on live tables.
Vendors and tools
| Postgres EXPLAIN / pg_stat_statements | Query analysis |
|---|---|
| pganalyze / Datadog DBM | Index advice |
On AWS: RDS Performance Insights; Aurora query plan management.
How it fails
- Index on (created_at, tenant_id) when every query filters on tenant_id first
- Function on the column (lower(email)) bypassing the index
What the interviewer asks next
Why doesn’t Postgres use my index?
The query doesn’t match the leading columns, wraps the column in a function, the table is small or the condition matches most rows (seq scan is cheaper), or statistics are stale.