Optimizing Django for building high performance systems

Sanyam Khurana (~CuriousLearner)




Many amateur developers who picks up Django write code which seems to work, but fails at scale.

Django has been made as a The web framework for perfectionists with deadlines, and perfection is often forgotten due to deadlines. In this talk, we'll discuss about common pitfalls to avoid while working on a Django based web application. The talk would revolve mostly around the following:

  • Profiling our web application to know exactly what queries are being executed on the database.
  • Making optimal use of Django ORM to avoid multiple queries to the database.
  • Usage of F objects, Q objects, prefetch_related, select_related et. all.
  • Addressing n+1 queries problems to database with ORM.
  • Making use of Asynchronous requests to avoid creating a backlog for the request-response cycle. A little bit about task queues like Celery.
  • Caching: Different types of caches to use -- both django caching as well as something like in-memory Redis cache.

In the end we'll look at an overall architecture of entire Django web application including wsgi, nginx, caching and database layer. This would provide a starting point to write clean code and optimizing Django Applications to the audience


  • Hands-on experience with developing Django Applications
  • Basic understanding of Django ORM including usage of Querysets and Managers.

Content URLs:

Slides: http://www.sanyamkhurana.com/presentations/django-optimizations/

Slides for the talk is work in progress and would be updated on the above link

Speaker Info:

Sanyam is an Open Source Contributor from Delhi, India. Mostly goes by CuriousLearner all over the web. He contributes to various upstream projects in different organizations & maintains a few of them. He has contributed various patches and bug reports upstream to Gecko Engine from Mozilla Organization.

He is a vouched Mozillian & an official Representative of Mozilla and has been listed in AUTHORS as well as credits section of every browser ever released by Mozilla. He mentored for PyDSA in RGSoC 2017. He volunteers for PyCon India and PyDelhiConf and has been an active member of PyDelhi, ILUG-D, LinuxChixIndia and DGPLUG.

Section: Web Development
Type: Talks
Target Audience: Intermediate
Last Updated:

Good stuff @sanyam.

Manjit Kumar (~manjitkumar)

Thanks @manjitkumar!

Hope to see you this year at PyDelhi Conf :)

Sanyam Khurana (~CuriousLearner)

Hi! Could you please add up slides to your workshop/talk?

Shivani Bhardwaj (~shivan1b)


Although it's a work in progress, I've added the slides for the talk.

Sanyam Khurana (~CuriousLearner)

Login to add a new comment.