# Workflow: analytics offload to a read replica

## Goal
Production writes never wait behind a BI dashboard's full-table scan again.

## Steps
1. Create a read replica from the production branch (Console, CLI, or API). Note the Free plan caps at 3 replica computes per project.
2. Size the replica for analytics: analytics wants memory for sorts and aggregations, so do not default it to the smallest compute.
3. Give the BI tool and reporting jobs a dedicated role and the replica connection string as `REPLICA_URL`, separate from the app's `DATABASE_URL`.
4. Set statement timeouts on the analytics role so a runaway query dies instead of sitting on the replica forever.
5. Verify a write through the app while a heavy report runs: production latency should be unaffected.

## Ordering constraints
- Create the replica before pointing BI at it; BI tools cache connection info aggressively.
- Set the analytics role's permissions before handing over the string; the replica is read-only at the Postgres level anyway, which is your backstop.

## Traps
- Writing to the replica fails with read-only transaction errors: any ETL that writes must target the primary.
- Replica lag: for freshness-sensitive dashboards, check lag before trusting the numbers.
- The replica does not inherit the primary's autoscaling range; size and configure it deliberately.

## Verify
Heavy report running, production p99 unchanged, and a deliberate write to the replica string fails as expected (proving the split is real).