OpenFaaS Integration & Serverless Functions
Aevum Encyclopedia utilizes OpenFaaS to orchestrate event-driven, stateless microservices across our global infrastructure. This architecture enables horizontal scaling for compute-intensive workloads such as citation validation, media transcoding, search indexing, and real-time content moderation.
All OpenFaaS functions run in isolated Kubernetes namespaces with strict resource quotas. Functions communicate via HTTP/1.1 or gRPC, with optional NATS JetStream backpressure handling.
System Architecture
The serverless layer sits between the API gateway and persistent storage. Incoming requests are routed through the faas-gateway, which handles authentication, rate limiting, and request forwarding to the appropriate function pod.
Architecture FlowCopyClient → CDN → API Gateway → faas-gateway ├── auth-validator (gRPC) ├── content-indexer (HTTP) ├── citation-parser (HTTP) └── media-transcoder (HTTP + S3 Trigger) Functions → Redis Cache / PostgreSQL / NATS Queue
Core Function Registry
| Function | Protocol | Concurrency | Memory | Purpose |
|---|---|---|---|---|
auth-validator |
gRPC | 500 req/s | 128MB | JWT verification, API key rotation, rate limit checks |
content-indexer |
HTTP | 2,000 req/s | 512MB | TF-IDF vectorization, Elasticsearch sync, NLP tagging |
citation-parser |
HTTP | 800 req/s | 256MB | DOI resolution, BibTeX/CSL conversion, source verification |
media-transcoder |
HTTP | 50 req/s | 2GB | FFmpeg pipelines, thumbnail generation, format normalization |
rate-limiter |
gRPC | 10,000 req/s | 64MB | Distributed token bucket, sliding window counters |
Deployment Configuration
Service Definition
Functions are deployed using stack.yml. Below is a production-ready template for the citation parser:
stack.ymlCopyversion: 1.0 provider: name: faas gateway: https://faas.aevum-enc.edu functions: citation-parser: lang: python3.11 handler: ./handlers/citation image: registry.aevum.io/encyclopedia/citation-parser:latest environment: REDIS_HOST: cache.internal ELASTIC_HOST: search.internal CONCURRENCY: 8 limits: memory: 256M requests: 1000 annotations: prometheus.io/scrape: "true"
CLI Deployment
bashCopy# Build and push container faas-cli build -f stack.yml faas-cli publish -f stack.yml # Deploy to cluster faas-cli deploy -f stack.yml --gateway=https://faas.aevum-enc.edu # Verify rollout faas-cli list --gateway=https://faas.aevum-enc.edu
Never embed credentials in stack.yml. Use Kubernetes Secrets or Vault injection via the AevumSecretsProvider sidecar.
Autoscaling Policies
OpenFaaS uses metric-driven autoscaling. Functions scale based on pending requests, CPU utilization, or custom Prometheus metrics.
| Policy | Min Replicas | Max Replicas | Cooldown | Target Metric |
|---|---|---|---|---|
| Standard | 1 | 20 | 30s | Pending > 5 |
| High-Traffic | 3 | 50 | 15s | Pending > 20 OR CPU > 70% |
| Batch/Async | 0 | 10 | 60s | Queue depth > 50 |
To configure scaling, add annotations to your function definition:
YAML AnnotationsCopyannotations: com.openfaas.scale.min: "3" com.openfaas.scale.max: "50" com.openfaas.scale.factor: "20" # 20 pending requests
Monitoring & Observability
Every function exposes Prometheus-compatible metrics at /system/metrics. Key metrics include:
http_requests_total{function="name"}- Total requests by statushttp_request_duration_seconds- Latency histogramfaas_function_pending_requests- Queue depthfaas_function_memory_usage_bytes- RSS memory consumption
Logs are shipped to Loki via the Fluent Bit daemonset. Use the following query to trace function invocations:
LogQLCopy{app="faas-provider", function="citation-parser"} |= "error" | json | request_id != ""
Grafana dashboards are available at grafana.aevum-enc.edu/d/openfaas with read-only access for partners.
CLI Reference
The faas-cli is the primary tool for function lifecycle management. Ensure you're running v0.14.0+ for full Kubernetes provider support.
Common CommandsCopyfaas-cli up -f stack.yml # Build, publish, deploy faas-cli invoke# Local/test invocation faas-cli logs # Stream stdout/stderr faas-cli secret create # Push to K8s secrets faas-cli rollout # Rolling update without downtime
Troubleshooting
Common Issues
- 504 Gateway Timeout: Function cold start exceeded gateway timeout (default 60s). Increase
read_timeoutor optimize init logic. - OOMKilled: Memory limit too low. Check heap profiling and adjust
limits.memory. - Pod CrashLoopBackOff: Missing environment variables or invalid handler path. Run
faas-cli build --no-cachelocally first.
For cluster-level diagnostics, inspect the provider logs:
bashCopykubectl logs -n openfaas-fn -l app=faas-provider --tail=100
File infrastructure tickets via support@aevum-enc.edu or join our Developer Slack (#openfaas) for real-time assistance.