Skip to content

All articles

PostgreSQL & Performance · Updated 1 min read138 wordsby Callum Reid

PostgreSQL Indexing Patterns That Cut API Latency by 80%

Before adding caching clusters or read replicas, three pragmatic relational indexing and query-shaping techniques resolve most production bottlenecks.

Share this article
LinkedInX / Twitter
PostgreSQL Indexing Patterns That Cut API Latency by 80%

When REST API endpoints slow down under growing datasets, teams often reach immediately for distributed caches. Yet in nine out of ten audits we conduct for UK businesses, the root cause lies in missing composite indexes or unpaginated ORM queries.

First, align B-tree indexes with real filter and sort predicates—for example, indexing (status, publish_date DESC) on editorial tables or (featured, display_order) on project showcases:

sql
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_blog_posts_status_publish_date
  ON blog_posts (status, publish_date DESC);

Second, project only the columns required for list views rather than transferring full article bodies over the wire. Finally, use EXPLAIN ANALYZE against realistic row counts during development:

sql
EXPLAIN (ANALYZE, BUFFERS)
SELECT id, title, slug, excerpt, publish_date
FROM blog_posts
WHERE status = 'published'
ORDER BY publish_date DESC
LIMIT 12;

Clean relational queries routinely respond in under 15 milliseconds without adding a single extra server to your infrastructure.

Keep reading

More engineering notes from overlapping topics.

View all articles

Planning a new web platform or legacy migration?

Speak directly with a senior UK engineer. Share your requirements and receive a pragmatic scope, architecture outline, and timeline.

Schedule Discovery Call