Behind a surprising number of "the site is slow" and 504 timeout incidents sits the same quiet culprit: the database. Apps wait on it, and when it slows, the slowness ripples outward into every page and API call. Yet the database is often the least-monitored part of the stack. Let's fix that.
Why the database deserves special attention
Your app might be fast and your servers healthy, but if a query is crawling, users feel it everywhere. The database is a shared dependency — one slow query or an exhausted connection pool can degrade the entire application at once. Monitoring it turns "the app is randomly slow sometimes" into a specific, fixable cause.
What to watch
| Signal | Why it matters |
|---|---|
| Query latency | Slow queries are the #1 cause of slow apps |
| Slow query log | Pinpoints which queries to fix |
| Connections | A full connection pool blocks new requests |
| Errors | Failed queries, deadlocks, constraint violations |
| Replication lag | Replicas falling behind serve stale data |
| Cache hit ratio | Low ratios mean the DB is working too hard |
| Disk & memory | A full disk or thrashing memory takes the DB down hard |
Query latency and slow queries
This is the big one. Track how long queries take — and especially the p95/p99, because the slowest queries cause the most pain. The slow query log is gold: it names the exact queries crossing your threshold, which is usually where a missing index hides.
Connections
Databases allow a limited number of simultaneous connections. When that pool is exhausted, new requests can't get a connection and just wait — which surfaces as timeouts in your app even though the DB itself is "up." Watch connection count against the limit.
Replication lag
If you use read replicas, lag means replicas are behind the primary — so reads return stale data, and a failover could lose recent writes. Spiking lag is an early warning of trouble.
Watch the trend
A slow query rarely arrives suddenly — it grows. A query that was fine at 10,000 rows crawls at 10 million. Watching latency over time catches the gradual slide before it becomes an outage, and points you at the query to optimise (usually with an index).
Connecting it to user impact
Database problems show up to users as application symptoms — timeouts, slow pages, 504s. That's why DB monitoring pairs so well with uptime and response-time monitoring: the external checks tell you something is slow, and the database metrics tell you it's the DB, and here's the query.
The bottom line
| Watch | The risk it catches |
|---|---|
| Query latency / slow log | The #1 cause of slow apps. |
| Connections | Pool exhaustion → app-wide timeouts. |
| Errors & deadlocks | Failed operations and contention. |
| Replication lag | Stale reads and risky failovers. |
| Disk / memory | Hard, sudden database outages. |
The database is the shared dependency everything leans on. Watch query latency and the slow log first, keep an eye on connections and replication, and focus on trends — and the DB stops being the mystery behind your "randomly slow" days.
Related: 504 Gateway Timeout, latency percentiles, and server monitoring basics.