Engineering
What this does: Generates real-time demand predictions via a secure, rate-limited API — enabling business applications to request forecasts on demand with enterprise-grade authentication and monitoring.
Architecture
The serving layer (src/demand_forecasting/serving) exposes a REST API for demand forecasting.
Security Middleware Stack
The API applies four layers of middleware, in order of priority:1
SecurityHeadersMiddleware
Adds OWASP-recommended headers:
X-Frame-Options: DENY, X-Content-Type-Options: nosniff, Content-Security-Policy, Referrer-Policy, Permissions-Policy. In production, adds Strict-Transport-Security (HSTS).2
RateLimitMiddleware
IP-based rate limiting (default: 60 requests/minute). Returns
429 Too Many Requests with Retry-After and X-RateLimit-* headers. Configurable via RATE_LIMIT_PER_MINUTE environment variable.3
TrustedHostMiddleware
Prevents Host header attacks. Allowed hosts are environment-specific — production hosts must be explicitly configured via
ALLOWED_HOSTS.4
CORS
Environment-aware origin allowlisting. Only
GET, POST, OPTIONS methods allowed. No wildcard origins in any environment.Authentication
API key authentication using Argon2id hashing with constant-time verification:- Key Storage: SHA-256 → Argon2id hashed in memory (loaded from
VALID_API_KEYSenv var) - Brute Force Protection: Max 10 failed attempts per hour per IP
- Rehashing: Automatic rehash if Argon2 parameters are updated
Inference Strategies
API Reference
- POST /predict
- GET /health
- GET /model/info
- GET /metrics/drift
- GET /metrics
Generates a forecast for a given set of conditions. Requires authentication.
Refer to the API Reference for complete schema details.
Related Pages
Generate Forecast API
Full API reference with request/response schemas and interactive playground.
Infrastructure
Docker Compose architecture and service configuration behind the API.
