Skip to main content
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.
The system provides a robust Real-Time Inference API powered by FastAPI with production-grade security, observability, and traffic management.

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_KEYS env var)
  • Brute Force Protection: Max 10 failed attempts per hour per IP
  • Rehashing: Automatic rehash if Argon2 parameters are updated
All /predict and /predict/ab endpoints require the X-API-Key header. Unauthenticated requests receive a 401 Unauthorized response.

Inference Strategies

API Reference

Generates a forecast for a given set of conditions. Requires authentication.

Refer to the API Reference for complete schema details.

Generate Forecast API

Full API reference with request/response schemas and interactive playground.

Infrastructure

Docker Compose architecture and service configuration behind the API.