Query Performance
Optimize Search
Use Filters Narrow results for faster queries:Caching Strategy
Query Results Cache identical queries:Database Optimization
Indexing
Ensure critical indexes exist:Query Optimization
Use EXPLAIN ANALYZE to identify slow queries:- Seq Scan (bad) → Add index
- Index Scan (good)
- High execution time → Optimize
Connection Pooling
Configure Supabase pool:Sync Performance
Batch Processing
Process documents in batches:Parallel Processing
Use worker threads for CPU-intensive tasks:Rate Limiting
Respect API rate limits:Frontend Optimization
Code Splitting
Split large components:Image Optimization
Use Next.js Image:API Route Caching
Cache API responses:Monitoring
Key Metrics
Track these metrics:- Query latency - p50, p95, p99
- Sync throughput - docs/second
- Error rate - 4xx, 5xx errors
- Database performance - query time
- Memory usage - heap, RSS
Tools
Scaling
Horizontal Scaling
Add more instances:Database Read Replicas
Distribute read load:CDN
Use Vercel Edge:Best Practices
Monitor First
Monitor First
Identify bottlenecks before optimizing
Cache Aggressively
Cache Aggressively
Cache at every layer (API, DB, CDN)
Batch Operations
Batch Operations
Never process one-by-one
Use Indexes
Use Indexes
Index all filtered/sorted columns
Optimize Queries
Optimize Queries
Use EXPLAIN ANALYZE regularly
Next Steps
Troubleshooting
Debug common issues