Django vs Rails: Picking the Right Web Framework

Django vs. Rails

Python/Django and Ruby on Rails are two of the most popular frameworks for web application development. Both allow for the rapid development of web applications, boast support from a broad community of developers and are entirely open-source.

The speed and performance differences between the two are negligible, with massively popular services built on each framework. So why would you choose one over the other? In this article we explore the advantages, similarities, and pros and cons of these two hugely important frameworks.

Language

Rails uses a language known as Ruby, released in 1995 and designed by Yukihiro Matsumoto. Ruby is an object-oriented, general purpose programming language. It’s a language known for being enjoyable to write – created with an emphasis on the ‘joy’ of writing it.

Django uses Python, designed by Guido van Rossum and released in 1990. It is also an object-oriented, general purpose programming language. Python emphases clarity and readability, it’s a language that is easy to learn and fast to write.

Syntax

Ruby’s syntax is somewhat flexible, this may seem like an advantage but can create difficulties as it is less easy to read. One feature can be achieved many different ways, this makes projects harder to pass on to new team members and teams.

One of Python’s guiding principles is that “There should be one– and preferably only one –obvious way to do it”. In contrast, with Ruby there are many different ways to achieve a feature. This makes Python code far easier to debug and read. With less idiosyncrasies and more standardisation, Django projects written in Python are easier to ramp up on and pass onto new team members.

Popularity

A big win for Django/Python is the popularity of the Python language. It’s already one of the most popular programming languages, and according to the latest research from Stack Overflow this popularity is growing faster than ever.

Python is commonly taught in universities, and is popular in the academic and scientific communities, making it easy to find graduate Python programming talent to train for Django development. In the Python ecosystem, libraries that support scientific/academic work such as NumPy and SciPy are extremely popular, and are used by 47% of Python developers. With Python there are also a range of integration tools available for working with ubiquitous software like Microsoft Excel.

This popularity means there are huge amounts of libraries and packages available for Python/Django that can be leveraged to get features built quickly. Resources and guides are available for achieving a lot of functionality, the chances are if there’s a feature or issues you’re facing – someone has faced it before and there is a pre-discovered solution out there.

Ruby on Rails boasts a vibrant community. However the sheer scale and variety of the Python ecosystem gives it a clear advantage for a wide range of tasks. Python is well suited to tasks beyond web development, with many libraries for data analytics, data science and machine learning.

According to the latest research from JetBrains, data analysis is the most popular use of the Python language, with web development and machine learning in second and third place respectively. Many of the most popular machine learning and big data libraries are written in Python. The language is ideally suited to big data analytics and manipulation tasks that are becoming ever more important. This means Django can be strongly leveraged when building big data tools as it uses the same language (Python) across the board.

Companies

Many large and popular platforms are built on both of these platforms. Django is used by popular internet services such as Instagram, Pinterest and Bitbucket, to name a few examples. While Ruby on Rails is used by Twitter, Github and Airbnb, amongst many others. As is proven by the stability of these platforms – these are both web frameworks that can be used at serious scale, handling hundreds of millions of requests and users.

Similarities

Ruby on Rails and Django share a lot of similarities. Both are open source, written in languages that are object-oriented and dynamically typed. The speed difference between the two frameworks is negligible and both use an MVC architecture. Ultimately it’s the design philosophy and programming language behind each which makes the overall difference.

So, what are the pros and cons of each framework?

Ruby on Rails Pros

  • Ruby is a more flexible language (this can also be a con – explored later!)
  • Faster to spin up new projects
  • Less code to make things happen
  • Web development popularity edge. Large ruby on rails community, almost entirely web development focused
  • Migrations are easier
  • Easy to deploy

Ruby on Rails Cons

  • Easier to build technical debt
  • It’s too flexible: one feature can be achieved many different ways, therefore can take longer understand how code works. Also can take more time to ramp up on projects and pass them to new teams.
  • Because less code and conventions to follow, sometimes code works and it’s hard to know why, how to fix the problem or modify it.
  • It’s bloated – Rails is bundled with a lot of unnecessary code, less senior Ruby developers may not understand much of what it does.
  • Ruby doesn’t do much else than web development well. No data analysis/big data functionality/ libraries like Python
  • Nothing in Rails ecosystem that’s comparable to Django REST framework for API development

Django/Python Pros

  • ‘Batteries included’
  • Python is a more versatile language
  • Tighter syntax
  • Fewer idiosyncrasies than Rails
  • Ships with comprehensive Django Admin portal for managing backend via GUI
  • Hiring: Python programmers easier to find than Ruby – one of the most popular programming languages. Great for new graduate hires.
  • Strong middleware layers out of the box
  • Projects can be passed along easier, due to standards-based code. There is only one way ‘right way’ of achieving something.
  • Less ‘magic’ – easy to understand how code works.
  • Python is well suited to other tasks beyond web development, and has many libraries for data analytics, data science and machine learning. Django can be strongly leveraged when building big data tools as it uses the same language (Python) across the board.
  • Very fast but not bloated (no magic)
  • Django REST framework – one of best tools for building APIs.
  • More powerful and comprehensive 3rd party libraries
  • Secure: Great security and user authentication tools baked-in
  • Scalable: caching system
  • Soon Django will be fully integrated with Channels: an asynchronous layer beneath Django for handling websockets, chat protocols and IoT protocols.

Django/Python Cons

  • Monolithic architecture
  • Not asynchronous by default
  • Maintains backwards compatibility – therefore updates move slowly.
  • Monolithic and all components get deployed together
  • Overkill for smaller projects

Conclusion

At Tivix, we strongly recommend Django, the ‘Web framework for perfectionists with deadlines’ certainly lives up to its name. While it can be overkill for small projects, it’s the ideal framework if you want to quickly build performant web applications that are easy to maintain. Django’s bundled middleware contains so many handy features – and makes building web applications much more efficient. The Django framework scales well, is secure and can easily be passed on and maintained by new teams.

With Django there are many cookie-cutter projects that you can choose from and within minutes you can have a base project using bootstrap-based CSS / Nginx / uWSGI / Travis-CI configuration and many more out of the box. Or you can choose to write a cookiecutter project and use it all over your projects. It’s also a great choice for agencies or any company starting many web application projects as it saves lots of ramp up time for developers.

Ultimately the ‘magic’ that makes Ruby on Rails so exciting can prove a big hurdle for building easily maintainable web applications. It’s flexibility is it’s downfall. For API development Ruby is firmly in second place, Django’s REST framework is an unparalleled tool for building APIs. Ruby is undoubtedly a rock-solid framework with a passionate community and many excellent features around migrations and easy deployment, however when compared to the advantages of working with Django, Ruby on Rails falls short.