Problem Statement
A single PostgreSQL instance handles all reads and writes. There is no read replica support, meaning read scalability is limited and there is a single point of failure for all database operations.
Evidence
Backend/src/database/database.module.ts — Single TypeORM datasource
infrastructure/terraform/rds.tf — Single db.t3.medium instance
Impact
No read scalability. Single point of failure for all database operations. Read-heavy workloads (gist listing) compete with writes (new gists) on the same instance.
Proposed Solution
- Configure read replica in Terraform (add read replica instances)
- Configure TypeORM read/write replication:
replication: { master, slaves: [] }
- Route read queries (findNearby, findByGistId) to replica(s)
- Route write queries (create) to master
- Handle replica lag with staleness tolerance configuration
Technical Requirements
- Must use TypeORM's built-in replication support
- Must handle replica lag gracefully (eventual consistency for reads)
- Must fall back to master if replicas are unavailable
- Terraform must create replica(s) with matching instance class
Acceptance Criteria
- Terraform creates read replica instance(s)
- TypeORM configured with master and slave(s)
- CREATE operations go to master
- SELECT operations go to replica(s)
- Replica failure falls back to master transparently
- Replica lag is monitored and reported
- All existing tests pass
File Inventory
infrastructure/terraform/rds.tf
Backend/src/database/database.module.ts
Backend/src/database/data-source.ts
Dependencies
None.
Testing Strategy
- Integration test: verify reads go to replica, writes to master
- Failover test: stop replica, verify reads fall back to master
- Performance test: compare read throughput with and without replicas
Security Considerations
Replicas must have the same security group restrictions as master. Data at rest encryption must apply to replicas.
Definition of Done
Problem Statement
A single PostgreSQL instance handles all reads and writes. There is no read replica support, meaning read scalability is limited and there is a single point of failure for all database operations.
Evidence
Backend/src/database/database.module.ts— Single TypeORM datasourceinfrastructure/terraform/rds.tf— Single db.t3.medium instanceImpact
No read scalability. Single point of failure for all database operations. Read-heavy workloads (gist listing) compete with writes (new gists) on the same instance.
Proposed Solution
replication: { master, slaves: [] }Technical Requirements
Acceptance Criteria
File Inventory
infrastructure/terraform/rds.tfBackend/src/database/database.module.tsBackend/src/database/data-source.tsDependencies
None.
Testing Strategy
Security Considerations
Replicas must have the same security group restrictions as master. Data at rest encryption must apply to replicas.
Definition of Done