Learnings after using Django for 5 years

Learnings after using Django for 5 years

The TLDR answer:

  • Even after 15 years, it is one of the best Frameworks in the market which can handle everything from rapid prototyping to a million request scale.
  • Truly stand by the motto - "The web framework for perfectionists with deadlines."
  • Best documentation when it comes to how the framework works.
  • Django ORM is a de-facto standard for me when I choose ORM in other languages or frameworks.
  • You get addicted to the migration feature which comes out of the box.
  • Django signals are one of the most underrated features.
  • Django auth makes you follow the best security practices out of the box.
  • Celery is required to build scalable products in Django.
  • Django Rest Framework is the default standard when it comes to building any modern web application in Django.

The Detail answer:

Django remains one of the best frameworks after all these years-

Django is a python framework, so anyone who has some knowledge of python can easily pick up Django when they want to build a web application. In the last 5 years or so we have seen a drastic adaption of Python language in the developer community, this is majorly due to advanced machine learning and data science. So whenever someone learns python for these purposes they start looking to learn how to build a web app to deploy these. Whenever they start looking for web frameworks in python, they majorly stumble upon flask or Django, since they are the pioneer in this field. With more and more new members adopting the Django framework, the community grows stronger and hence they keep on updating the framework. In the past couple of years, I have seen few drastic changes which keep Django as one of the favorites

  • Async feature to Django- We all know python is not build for multithreading (thanks to GIL 😒), but in today's modern world async or parallel processing is a defacto standard, so DSF (Django Software Foundation, governing body for any change in Django) understood it and started to incorporate this features in Django 3.x and kept the framework up to date to the latest trend in the developer community.

Django is used by startups as well as companies at scale. Few notable mentions are Disqus, Instagram, Mozilla, Pinterest, Sentry.

The web framework for perfectionists with deadlines.

We all can agree that when we are building new products, especially in startups, we always have strict deadlines and need to be agile, where every week if not daily, the product would see some new transformation. And being a developer we hate building any half-baked feature. Here comes Django to the rescue, it gives us all the basic/advanced features which any early-stage product would need. It provides us with  Authentication, Admin interface, Migrations, Jinja templating engine (though I would suggest not to use it since this might become a headache soon)

Best documentation

Maturity pays off, that's what has happened with Django. Since it has been around for so many years, the documentation has evolved to be one of the best in the industry. One thing I hear from people starting Django is, there aren't enough blogs in Django, they don't understand that blogs will become obsolete, but official documentation is always up to date. And one of the reasons why there aren't enough blogs around Django is because the documentation covers all the points in detail, so why would some repeat the same information.

Django ORM

I started my career as a data engineer, majorly working in ETL pipelines, so SQL was bread and butter for me. Naturally, when I moved to web development, I was always inclined towards doing most of the computation at the database layer, rather can doing it in the application layer, which also is the right way to build web applications, try to always do most of the computation in the DB layer.

I haven't found a single scenario in all these years where Django ORM has let me down, I could always do anything and everything from the Django ORM layer. I have become a spoilt brat, nowadays whenever I explore new frameworks or work on different languages, I would always try to compare if the ORM can satisfy all the cases which Django does. And the most important thing, Django ORM is a package out of the box, so there is no additional overhead of new packages.

Django Migration

Django migration has to be one of the USPs for developers to stick to Django. If you have worked with Relational databases, you know how painful it can become when you have a large team and you have to do migrations on the database. Most of the time the production, staging, and local setup are never in sync with the DDL which people are using. One has to create a strong project in the project development cycle to ensure that nothing breaks randomly and developers have the freedom to perform migration operations.

Django migrations help us solve all the above problems seamlessly. Migration files are created automatically by the use of a single command. And the timeline of every migration is captured in the django_migrations the table which can be treated as the source of truth.

Django Signals is underrated

When I started learning Django and writing production code in Django, I had stumbled upon Django Signals after almost 6-8 months. Finally, when I started to learn more and use it, I realized why the heck I didn't know it before, it solved so many problems, like circular imports, decoupling multiple applications, performing multiple operations when a certain task is being performed.

So to all the folks who are starting Django, learn about this feature ASAP, it will change the way you look at development.

Secure application with Django

There is no denying that security is the highest priority when it comes to developing any web application. I started my web development career as a self-taught developer, so naturally, there wasn't anyone to tell me the best practices and all things to follow. Django came to my rescue since authentication and security came out of the box so automatically I read everything around authentication. All the hunches and guess of how systems should work was validated by the implementation of authentication, authorization and security features of Django.

At times I got deviated to drop default Django authentication to pick JWT, but later I realized all the pitfalls and corner cases that Django solved. Django gives you CSRF protection, XSS protection,  block SQL injection, session-based authentication, etc out of the box.

Celery and Django are best friends 👫

As you progress learning Django you would realize that Django alone is not enough to build a scalable application. You would find use cases where certain tasks need to be performed at a particular time. Your first instinct would be to implement default Linux-based cron, but you would slowly realize that Linux cron jobs are not scalable. At certain times you will have few long-running tasks which need to work asynchronously, the first suggestion you get when you will ask this problem is, start using AWS lambda, though this solution works, you would realize that you want to use the same codebase where your Django lives so that you can follow DRY and also code is maintainable and it gets updated.

Wolla!! Celery and Celery Beat comes to your rescue, you can now use all the code which you have used in your web application and make use of the features of Django, like ORM, etc, without introducing any drastic change. You will need to add 3 new components, Redis, Celery, Celery Beat. All three of them are infrastructural setup, so once you do the set up the whole team would simply have to write the code for business logic, without worrying about the infrastructure changes which is involved with cron jobs and AWS lambda.

How to setup Celery with Django?
Celery is an asynchronous task framework that can be used to perform long-running jobs required in the Django web application

DRF is for modern applications

Those days are gone when you write code only for desktop browsers. Now every business needs a multi-platform presence, you need to build applications for the android platform, IOS, IoT, Browser, etc. Django was built 15 years back, so that time most of the clients were browser-based, so Django was able to cater to all the needs of that time, but with more adaption of technology, now even browsers have improved, people have started to use Single Page Applications like ReactJS, Angular, VueJS to serve the users a better experience.

Hence Django alone is not sufficient to build any modern application for today. Here come Django Rest Framework (DRF) to the rescue, everything in today's world is driven by API, and most of the time they follow the ReST protocol, so DRF perfectly fits this use case and helps us build the modern application seamlessly.