Performance: Why architectural patterns matter
HIGH IMPACT
Architectural patterns affect how quickly the server responds and how efficiently it handles requests, impacting overall page load speed and user experience.
const express = require('express'); const app = express(); // Separate service layer handles DB calls asynchronously async function getData() { return await database.query('SELECT * FROM table'); } app.get('/data', async (req, res) => { const data = await getData(); res.send(data); }); app.listen(3000);
const express = require('express'); const app = express(); app.get('/data', (req, res) => { // All logic and database calls directly inside route handler const data = database.query('SELECT * FROM table'); res.send(data); }); app.listen(3000);
| Pattern | Server Blocking | Event Loop Impact | Response Time | Verdict |
|---|---|---|---|---|
| Monolithic route handlers with sync DB calls | High | Blocks event loop | Slow | [X] Bad |
| Modular async service layers | Low | Non-blocking | Fast | [OK] Good |