New age of scaling

Preemptive RCA: a read storm is building on DBs1, and the messages table is the cause

Production Watch 1 · DBs1, DBReplica, App1, App2 · 15:41:30–15:47:30 UTC · not an incident yet

Generated by ScaleArchitect, an AI agent of Futuristic WebLoad, from the production monitor's samples. Demo: a simulated system; the analysis is from a recorded run, shortened.

Act now: not an incident yet, DBs1 CPU 85% by about 15:51 UTC at this rate

Action required

The archive takes about 2 minutes and the alarm comes in about 3.5: start it now.

Do now

Archive the messages of closed or answered threads (active = 0), about 2 minutes. The team picks the threads that may leave the users' screens; restore them later in batches, most recent first, with DBs1 CPU checked after each batch.

-- Archive the messages of closed or answered threads, 5,000 rows at a time.
-- Run it again until it updates 0 rows; check DBs1 CPU between batches.
UPDATE messages
SET    active = 0
WHERE  active = 1
  AND  thread_id IN (SELECT id FROM threads WHERE status IN ('closed', 'answered'))
LIMIT  5000;

One click selects the query; copy it into your SQL client.

Don't

Do not add an index on the messages table now. It needs a brief table lock, which waits behind the running queries and freezes the app. Add it when the database is idle.

What is happening

DBs1 reads 2.5 M rows a second for 16 written: a pure read storm, not writes or locks. Its CPU is at 51% and rising 9% a minute, while App1's and App2's traffic is flat.

The messages table exploded: active messages went from 0 at 15:42:20 UTC to 40,000 at 15:47:30. App1's 30-second unread-count poll can narrow only by active = 1, so every poll reads every active message. The cost of a poll is the number of messages times the number of users, and it grows with every new message.

Active messages
40,000
0 at 15:42:20
DBs1 CPU
51%
+9%/min · alarm at 85%
Rows read per second
2.5 M
16 written
Time to 85% CPU
~3.5 min
the archive takes about 2

Sample by sample

Active messages

Count, every sample (12 s), UTC. A straight climb from 15:42:20: it does not level off.

020,00040,00060,00015:4215:4415:46
Table (every sample)
UTCValue
15:41:300
15:41:420
15:41:540
15:42:060
15:42:180
15:42:301,458
15:42:423,207
15:42:544,956
15:43:066,706
15:43:188,455
15:43:3010,204
15:43:4211,954
15:43:5413,703
15:44:0615,452
15:44:1817,202
15:44:3018,951
15:44:4220,354
15:44:5421,758
15:45:0623,161
15:45:1824,564
15:45:3025,967
15:45:4227,371
15:45:5428,774
15:46:0630,177
15:46:1831,580
15:46:3032,984
15:46:4234,387
15:46:5435,790
15:47:0637,193
15:47:1838,597
15:47:3040,000
DBs1 CPU

Percent, every sample, UTC. It climbs with the active count, not with traffic.

0%25%50%75%100%15:4215:4415:46preemptive 50%alarm 85%
Table (every sample)
UTCValue
15:41:303.0%
15:41:423.2%
15:41:543.5%
15:42:063.7%
15:42:184.0%
15:42:305.4%
15:42:427.2%
15:42:548.9%
15:43:0610.6%
15:43:1812.3%
15:43:3014.1%
15:43:4215.8%
15:43:5417.5%
15:44:0619.2%
15:44:1821.0%
15:44:3022.7%
15:44:4224.6%
15:44:5426.5%
15:45:0628.4%
15:45:1830.2%
15:45:3032.1%
15:45:4234.0%
15:45:5435.9%
15:46:0637.8%
15:46:1839.7%
15:46:3041.6%
15:46:4243.5%
15:46:5445.3%
15:47:0647.2%
15:47:1849.1%
15:47:3051.0%
DBs1 rows read per second

Rows a second, every sample, UTC. Reads grow with active messages; writes stay near 16 a second.

01,000,0002,000,0003,000,00015:4215:4415:46
Table (every sample)
UTCValue
15:41:3015,000
15:41:4216,200
15:41:5417,400
15:42:0618,600
15:42:1819,800
15:42:30102,308
15:42:42201,077
15:42:54299,846
15:43:06398,615
15:43:18497,385
15:43:30596,154
15:43:42694,923
15:43:54793,692
15:44:06892,462
15:44:18991,231
15:44:301,090,000
15:44:421,184,000
15:44:541,278,000
15:45:061,372,000
15:45:181,466,000
15:45:301,560,000
15:45:421,654,000
15:45:541,748,000
15:46:061,842,000
15:46:181,936,000
15:46:302,030,000
15:46:422,124,000
15:46:542,218,000
15:47:062,312,000
15:47:182,406,000
15:47:302,500,000

Findings

F1

Every unread-count poll reads every active message

Act now
Active 40,000DBs1 CPU 51%, +9%/min85% at ~15:51 UTC

No one changed anything here. It is built into the design: App1's unread-count query filters on active = 1 plus several OR-conditions and groups by thread, so each 30-second poll reads every active message. Rows read follow the messages table, while requests stay flat. Lock waits are 0: this is not a lock storm.

To watch

🤖 For your coding agent

Feed the MD into your coding agent for a fast response: rca-preemptive.md (attached to the email) holds the cause in the code, the exact change, the files, and how to check it worked.