New age of scaling

4. The primary database sets the scaling limit

ScaleArchitect · Scaling RCA · 19 October 2026 · 4 of 4

100 Role A + 600 Role B baseline · 150 + 1,000 step-up · shared-database RCA

Test window: 14–19 October 2026 · All times UTC · Root causes, proposed fixes and the next scaling gate

Scaling decision

HOLD · Combined journey fails at step-up The query changes give the baseline more headroom. At 150 Role A + 1,000 Role B users, however, the primary reaches 100%, requests occupy the full app tier, and the Role B item submission does not complete. The mostly idle replica is not sharing that demand.

Next move: Correct read routing and share repeated polling answers. Remove filter-click amplification. Retest the complete journey at the same load before making any capacity claim.

Primary / replica CPU peak
100% / 7.8%
Afternoon step-up · peaks, not simultaneous values
Role A browser p95
14.62 s
1.62 s at the lower combined load
Origin 429 responses
1,689
1,524 Role A + 165 Role B; also one 504

What the current changes achieve

The same nominal baseline now uses less database CPU

100 Role A + 600 Role B · 14 Oct vs 19 Oct morning. Several code/configuration changes coexist, including replica sizing; this is not a one-change causal benchmark. Do not add peak percentages across machines.

Change in the tested revisionCurrent effectRemaining issue
Info-poll aggregates consolidatedFewer heavy queries per callAnswers are still recomputed per user
Duplicate mentions timer removed; query boundedFewer and cheaper pollsOther polling still amplifies requests
Status-bar reads route to the primaryReplica pressure fallsPrimary carries the remaining read bottleneck
Message polling avoids unconditional writesFewer locking writesShared DB remains a limit

The improvement is real at the measured baseline; its exact split between rewrites, collation and other changes is not isolated. Lower-load success is not acceptance of the larger combined journey.

Where the larger combined step breaks

Measure · 19 Oct100 + 600 users150 + 1,000 users
Primary CPU peak46.3%100%
Primary connections peak89723
Role A browser p951.62 s14.62 s
Role B browser p951.08 s14.17 s
Origin 429 · Role A / Role B0 / 01524 / 165
Origin 5xx · both apps01 · HTTP 504
Role A page-aborted calls1,5088,077
The primary saturates while the replica stays lightly used

19 Oct step-up · UTC minute starts. Monitoring samples are aligned back one minute, matching the source alignment. The 95% line is a proposed future stop rule, not an enforced stop in this run.

Both applications wait on the shared constraint

19 Oct step-up · Cloud Run per-minute p95 of dynamic calls. Not the whole-run browser p95 in the table above. E14.

Root causes and proposed fixes

F10

Repeated read work saturates the primary and fills app concurrency

P0 · Scaling blocker
Owner Backend + database engineerConfidence Metrics + query mix + recoveryEvidence E14

Impact. Requests wait rather than compute. All ten Role A instances hit their 100-request caps, origin refusals appear, and Role B slows on the same shared database. Adding more waiting app requests is not the first fix.

Root cause

Read-only status counts now open a primary connection before replica routing can run. Identical per-scope polling answers are also rebuilt for each user. The remaining hot query families dominate sampled execution time on the primary.

Evidence

The primary peaks at 723 connections; Role A app CPU stays at or below 22%. Query Insights execution-time shares are info-poll CTE 39.7%, status counts 25.6% and chat aggregation 18.9%—84.2% together, not a CPU allocation. When Role A finishes, primary utilization drops to about 52% and then 17% while Role B continues: this supports the shared-DB diagnosis.

Proposed fix

First: route read-only polling that is safe to offload through the replica connection before the primary-first authorization include locks in the connection choice. Next: cache repeated answers for a short, agreed freshness window, keyed by every scope and permission dimension. Keep writes and read-after-write-sensitive operations on a consistency-safe path.

Database routing · proposed connection order

Adapted, redacted excerpt · application names, fields, paths and response labels are illustrative aliases.

- summary_counts.php opens session_bootstrap.php first; primary connection is selected
- Later openReadConnection path does not run
+ Select the read-replica path before primary-first connection setup
+ Keep authorization checks intact and writes on the primary
+ Define a safe fallback for lag or replica unavailability

Connection-order specification from the code review in E14. Review connection side effects and consistency before implementation.

Shared polling answers · proposed cache contract

Adapted, redacted excerpt · application names, fields, paths and response labels are illustrative aliases.

- Every user recomputes the same counts every poll
+ Cache key = assigned resource scope + complete access-scope predicate + permissions
+ Cache lifetime = agreed 5–10 second freshness window
+ On a hit, return the same authorized response contract

Proposed cache behavior, not a measured gain. Include every result-changing input; bound stale data and avoid a cache-miss stampede.

Risk and rollout

A missing permission dimension can expose the wrong counts. Replica lag can violate read-after-write expectations. Per-instance APCu does not imply one shared result across all instances; choose cache scope explicitly.

Retest and acceptance

Compare authorized results with uncached primary responses, including permission changes and replica lag. Repeat 100 + 600, then the identical 150 + 1,000 journey with one change at a time. Require completed actions, agreed p95 and zero refusals; set DB stop conditions before starting.

F11

A single filter action fans out into repeated refreshes

P1 · Small change, large leverage
Owner Frontend developerConfidence Action timing + request burstsEvidence E14

Impact. A normal user action adds a request storm when the database is already saturated. Browser aborts waste work and obscure the user-visible tail.

Root cause

resetAllFilters triggers about 13 refresh pairs per page instead of applying one state transition and issuing one refresh. Periodic requests continue overlapping slow responses.

Evidence

At the burst, 144 users click; Role A browsers issue 774 requests in one second. Role A browsers abort 8,077 requests across the run, including 4,783 in the 12:22 UTC minute. Origin logs record 1,120 refusals in the second wave. These are different scopes: 774 is browser-issued, not the origin peak, and the clear-filters action amplifies saturation rather than starting it.

Proposed fix

Update all filter state without triggering individual refresh handlers, then refresh once. Debounce text input. Permit only one periodic poll in flight, with bounded backoff when the server is slow.

Filter update · proposed behavior

Adapted, redacted excerpt · application names, fields, paths and response labels are illustrative aliases.

- Clear each filter and let each handler refresh both panels
+ Suppress per-field refresh during one clear-all transaction
+ Apply the final filter state once
+ Issue one coordinated refresh
+ Ignore stale replies; skip overlapping periodic polls

Behavioral diff for resetAllFilters and refresh ownership. Preserve deliberate user actions and error recovery.

Risk and rollout

Avoid intermediate or stale filter results, duplicate event bindings, and flags that remain set after errors. Backoff must not silently stop intentional refresh or hide an error.

Retest and acceptance

One click produces one coordinated refresh. Repeat the synchronized click at the same load and compare requests per action, aborts, origin refusals and correct UI state. Do not claim the fix eliminates DB saturation until the retest proves it.

F12

The item-submission journey fails before the load plan completes

P0 · Acceptance failure
Owner Test owner + application teamConfidence Step logs + action recordsEvidence E14

Impact. The test cannot certify 1,150 successful users. The application keeps responding and recovers, but the intended business writes and later synchronized actions do not occur.

Root cause

At baseline, re-seeded categories no longer match the recording. At step-up, the submission screen takes about 13.5 seconds against a roughly 10-second step wait; item submission fails and later load is no longer the intended profile.

Evidence

Neither run records item submission. The baseline obstruction is recording/data alignment; the step-up obstruction is the slow report flow. Automatic recovery and zero baseline origin 5xx/429 do not close these journey failures. Other cancelled or dropped calls remain visible.

Proposed fix

Retarget the recording to the current seeded categories, then retain a meaningful user wait budget. Resolve the slow path rather than merely extending the timeout. Gate success on action records and returned business state, not on scripts reaching their final instruction.

Run acceptance · proposed contract

Adapted, redacted excerpt · application names, fields, paths and response labels are illustrative aliases.

- All scripts finish or keep receiving HTTP responses
+ Report planned, started, reached-action and completed users separately
+ Confirm each expected business write and resulting state
+ Report failed steps and missing later synchronization releases
+ Require the agreed latency budget at the full combined load

Acceptance specification; no extra reports are assumed submitted and no unobserved after-fix run is claimed.

Risk and rollout

Changing waits can change concurrency and hide the original failure. Keep scenario, data and user pace stable between comparable runs; record any necessary recording correction.

Retest and acceptance

Run the complete corrected baseline, then step up with both applications. Count expected versus submitted items and verify their state. Only a successful same-load journey can support the next capacity decision.

The next scaling iteration

OrderOwnerChangeExit criterion
1 · P0Test + appCorrect recording alignment; preserve meaningful wait budgetExpected writes and full journey are measurable
2 · P1FrontendOne filter refresh; one periodic request in flightRequests/action and aborts fall; UI stays correct
3 · P1Backend + DBSafe replica routing, then permission-scoped cacheCorrect results; DB headroom at the same load
4 · P0 gateTest ownerRepeat baseline, then 150 + 1,000 step-upComplete actions; agreed p95; zero refusals

Do not buy the next limit blindly

The baseline improvements justify another controlled iteration—not a capacity certificate. Remove repeated work and route reads safely, then let the next full-journey result decide whether infrastructure scaling is necessary.