Database Architecture
Overview
Database architecture decisions strongly influence system scalability, consistency, and failure behavior.
Common Patterns
- Single primary with read replicas
- Sharding by tenant or key range
- Polyglot persistence by workload type
- Event sourcing with append-only logs
flowchart LR
A[Application] --> P[(Primary DB)]
P --> R1[(Read Replica 1)]
P --> R2[(Read Replica 2)]
Production Example
A reporting-heavy SaaS platform routes writes to a primary PostgreSQL node and read traffic to replicas. A cache layer protects frequent dashboard queries.
-- Read request routed to replica
SELECT customer_id, monthly_spend
FROM billing_summary
WHERE month = '2026-08'
ORDER BY monthly_spend DESC
LIMIT 100;
Design Considerations
- Consistency requirement per use case
- Recovery objectives (RPO and RTO)
- Data retention and archival policy
- Migration and schema evolution strategy
Common Pitfalls
- Treating all workloads with one storage model
- Ignoring replication lag in read-after-write flows
- Missing backup restoration drills
Key Takeaways
- Database architecture must match workload patterns.
- Read/write separation improves scale for read-heavy systems.
- Recovery planning is as important as schema design.