When a database does too much: Reflecting on PostgreSQL’s hidden capabilities
Kowshiq Kattamuri
Advanced App Engineer, Accenture
Author | YouTuber | Tutor
Advanced App Engineer, Accenture
Built fully on PostgreSQL
Core of product architecture
Initially monolithic, then sharded across instances
The Polyglot Problem
Complexity and Cost
PostgreSQL for core data
Redis or Memcached for caching
RabittMQ or Kafka for job queues
Elasticsearch for search
Kafka
Topics, partitions, replication factor, retention policies, consumer groups, maybe schema registry
Redis
Lists/BRPOP or streams/XADD/XREAD, stream groups, persistence config (AOF/RDB), eviction policy
RabbitMQ
Exchanges, queues, bindings, dead-letter queues, delayed-retry plugin
Conventional way
Options to consider when you are processing tens of thousands of events/sec
Postgres as Queue
Postgres as Queue
Creating Indexes
Postgres as Queue
Enqueue + wake workers (atomic + instant)
Postgres as Queue
Worker: claim with SKIP LOCKED (no double work), then process
Postgres as Queue
Finish job or retry with backoff
The big process
vs
Postgres
way
A poor man’s perspective
Amazon Dynamo DB
Plan partition keys and sort keys, manage provisioned vs. on-demand capacity, handle global/local secondary indexes,
Redis
Set up the server, manage persistence (RDB or AOF), configure clustering/replication for fault tolerance
Memcached
Configure the daemon, decide on memory allocation, and ensure consistent hashing
Conventional way
Options to consider when ultra-low latency and high throughput at massive scale are critical.
Postgres as Cache
Creating a lightning fast cache table
Postgres as Cache
Insert and fetch with SQL
Postgres as Cache
Emulating TTL
The big process
vs
Postgres
way
A poor man’s perspective
Apache Solr
Dedicated search server with configs, schema tuning, and monitoring overhead.
Algolia
Managed service but adds cost, vendor lock-in, and data sync maintenance.
Elasticsearch
Requires setting up separate clusters, managing nodes, and syncing data from DB.
Conventional way
Options to consider when ultra fast, web-scale, search-tuned infrastructure is needed.
Postgres for full text search
Searching for JPMorgan Chase using a query like jp
Postgres for full text search
For efficiency during lookups
Postgres for full text search
Optimizing Further
Postgres for full text search
Full text search
Postgres for full text search
Optimized full text search
The big process
vs
Postgres
way
A poor man’s perspective
Real time features
Pusher
Integrate SDKs, manage channels/events, and pay recurring SaaS fees for scale.
Apache Kafka
Set up clusters, brokers, topics, and a separate pipeline just to stream events.
Firebase Realtime Database
Spin up a separate cloud service, sync app with it, and depend on vendor infra.
Conventional way
Options to consider when live updates need to be handled outside the database.
Postgres for real time updates
Setting up PostgreSQL Triggers
Listening for notifications
The big process
vs
Postgres
way
A poor man’s perspective
Development Complexity
Different client libraries and connection patterns
Coordinating deployments across multiple services
Operational Overhead
Different services to monitor, update, and debug
Different scaling patterns and failure modes
Multiple configurations to maintain
Separate backup and disaster recovery procedures
Inconsistent data between systems
Different performance tuning approaches
Let’s do some Math
20 $ PM
Redis
Message queue
25 $ PM
Search service
50 $ PM
Monitoring for 3 services
30 $ PM
Grand Total
125 $ PM
The Single Database That Scales
Single Postgres cluster handling millions of bookings
With more than 10 million users uses PostgreSQL in its data lake.
Entire DevOps platform on Postgres
The magic is in Postgres's architecture
Proven options for horizontal scaling
Read replicas for query scaling
Partitioning for large tables
Connection pooling for concurrency
Logical replication for distributed setups
Here are some of the best articles and posts on PostgreSQL that I found in my search.
Postgres might be too good for its own good.
Thank you all for being such a fantastic audience!!!
My Linktree QR code