A collection of opinionated best practices and conventions for building scalable FastAPI applications, based on real-world startup experience.
FastAPI Best Practices is a curated collection of conventions and architectural patterns for building robust, scalable FastAPI applications. It addresses common pitfalls in project structure, async programming, dependency management, and database interactions, based on lessons learned from developing production systems at a startup.
Backend developers and engineering teams building or maintaining FastAPI applications, particularly those working on monoliths or complex services where scalability and maintainability are critical.
It provides concrete, opinionated guidance that helps teams avoid common mistakes, establish consistent patterns, and leverage FastAPI's features effectively, reducing technical debt and improving developer velocity.
FastAPI Best Practices and Conventions we used at our startup
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Promotes a domain-driven modular structure inspired by Netflix's Dispatch, which prevents spaghetti code in growing monoliths, as detailed in the project layout section.
Provides clear guidance on when to use async vs sync routes, with practical examples for I/O-intensive and CPU-intensive tasks, avoiding common performance pitfalls.
Encourages extensive use of Pydantic for validation and serialization, including custom base models and decoupled settings, enhancing data consistency across the app.
Demonstrates advanced dependency patterns like chaining and caching, reducing code duplication and improving testability, as shown in the dependencies section.
Offers actionable advice for real-world scenarios, such as hiding API docs in production and setting up async test clients from day one to avoid integration issues.
The prescribed structure and conventions may not fit all teams or existing codebases, potentially causing adoption friction without flexibility for alternative patterns.
Lacks beginner-friendly explanations; for instance, async concepts are discussed without basic introductions, making it less accessible for newcomers.
Relies on links to external GitHub issues and blogs for some explanations, which could become broken or outdated, reducing long-term reliability.
Focuses heavily on code patterns without addressing broader ecosystem integration, such as deployment with Docker or monitoring, which are crucial for production.