Avatar of RileyMShea

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.

READ MORE
3 upvotes·2 comments·17.8K 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.

https://www.howtographql.com/basics/1-graphql-is-the-better-rest/

Hope that helps!

·
Reply
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: https://github.com/vitalik/django-ninja) to improve performance.

·
Reply