Question
[PERF-025] Add server-side response time monitoring with P95/P99 latency tracking
Asked by: USER2639
81 Viewed
81 Answers
Answer (81)
Problem
The app tracks Web Vitals on the client side and has slow query monitoring for the database layer, but there is no server-side response time tracking across API routes and server actions. Without P95/P99 latency metrics, it is impossible to detect gradual performance regressions or set meaningful SLAs.
Proposed Solution
- Middleware-level timing — Record response times for all API routes and server actions in the Next.js middleware or via a wrapper
- Percentile tracking — Compute and expose P50, P95, P99 latency per endpoint
- Latency budget alerts — Alert when P95 exceeds a configurable threshold (e.g., 500ms for API, 2s for page loads)
- Dashboard integration — Surface latency metrics in the existing monitoring/admin dashboard
Acceptance Criteria
- [ ] Response times are recorded for all API routes
- [ ] P50/P95/P99 metrics are available per endpoint
- [ ] Alerts fire when latency budgets are exceeded
- [ ] Historical latency data is retained for trend analysis (at least 7 days)
[PERF-025] Solution
Problem: The application tracks Web Vitals on the client side and has slow query monitoring for the database layer, but there is no server-side response time tracking across API routes and server actions. Without P95/P99 latency metrics, it is impossible to detect gradual performance regressions or set meaningful SLAs.
Solution:
- Middleware-level timing: Record response times for all API routes and server actions in the Next.js middleware or via a wrapper.
- Percentile tracking: Compute and expose P50, P95, P99 latency per endpoint.
- Latency budget alerts: Alert when P95 exceeds a configurable threshold (e.g., 500ms for API, 2s for page loads).
- Dashboard integration: Surface latency metrics in the existing monitoring/admin dashboard.
Acceptance Criteria:
- [ ] Response times are recorded for all API routes.
- [ ] P50/P95/P99 metrics are available per endpoint.
- [ ] Alerts fire when latency budgets are exceeded.
- [ ] Historical latency data is retained for trend analysis (at least 7 days).