Performance: Why database connectivity matters
HIGH IMPACT
Database connectivity affects server response time and overall user experience by controlling how fast data is retrieved and sent to the frontend.
import { Pool } from 'pg'; const pool = new Pool(); export async function handler(req, res) { const result = await pool.query('SELECT * FROM users'); res.json(result.rows); }
import { Client } from 'pg'; export async function handler(req, res) { const client = new Client(); await client.connect(); const result = await client.query('SELECT * FROM users'); await client.end(); res.json(result.rows); }
| Pattern | Connection Overhead | Server Response Time | Resource Usage | Verdict |
|---|---|---|---|---|
| New connection per request | High (connect + disconnect each time) | Slow (adds 50-200ms delay) | High CPU and memory usage | [X] Bad |
| Connection pooling | Low (reuse existing connections) | Fast (minimal delay) | Efficient resource use | [OK] Good |