Performance Troubleshooting
Diagnose and fix performance issues.
Slow API Responses
Database Queries
Symptom: Endpoints take > 1 second
Diagnosis:
-- Find slow queries in PostgreSQL
SELECT pid, now() - pg_stat_activity.query_start AS duration, query
FROM pg_stat_activity
WHERE state = 'active'
ORDER BY duration DESC;
Fixes:
- Add database indexes for frequently queried columns
- Reduce
relationsin API queries - Use pagination (
page+limitparams) - Enable query caching with Redis
N+1 Query Problem
Symptom: Many small queries instead of one JOIN
Fix: Use eager loading for relations:
const result = await this.service.findAll({
relations: ["user", "organization"],
});
High Memory Usage
Symptom: API process exceeding memory limits
Fixes:
- Increase
NODE_OPTIONS="--max-old-space-size=4096" - Check for memory leaks (unclosed connections, large caches)
- Use streaming for large data exports
Redis Performance
Diagnosis:
redis-cli INFO memory
redis-cli INFO stats
redis-cli SLOWLOG GET 10
Fixes:
- Set appropriate
maxmemoryand eviction policy - Monitor key expiration
- Use Redis Cluster for large datasets
Frontend Performance
Fixes:
- Enable lazy loading for feature modules
- Use
OnPushchange detection strategy - Implement virtual scrolling for long lists
- Optimize images and assets
Related Pages
- Monitoring & Observability — monitoring setup
- Scaling & HA — scaling guide
- Redis & Caching — caching patterns