#🧱 Building Block: PostgreSQL
#Overview
PostgreSQL is a powerful, open-source object-relational database system. It has a strong reputation for reliability, feature robustness, and performance.
#Key Concepts
- ACID Compliance: Ensures that all database transactions are processed reliably.
- JSONB: Binary JSON storage that allows for efficient indexing and querying of semi-structured data.
- Replication: Supports streaming replication for high availability and read scaling.
- Extensions: Rich ecosystem including
PostGIS(geospatial),pg_trgm(fuzzy search), etc.
#When to Use
- Structured Data: When you need a solid relational schema with strong consistency guarantees.
- Complex Queries: When you need powerful JOINs and analytical functions.
- Hybrid Data: When you have a mix of structured and semi-structured (JSON) data.
#Scaling Strategies
- Vertical Scaling: Increasing CPU/RAM of the primary node.
- Read Replicas: Offloading read traffic to secondary nodes.
- Sharding: Using tools like
Citusor application-level sharding to distribute data across multiple primary nodes.
#Trade-offs
- Pros: Mature, extremely reliable, rich feature set, standards-compliant.
- Cons: Horizontal scaling for writes is complex and requires third-party tools or manual sharding.