Stage 4 · Provision
Database Scaling Strategies
Polyglot Persistence
Choosing the right database for each access pattern — relational, document, graph, and time-series.
What Is Polyglot Persistence?
Polyglot persistence means using different data stores for different data access patterns. Instead of forcing everything into a single relational database, you use the best tool for each job: PostgreSQL for transactions, Redis for caching, Elasticsearch for search, Neo4j for relationships.
Database Types
| Type | Examples | Best For |
|---|---|---|
| Relational | PostgreSQL, MySQL | ACID transactions, joins, structured data |
| Document | MongoDB, Couchbase | Flexible schemas, nested objects |
| Key-Value | Redis, DynamoDB | High-throughput, simple lookups |
| Search | Elasticsearch, Meilisearch | Full-text search, faceted queries |
| Graph | Neo4j, Amazon Neptune | Relationship traversal, recommendations |
| Time-Series | InfluxDB, TimescaleDB | Metrics, IoT, time-stamped data |
| Column-Family | Cassandra, HBase | Write-heavy, wide rows, time-series |
Choosing the Right Database
Service: E-commerce Platform
User profiles → PostgreSQL (ACID, complex queries)
Product catalog → MongoDB (flexible schemas)
Session store → Redis (fast reads, TTL)
Search → Elasticsearch (full-text, facets)
Recommendations → Neo4j (graph traversal)
Order history → PostgreSQL (transactions)
Click stream → Kafka → InfluxDB (time-series)
Product images → S3 + CloudFront (blob + CDN)Each data access pattern maps to the most appropriate database. The user service uses PostgreSQL for transactions, while the search service uses Elasticsearch for full-text queries.
Keeping Data in Sync
The hardest part of polyglot persistence is keeping data consistent across multiple databases. CDC (Change Data Capture) with tools like Debezium streams changes from PostgreSQL to Kafka, which can then feed Elasticsearch, Redis, and other stores.
PostgreSQL → Debezium CDC → Kafka
│
┌───────────┼───────────┐
│ │ │
Elasticsearch Redis Cache Analytics
(search index) (hot data) (data warehouse)The source of truth is PostgreSQL. CDC captures every change and streams it to Kafka. Downstream consumers update their respective stores. This ensures eventual consistency across all systems.
The Complexity Cost
- More operational overhead — Each database has its own monitoring, backups, and upgrades.
- Data consistency challenges — Ensuring consistency across stores requires careful design.
- Team expertise — Engineers must learn multiple database systems.
- Cross-store queries — Joining data across databases requires application-level joins.
Start with PostgreSQL. Add other databases only when you have a clear access pattern that PostgreSQL cannot handle efficiently. Every new database is a new operational burden.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.