Dev.Junction 6 Tips for Building HighQuality Django Apps at Scale Save For Later Dev.Junction Introduction Django is a robust framework, it is used by companies like Disqus, Instagram, Pinterest, Bitbucket, etc. Let's have a quick look at some of the things that can scale your application easily and help you improve performance. Dev.Junction 1. Query Optimization Use select_related, prefetch_related for SQL join operations instead of running multiple queries to get data from related tables. Use bulk_create, bulk_update for the creation and updation of many rows at once. Monitor the ORM queries using the django_debug_toolbar plugin. Dev.Junction 2. Connection Pooling Using PostgreSQL or MySQL? pool your database connections depending on the number of users hit. CONN_MAX_AGE is the parameter you can set in your settings.py to specify the age(integer) of a persistent database connection. 0 means close the connection just after the end of each request, None is never close a connection. Dev.Junction 3. Middleware Audit and remove unused middlewares from settings.py file. Apply ConditionalGetMiddleware, GZipMiddleware, and FetchFromCacheMiddleware for more improved response time. Note: Be careful with GZipMiddleware. Dev.Junction 4. Caching You can apply to cache so that your application will not be querying the same data for each request. In Django, You can apply to cache on the whole Site level, the View level, template level, or at a template fragment level. Django comes with prebuilt Memcache, Db Cache, file-based cache & local memory cache support. Dev.Junction 5. Distributed Task Queues Use Celery or Django Q with robust task brokers such as RabbitMQ for the tasks which are going to take a long time and are assumed to be asynchronous in nature. Do not perform long-running tasks inside your view directly, always use task queues to transfer the load. Dev.Junction 6. Apply Indexing An index is used to speed up data search and SQL query performance. The database indexes reduce the number of data pages that have to be read in order to find the specific record. Indexing makes columns faster to query by creating pointers to where data is stored within a database. Dev.Junction Follow Me, for more awesome content related to Programming, Development & Freelancing.