Shawn Ng

Rails VS Django VS Express

In this project, I compared the top 3 popular web application frameworks: Ruby on Rails, Django and Express.

Rails vs Django vs Express
Image Credit: Source

Project Overview

My earlier projects are USA-centric. This time, I decided to focus on China, the world's 2nd largest economy, with 19% of the world's total population.

To compare the top 3 popular web frameworks (Ruby on Rails, Django, Express) in details, I will create a China Emperor (CE) database.


Frameworks comparison
Score from 0-3. 3 being the best, 0 means not available. Same points for each feature is possible

These 3 frameworks have different strengths. If the goal is to build a simple web app (such as this website), I will choose Rails.

I will choose Django if I am building a business where data collection is a priority.

Express is a minimalist framework. It means that I have to understand, choose and maintain individual components. I can build the same product using Rails and Django in a shorter timeframe. However, if my business requires a mobile app, Express might become the best choice, because building a progressive web app (PWA) requires JavaScript framework/libraries.

Web app size comparison

All app sizes
All web app size
  • Based on app size, Django is the smallest while Express is the biggest. These images show why I give Django 3 points and Express 1 point.
Rails app size
Rails web app size
  • We can reduce Rails app size to 1MB if we clean up the tmp folder constantly.
Django app size
Django web app size
Express app size
Express web app size

NPM is 1 of the biggest strength of Express app, but it appears that it's bloating the app.

Database design

After thinking for 10 mins, I decided to create the 3 tables for the CE database: Archetypes, Dynasties, and Emperors

Archetypes and Dynasties are lookup tables. They store all the possible personality archetypes and dynasties details respectively.

Rails diagram

China emperor rails
Rails CE database design

Django diagram

China emperor django
Django CE database design

Express diagram

China emperor express
Express CE database design

When I was building Rails and Django CE web app, I restrict the number of characters for specific columns. Because I am careful and I am not 100% confident with the validation tests.

I shouldn't have done this premature optimization, but I did it because I love lean, mean killing machine. Therefore, Express CE web app doesn't have this restriction


Archetypes list

Django express archetypes
Archetypes list

I created the 3 possible archetypes for emperors: Conqueror, Builder and Mediocre

You can understand what each archetype means from their descriptions.

Dynasties list

Django express dynasties
Dynasties list

For all the columns in dynasties table, only Dynasty length column is a calculated field:

Dynasty length = End year - Start year

I stored the value as a column in the database, which I regret now. The idea I have when I design the database is this:

SELECT * FROM dynasties WHERE dynasty_length > 200;

Instead of:

SELECT * FROM dynasties WHERE end_year - start_year > 200;

But now, I have to write the query like this:

SELECT * FROM dynasties WHERE CAST(COALESCE(dynasty_length,'0')) > 200;

because I chose the wrong datatype for the year columns. I should have used datatype INTEGER instead of VARCHAR for the year columns. I used VARCHAR because I was thinking of storing the date in VARCHAR. But I forgot since I already restricted the year columns to 4 digits (YYYY), it is impossible hard for the users to input the wrong year

To ensure data integrity, if I want to store calculated fields, I need to have bullet-proof tests to ensure that the users don't input data that I don't foresee. It will be a cleaner solution if I do the calculation at view instead of the model. At least if the data is wrong, I can see it on the UI. The database will be error free.

Emperors list

Django express emperors
Emperors list

Rails in-depth

Rails archetypes
Rails archetypes list
Rails dynasties
Rails dynasties list
Rails emperors
Rails emperors list

What I love about Rails:

  • Scaffold helps you generate model, controller, and view (MVC), with default CRUD. All you have to do is to update the CSS to make it look good
  • Configurations are of pre-configurated, all you have to update is database configuration and which routes to use, and you can focus on building the actual product
  • Clean directory structure as you don't need to build custom configurations

Django in-depth

Django admin
Django admin page
Django user auth
Django user authorization settings
Django admin emperor form
Django admin emperor form

What I love about Django:

  • The admin dashboard is too awesome. I can't imagine building an admin dashboard from scratch
  • Users & groups authentication and authorization require a lot of engineering work as you need to think about the type of permissions and the security hash to store passwords securely. And Django offers you all these features by default
  • Django model and admin form have no match

Express in-depth

Express gives me nothing but pain

No bias here, because I like JavaScript and I'm decently good with it.

Questions about the emperors

Q1. Ying Zheng (Qin Shi Huang) is the 1st emperor of China, why is he a builder and not a conqueror?

He is born as the prince of Qin kingdom and become the king at the age of 13. He conquered all 6 kingdoms and unified China. He is the 1st emperor of China. He inherited the Qin kingdom, which becomes the foundation of the Qin dynasty. In my opinion, he is a builder and not a conqueror.

Q2. Since when is Cao Cao an emperor?

He has the power of the emperor, even though he doesn't have the official title. As I value actual power over the title, I consider him an emperor. And because I like him.

Final thoughts

From this project, you see the mistakes that I have made because I don't spend more than 10 minutes thinking about the database design. Lucky this is a learning project and not an actual multimillion/billion dollar startup. Then again, if this is a real business, I would be 1000 times more careful. It will be a bad joke if you destroy your empire before your enemies come

So, have you decided which framework is the most suitable foundation for your empire?

Published: 2018-12-08 | Updated: 2021-04-02

Share this!