Needs advice
Django REST frameworkDjango REST framework

Not sure if we should use DRF or FastAPI. I hear many good things about FastAPI, but it doesn't seem to have a big community. Most important things for us: - speed - ease of development - scalability & security

We're likely going to use MongoDB, so not sure if that changes anything. Would appreciate any help!

5 upvotes·40.2K views
Replies (4)

Depends on if you're building an api/microservice or a monolith. Django has a bigger ecosystem of plugins which may, or may not, save you from writng code yourself. DJango can "kind of" work with mongo, but it's really designed to go along with an SQL database. It's also an aging ecosytem though, with many unmaintained plugins.

FastAPI will win out in pretty much every other respect.

3 upvotes·2 comments·9.7K views
Deepak T
Deepak T
June 4th 2021 at 4:55AM

As RileyMShea said, Django has close coupling with SQL.

Being said that, I have used DRF with MongoDB before, and it worked well but its gets quirky at places. Django and DRF are very matured frameworks which gives tones of stuff out of the box. It will give you ease of development and security, but speed and scalability depends a lot on the person who is writing the code. I have seen DRF APIs working like a charm and dot net APIs being a pain in the ass. Depends on the developer.

I have not used FastAPI personally, but I have used Starlette on which FastAPI is based and Starlette was created by creator of Django REST (tom christie). You will get the speed but in the long run (3-5 years) ease of development is extremely important. You can achieve speed outside the framework (read caching, DB optimization, raw SQL queries) but if your next developer or development team cannot extend the existing implementation, you will have to trash it.

I am not saying don't go for FastAPI, but duration of the project as well as company size will be the key factors in your decision-making.

Also, look at GraphQL, a lot of pain areas with REST API, like nested resources, or writing custom APIs because main resource based APIs don't fulfil your data needs, are addressed in GraphQL.

Hope that helps!

Ryan Manzer
Ryan Manzer
June 4th 2021 at 2:14PM

I find that DRF provides classes like the Viewsets that allow you to get a fairly large and nuanced API structure in place quickly. I like to use it to spin up my MVP and make changes. Once the API design is stabilized and meets the specified needs I've been migrating endpoints to FastAPI ( or django-ninja: to improve performance.

ETL Developer at Tellus Home·

FastAPI might not have a big community but the documentation is awesome and covers every aspect of the framework itself. I'd recommend coming up with a pilot project yourself and try it on your own. It has a bit learning curve as FastAPI itself is a combo of a few existing projects otherwise it is amazing.

5 upvotes·21.3K views
View all (4)
Avatar of RileyMShea