These are intentionally small, readable snippets that demonstrate the engineering posture: health checks, process supervision, reverse proxying, deployments, and rate limiting.
Health check pattern (simplified)
Provides a fast, reliable signal for uptime checks and deploy smoke tests by exercising the app and database path.
@api_bp.route("/health")
def health_check():
db.session.execute(text("SELECT 1"))
return jsonify({"status": "ok"})
Gunicorn behind Nginx (sanitized)
Uses a process-managed application server so the service stays stable across reloads and failures.
# systemd-managed gunicorn (conceptual)
gunicorn -w 2 --threads 2 --worker-class gthread \\
--max-requests 1000 --max-requests-jitter 50 \\
--timeout 120 -b 127.0.0.1:8005 app:app
Nginx reverse proxy (sanitized)
Keeps the public edge consistent while proxying requests to the app on localhost, and preserves client identity for logs and rate limiting.
location / {
proxy_pass http://127.0.0.1:8005;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Deploy pull and reload (sanitized)
Makes releases deterministic and auditable by tying deployments to commits, then validates a known-good health endpoint after reload.
git fetch origin main
git reset --hard origin/main
systemctl reload app.service
curl -fsS http://127.0.0.1:8005/api/health
Rate limiting posture (conceptual)
Reduces abuse risk and protects availability by enforcing simple request budgets on public endpoints.
resp = apply_rate_limit("60 per minute")
if resp:
return resp