Skip to content

Migrating from Flask to FastAPI

lasryariel edited this page Sep 6, 2024 · 3 revisions

Decision Record: Migration from Flask to FastAPI

This is a Decision Record. The decision was to Adopt aka migrate from Flask to FastAPI.

Issue

Problem Statement

Our previous backend framework, Flask, served the project well but had limitations with developer accessibility, particularly for junior developers. As our project scales and our team grows, there is a need for a more modern framework that can support asynchronous operations, provide better integration with type hints, and improve code readability. FastAPI emerged as the preferred choice due to its built-in features such as dependency injection and automatic OpenAPI documentation generation.

Solution

We have chosen to migrate from Flask to FastAPI due to:

  • Performance: FastAPI’s async capabilities improve performance, especially with concurrent requests.
  • Developer experience: Type hints, Pydantic validation, and automatic OpenAPI documentation streamline development and make the code more accessible to new contributors (Issue #773).
  • Dependency management: FastAPI's Dependency Injection simplifies modularization and testability (Issue #777).

Feasibility Determination

  • Performance gains: Initial tests indicate FastAPI will offer better performance, particularly with async operations.
  • Migration ease: Most of the existing code can be ported without significant refactoring. Key efforts will focus on transitioning from Marshmallow to Pydantic for serialization.
  • Scalability: FastAPI’s modern architecture is expected to support long-term growth and ease of new feature development.

The migration will be completed as part of the 6.0.2 milestone.