Production Checklist
1. Build for Production
Section titled “1. Build for Production”# Release build of the Rust extensionmaturin develop --release --manifest-path crates/justapi-py/Cargo.tomlCargo.toml sets panic = "abort" in release mode — panics safely abort the process (no UB across PyO3 FFI).
2. Process Supervision
Section titled “2. Process Supervision”Run under a supervisor that restarts the process:
# systemd unit[Service]ExecStart=/srv/app/venv/bin/python -m myappRestart=alwaysRestartSec=1StartLimitIntervalSec=10StartLimitBurst=5For Kubernetes, set restartPolicy: Always with liveness and readiness probes.
3. TLS Termination
Section titled “3. TLS Termination”Recommended: Terminate TLS at an edge proxy (nginx, Caddy, cloud LB):
server { listen 443 ssl; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 1m; }}4. Request Body Size
Section titled “4. Request Body Size”Set the smallest value your endpoints allow:
app.run("0.0.0.0:8000", max_body_size=1024 * 1024) # 1 MiBBodies over the limit receive 413 Payload Too Large.
5. Security Headers
Section titled “5. Security Headers”app.enable_secure_headers(with_hsts=True)app.add_cors( allow_origins=["https://yourdomain.com"], allow_methods=["GET", "POST"],)CORS is deny-by-default — no permissive * unless you configure it.
6. Health Checks
Section titled “6. Health Checks”app.register_health_check("postgres", lambda: db_ok())
# Endpoints:# GET /health → liveness probe (200 = OK)# GET /ready → readiness probe (200 = all deps healthy)# GET /live → lightweight liveness alias7. Metrics
Section titled “7. Metrics”# Scrape /metrics with Prometheuscurl http://localhost:8000/metricsKey signals: request count by route/status, p50/p95/p99 latency, error ratios.
8. Timeouts
Section titled “8. Timeouts”justapi serve --timeout 30 # Request timeout in secondsKeep proxy and JustAPI timeouts aligned to avoid spurious 504s.
9. Graceful Shutdown
Section titled “9. Graceful Shutdown”run() installs SIGINT/SIGTERM handlers. On signal, it:
- Stops accepting new connections
- Drains in-flight requests
- Calls plugin shutdown hooks
- Exits cleanly
Ensure your supervisor sends SIGTERM (not SIGKILL) for clean drains.
10. Pre-Flight Checklist
Section titled “10. Pre-Flight Checklist”- Release build (
maturin develop --release) - Supervisor with
Restart=always/restartPolicy: Always - TLS terminated at proxy (or native TLS configured)
-
max_body_sizeset to the smallest value your endpoints allow -
enable_secure_headers()called; CORS explicitly configured -
/live+/readywired to liveness/readiness probes -
/metricsscraped; alerts on error ratio + p99 - Request timeout set; proxy idle timeout ≥ JustAPI timeout
- Graceful shutdown verified (SIGTERM drains cleanly)
- No request bodies logged in production
See Also
Section titled “See Also”- Docker — Container deployment
- Kubernetes / Helm — K8s deployment
- Performance Tuning — Optimize your app