How It Works
By default, in most cases, when deploying FastAPI applications to FastAPI Cloud, everything will just work out of the box with zero configuration needed. ✨
There are some additional configurations you can make and things you can have in mind to customize your application.
Default Workflow
Section titled “Default Workflow”When you run the fastapi deploy command, the following happens:
- Your app code is packaged and uploaded.
- Your app is installed and built.
- Your app is deployed.
- The deployment is verified.
Let’s go over these steps in more detail.
Package and Upload
Section titled “Package and Upload”When you run the fastapi deploy command, it will read and package your application code and files.
By default it will respect configurations in .gitignore files, for example, to not include your local Python virtual environment or any other excluded files.
You can configure this further using the .fastapicloudignore file, you can read more about it in the docs page for Ignore or Un-ignore Files.
This step will not install or build anything in your local system, only upload the files. So you don’t need any additional local dependencies, the rest is done in the cloud. 😎
In this step, a new deployment record is created for your app in your FastAPI Cloud account.
Install and Build
Section titled “Install and Build”Once the upload is finished, the build process starts.
FastAPI Cloud will take your files and will install and build your application.
This is all done following and respecting Python standards and common conventions, so you won’t have surprises.
You can read more about how dependencies are installed in the docs page: Install Dependencies.
Deployment
Section titled “Deployment”The next step is the deployment of your app. This is done in a way that allows for zero downtime deployments.
FastAPI Cloud has autoscaling based on requests, so if your app has a lot of traffic, it will scale up the number of deployment instances automatically.
When a new deployment is created, it is rolled out gradually to avoid downtime.
This means that while the new deployment instances are started, the old ones are still running and serving traffic, so they are gradually and cleanly replaced with the new ones.
This should ensure you have the best uptime possible (zero downtime).
But you should also make sure that your code is compatible with zero downtime deployments, for example, with database migrations.
You can read more about this in the Deployments and Database Migrations docs page.
Deployment Verification
Section titled “Deployment Verification”Once the new deployment instances are running, FastAPI Cloud will verify that they are working correctly.
If there’s any problem with the new deployment, the last successful deployment will be kept.
You will be able to see the status of your deployments in the FastAPI Cloud dashboard.
If you can run the fastapi dev command locally, it should work in FastAPI Cloud as well! 🚀
If you normally need to pass a path file to the fastapi deploy command, you can instead configure it in the pyproject.toml file. You can read more about it in the docs page about Configuring FastAPI.