CraftComposable · Yields to: Voice, Process
Harden
Production-harden code for 1M+ users. Adds caching, rate limiting, graceful shutdown, error handling, and scalability patterns.
When to Use
- User says "harden my code", "prepare for launch", "make it scalable"
- Code needs caching, rate limiting, or error handling
- Preparing for high traffic
Triggers
"harden my code", "prepare for launch", "add caching",
"add rate limiting", "make it production-ready"Examples
Example 1
Harden an API endpoint
Add production patterns to a simple Express endpoint.
Before:
javascript
app.get('/api/users/:id', async (req, res) => {
const user = await db.findUser(req.params.id);
res.json(user);
});After /harden:
javascript
const rateLimit = require('express-rate-limit');
const cache = new NodeCache({ stdTTL: 60 });
const limiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 100 });
app.get('/api/users/:id', limiter, async (req, res) => {
const cacheKey = `user:${req.params.id}`;
const cached = cache.get(cacheKey);
if (cached) return res.json(cached);
try {
const user = await db.findUser(req.params.id);
if (!user) return res.status(404).json({ error: 'User not found' });
cache.set(cacheKey, user);
res.json(user);
} catch (err) {
logger.error('User fetch failed', { id: req.params.id, err });
res.status(500).json({ error: 'Internal server error' });
}
});Example 2
Refactor then harden
Clean up messy code, then add production patterns.
/refactor → /harden
Refactor splits a 2000-line monolith into focused modules.
Harden adds: rate limiting per module, graceful shutdown
handlers, health check endpoints, structured logging,
input validation, and error boundaries.What It Adds
| Pattern | Description |
|---|---|
| Caching | In-memory, Redis, CDN, cache invalidation |
| Rate Limiting | Token bucket, sliding window, per-user limits |
| Graceful Shutdown | Signal handling, connection draining, cleanup |
| Error Handling | Retry logic, circuit breakers, fallbacks |
| Monitoring | Health checks, metrics, logging |
| Security | Input validation, CORS, CSP, auth |