I am debating what is the more "correct" / better performance solution to implementing a REST API on Azure that has a basic CRUD to a database:
- Create a Fast API app and deploy it simply on an Azure App Service
- Create an Azure Function App that every endpoint is represented by an Azure Http trigger function (inside of the azure function app) - the code in the function will be the basic CRUD functionality of the endpoint written in python (has nothing to do with fast api - basically only uses the pure code that would be inside a FastAPI route).
Both eventually would be wrapped with Azure API Manager.
What solution will have better response time?
Will server-less be more resilient?
Thanks
CodePudding user response:
If the functions use the python runtime, then FastAPI is a very popular alternative.
I personally found the migration of Azure Functions to a FastAPI App Service to be very smooth and hassle-free.
Differences between the above two:
- Function Independent Changes: Primarily we need to import FastAPI and Status, CORS Middleware in the include statements to avoid CORS issues.
- In the Azure functions, CORS will be enabled through the portal.
For getting the more information about the differences like Function dependent changes, Return Statements, adding more than one function/endpoint, please visit this article.
FastAPI ranks among the highest-performing Python web frameworks for building APIs out there and it's being used more and more day by day.
Not only in terms of the number of queries handled per second, but also the speed of the development and its built-in data validation makes an ideal for the backend side.
CodePudding user response:
A few other aspects which you need to think about like scalability, cost and ease of development.
- If you use Fastapi on an app service, you will need to configure the scaling rules yourself. An azure function on consumption or premium plans will scale automatically.
- Fastapi on an app service will cost money even if you are not using it. But an azure function on consumption plan will cost only if you use it and you get 1 million executions free every month so the cost is basically nothing if your execution count is < 1M.
- Since FastAPI is an API framework, it comes in built will correct
responses in case of errors and you just handle whatever you need to. For Azure function you will need to code pretty much everything.
