Skip to content

Different Routers with Dependency Conflicts for Scaling API #5721

@brandonbiggs

Description

@brandonbiggs

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

$ python3 example_1.py &
$ python3 example_2.py &
$ cat main.py
app = FastAPI()

from routers import example_1
app.include_router(example_1.router) # Is connecting to the example_1.py running in background

from routers import example_2
app.include_router(example_2.router) # Is connecting to the example_2.py running in background

Description

Hi all!

I have a question about scaling my API. The applications I'm trying to serve have very different needs. One app at /example_1 may need Tensorflow 1.4 but /example_2 needs Tensorflow 2.1. Unfortunately backwards compatibility won't work, especially as I add /example{3..n}. I am currently running into a big dependency issue (age old Python problem :D). So I have been exploring how to run each router in a separate "process" so they can access their own dependencies that don't conflict with each other. I'd like to run each out of a Docker container for ease of managing dependencies, but if I need to just use conda/pyenv that would work too.

I preferably don't want to run each router as it's own fastapi instance as I want to have all the docs, base urls, etc all out of the same place, but if I have to run each as their own fastapi instance I can. I don't know how to "scale" like this. I've tried googling/searching through the documentation, but I haven't been able to find anything helpful. I may also be looking in the wrong place, so any guidance would be greatly appreciated. Thanks.

Operating System

Linux, macOS

Operating System Details

No response

FastAPI Version

0.71.0

Python Version

3.8

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions