M&L
/
Introduction
-
App crashes during traffic spike 💀🥺
-
Monitoring
ensures uptime & speed
-
Logging
tracks errors & actions
-
👺 Myth
: “I’ll check manually”
-
Example: Slow “lifestyle” filter
M&L
/
Use Cases
M&L
/
Example
import express from 'express';
import winston from 'winston';
import { Request, Response } from 'express';
const app = express();
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.File({ filename: 'app.log' }),
new winston.transports.Console()
]
});
app.use(express.json());
app.get('/posts', (req: Request, res: Response) => {
const { tag } = req.query;
logger.info('User filtered posts', { tag, timestamp: new Date() });
// Simulate fetching posts
res.json([{ id: 1, title: 'Sample Post', tag }]);
});
app.post('/admin/posts', (req: Request, res: Response) => {
const { title } = req.body;
if (!title) {
logger.error(
'Post save failed',
{ error: 'Missing title', timestamp: new Date() });
return res.status(400).json({ error: 'Title is required' });
}
logger.info('Post saved', { title, timestamp: new Date() });
res.json({ message: 'Post saved' });
});
app.listen(3000, () => {
logger.info('Server started on port 3000');
});
M&L
/
Stress Testing
-
Stress test
: Simulate heavy traffic
-
Find bottlenecks
: Optimize weak points
-
Example
: 10,000 users filtering
-
Tools
:
Locust
,
JMeter
,
k6
M&L
/
Key Takeways
- Monitor uptime, speed, errors
- Log all events, not just errors
- Stress test for traffic spikes
- Pitfall: Don’t skip automation