Code RoomN+1 queries activity feed
MediumPrep Room Coding #2766

N+1 queries activity feed

On-callDatabases & SQLMid–Senior~30 min

After a feature launch that added an 'activity feed' to user dashboards, your DB's read load tripled and dashboard load times went from 300ms to 4s, worst for power users. APM shows the dashboard endpoint issuing 300+ near-identical small queries per request — one `SELECT ... WHERE id = ?` per feed item — each individually fast (under 1ms) but adding up. The feed query that fetches the item ids is itself quick. CPU is high but not pinned; connection count is elevated. Triage and mitigate.

What a strong answer looks like

Stop the bleeding first (mitigate), then form hypotheses from real signals. Separate root cause from symptom, communicate status as you go, and close with what prevents a repeat.

0:00 of about 30 min
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.