ADR-003: FastAPI as Web Framework
Status
AcceptedContext
The original Heka platform was built on Flask with Gunicorn, which led to several limitations:- Synchronous by default: Poor performance for I/O heavy operations
- No native async support: Difficult to implement websockets, SSE
- Manual API documentation: OpenAPI specs maintained separately from code
- Limited type safety: No automatic request/response validation
- Concurrency issues: Problems with worker processes and shared state
Decision
We selected FastAPI as the foundation web framework for Tasteful.Key Advantages
- Native Async Support: Built on ASGI (Starlette) for true asynchronous processing
- Automatic API Documentation: OpenAPI/Swagger docs generated from code
- Type Safety: Pydantic integration for request/response validation
- Performance: Among the fastest Python web frameworks
- Modern Standards: Built-in support for modern web standards (JSON, WebSockets, etc.)
Implementation Pattern
Integration with Tasteful Architecture
Consequences
Positive
- Async Performance: Better handling of I/O operations and concurrent requests
- Developer Experience: Automatic API docs, type hints, IDE support
- Validation: Built-in request/response validation reduces bugs
- Standards Compliance: OpenAPI 3.0, JSON Schema support out of the box
- Future-Proof: Modern async architecture supports websockets, SSE, etc.
- Ecosystem: Large ecosystem of FastAPI extensions and middleware
Negative
- Learning Curve: Team needs to understand async/await patterns
- Complexity: More complex than synchronous frameworks for simple use cases
- Debugging: Async stack traces can be more difficult to debug
- Dependencies: Heavier dependency footprint than minimal frameworks
Trade-offs
- Performance vs. Simplicity: Better performance but requires async understanding
- Type Safety vs. Flexibility: More rigid but catches errors earlier
- Auto-documentation vs. Control: Generated docs are convenient but less customizable
Alternatives Considered
-
Flask + Flask-RESTX: Continue with existing stack
- Rejected: Doesn’t address async/performance issues
-
Django REST Framework: Full-featured framework
- Rejected: Too opinionated, heavy for our modular architecture
-
Starlette: Direct use of ASGI framework
- Rejected: Too low-level, would require building features FastAPI provides
-
Tornado: Async web framework
- Rejected: Less modern, smaller ecosystem
-
Sanic: Fast async framework
- Rejected: Less mature ecosystem, no automatic API documentation