Skip to content

Example: Multi-Tenant API Service (FastAPI + enzu) #23

Description

@teilomillet

Goal

Production SaaS example showing how to integrate enzu into a FastAPI service with per-customer budgets.

Use Case

Document analysis API with multiple customers, each with their own budget limits.

What It Demonstrates

  • FastAPI integration - REST endpoints with enzu execution
  • Multi-tenant isolation - per-customer budget tracking
  • Job queue pattern - async processing with delegation
  • Observability - Prometheus metrics, structured logging
  • Rate limiting - budget-aware request throttling
  • Session management - customer context preservation

Deliverables

  • examples/api_service/
    • main.py - FastAPI app with endpoints
    • models.py - Pydantic request/response models
    • budget.py - per-customer budget controller
    • worker.py - background job processor
    • docker-compose.yml - Redis + service setup
    • README.md - deployment guide, API docs
    • tests/ - integration tests
    • metrics.py - Prometheus exporters

Example Endpoints

POST /analyze - Submit document for analysis
GET /jobs/{id} - Check job status
GET /metrics - Prometheus metrics
GET /health - Health check

Success Criteria

  • Runs with docker-compose
  • Multiple customers isolated
  • Budget enforcement per customer
  • Prometheus metrics exposed
  • Clean error handling + typed outcomes

Target Audience

SaaS companies, API service builders

Estimated Effort

Large (3-4 days)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions