A page takes 4 seconds to load; the APM trace shows 300 identical `SELECT ... WHERE id = ?` queries in one request.

BeginnerTroubleshootingLatency
Answer

Likely causes → The N+1 query problem: the ORM loads a list, then lazily loads a relation per row.

Diagnose → In the trace, group spans by SQL statement and count them. Locally, enable ORM query logging and hit the endpoint.

Fix → Eager-load the relation (select_related/prefetch_related in Django, includes in Rails, JOIN FETCH in JPA), or batch with WHERE id IN (...).

Prevent → Add a test that asserts the query count for key endpoints, and an APM alert for requests with more than N DB calls.

All Real-World Interview questions Roadmap: Interview readiness

More on Latency