Problem
POST /v1/gs/db serves the sheet-export tooling (~100 distinct consumers, identified via the identifier field in the slow-query logs). The syncs run on timed triggers around the clock against PRD, and their query shape makes them far heavier than they need to be:
- 10,754 queries >3s in the last 7 days (~1,500/day), runtimes up to 12.6s, PRD only.
- Every observed sync passes
updatedSince: 1970-01-01 — the DTO's incremental capability is unused, so each run re-scans from epoch with joins and DESC sorts (maxLine 100–500 + multi-table joins).
- Requests up to 8 MB response size were observed; one query ran 98s.
Impact
- Ingress errors: exports that outlive the origin's patience die mid-flight and surface as 502/EOF at the edge (tracked infra-side in DFXServer/server#744, which asks for this exact follow-up triage).
- Process stalls: of 4 clean (non-deploy) container restarts checked, 2 were preceded by a ~5x burst of slow
/gs/db queries in the prior 10 minutes (27 resp. 25 vs ~5 baseline). Contributing stressor — not proven sole cause.
- Steady DB load on the serving path for reporting reads.
Fix options (not mutually exclusive)
- Consumer-side (biggest win, no API change): make the sheet syncs pass a real
updatedSince so pulls are incremental. Needs an owner for the sheet scripts + a doc note in the GS module.
- Server-side guardrails: limit concurrent
/gs/db exports (queue, e.g. 2 in flight), and/or per-identifier rate limit; consider a hard runtime cap with a clear 429/503 so a heavy query fails fast instead of stalling the process.
- Structural: serve GS reads from a read replica so reporting load cannot touch the serving path.
Acceptance
Problem
POST /v1/gs/dbserves the sheet-export tooling (~100 distinct consumers, identified via theidentifierfield in the slow-query logs). The syncs run on timed triggers around the clock against PRD, and their query shape makes them far heavier than they need to be:updatedSince: 1970-01-01— the DTO's incremental capability is unused, so each run re-scans from epoch with joins and DESC sorts (maxLine100–500 + multi-table joins).Impact
/gs/dbqueries in the prior 10 minutes (27 resp. 25 vs ~5 baseline). Contributing stressor — not proven sole cause.Fix options (not mutually exclusive)
updatedSinceso pulls are incremental. Needs an owner for the sheet scripts + a doc note in the GS module./gs/dbexports (queue, e.g. 2 in flight), and/or per-identifierrate limit; consider a hard runtime cap with a clear 429/503 so a heavy query fails fast instead of stalling the process.Acceptance
/v1/gs/dbreduced by an order of magnitude (baseline: ~1,500/day)./gs/db-attributable ingress EOF/502s in the edge logs (verification via DFXServer/server#744).