why django is slow compared to other frameworks like fastapi

I already know that django is slow because a lot of included batteries in it which make things simple and easy but regarding performance I think it’s the slowest python web framework
so my question here ?
Can i use django for a high traffic project ?

Really? I didn’t “know” that, and that’s after working with Django for 7 years now along with working with (at various times) Zope, Twisted, TurboGears, CherryPy, Flask, and Bottle. I find nothing “slow” about it in real applications as opposed to prototypes, demos, and other contrived examples.

I’m not the person to answer that, there’s no site I’ve ever built that would be considered “high traffic”. For that, you should ask Google among other large corporations that have adopted it.

Would you consider Instagram, Spotify, Pinterest, and YouTube to be “high traffic”? They’re all build on Django.

(See 10 Popular Django Websites That You Probably Know | Django Stars for some more examples.)

I didn’t say that it’s slow in general I said it’s slow compared to the other python web frameworks and that’s not my opinion it’s based on benchmarks as declared here.
Web Frameworks Benchmark
Thanks for your reply.

(Emphasis added)

Note: I do mean “not slow” both in absolute terms and relative to any other Python-based web framework I have used.

I’ve seen - been referred to - that site before. It has no real-world decision-making value.

Yes, I understand what they’re trying to do. However, their results are meaningless.

You’re never going to “productionize” a “Hello World” application. It would be a mistake to make any kind of technology-platform decision based upon the information provided there.

Proper benchmarking of application and application stacks is a very complex and nuanced subject.

2 Likes

I’m going to +1 Ken’s shoutout about meaningless metrics.

My advice is to pick the framework that you are the most productive with if that’s FastAPI, then great. If it’s Django, then wonderful. All that matters is that you are using a set of tools that solve your problem well.

I love and support both of these frameworks (and Flask, too), and I find my side projects might start with FastAPI until I need a database, and then nothing beats the Django Admin IMO.

As far as benchmark websites go, the website you mentioned pegs Django at making 9200 requests a second. Which is something like 33.1 million requests an hour (give or take my bad math.)

I have been doing this for a while, and I have only ever seen one website exceed that, which was 75 million hits in an hour with a 7.5 million an hour average, then it probably fell to maybe 10k requests an hour. That website was a total outliner compared to other high-traffic websites.

Django was just fine, but you aren’t going to have a website that big that doesn’t have a CDN in front of it no matter which framework or platform you use. I think the webserver maybe saw a few hundred requests over that hour because of caching.

So I would optimize for readable code and use the framework that sparks the most joy for you. Maybe that’s Django.

4 Likes

Django is not slow. Instagram was built on it, and all these years later they’re still using the core request-response handlers.

There’s a nice Django Chat episode on this: https://djangochat.com/episodes/django-instagram-carl-meyer

Can i use django for a high traffic project ?

I don’t imagine you’ll serve more traffic than Instagram.

3 Likes