Wednesday, May 30, 2012

Techie Stuff: Django on Google App Engine vs Amazon EC2

I am not a sys admin and I really hate sys admin-y things. I'm a coder. I just want an environment that works and that can run my code. Period.

That makes Google App Engine extremely appealing. You have zero sys admin responsibilities in the App Engine world. This is a godsend to me. My first business, EssayTagger.com, is happily running on App Engine. But as with all things in life, there are tradeoffs.


Django + App Engine = sigh
As I'll detail in another post, I've recently become a huge Django convert. What takes me 1000 lines to do in Java/JSP I can do in 10 lines in Django. It's 1000% amazing. But it's not a great fit for App Engine. Boo.

For years Django has been crippled on App Engine due to App Engine's flat datastore; without a SQL backend to connect to, Django had to be hacked and modified and abused to work on App Engine.

The good news is that Google's Cloud SQL is (supposedly) coming out of its limited preview period on June 12th. I was able to get EssayTagger in on the limited preview back in October 2011 and have been running it as our production DB ever since.

The full launch of Cloud SQL means that Django can now be fully supported on App Engine. This is big. This means that Django on App Engine is a slam dunk, right?

Not so fast.

App Engine currently (v1.6.6) only supports Django 1.3. Boo. Perhaps they'll rev up to Django 1.4 on June 12th to coincide with the Cloud SQL launch. But I don't like sitting here just crossing my fingers, waiting to see what Google will do.

You should be able to run any version of Django you want (once Cloud SQL becomes generally available) by including the Django source with your Python app; Django is, after all, just another Python module. I'm naturally cautious though so I fear this approach. It just isn't common enough and I haven't seen enough documentation and/or tutorials out there to go this route.


Django + Amazon EC2 = Yay! But...
By contrast I can get an EC2 instance up and running and configure it however the heck I like. Need Django? Here ya go:

Install pip:
$ sudo apt-get install python-pip

Then use pip to install Django:
$ sudo pip install Django


Done and done!

But there's a "but." The EC2 world gives you clean instances that look and act just like your own linux box sitting in a server rack somewhere. That means that in the EC2 world I have to be a sys admin. Boo.


I barely have any clue what I'm doing as a linux sys admin. I know just enough UNIX commands to move around and create directories, use nano to edit files (the other editors scare me!), work with the mysql command line interface, and configure and manage Apache.

I spent about three days just getting celery to talk to rabbitmq and then setting it up to run under supervisord. The sys admin world is frustrating as hell. The documentation and tutorials have gotten a whole heckuva lot better in the last decade, but this is still a world that I'd rather have nothing to do with if I could.

Oh App Engine, I already miss you!


And so the winner is...
For me Django 1.4 is a non-negotiable must-have. That means, for now, EC2 is my only choice.

Will this change if/when App Engine adds Django 1.4 support? Possibly. But there will still be other considerations. For example, my first μ-Dev project is going to require the django_facebook module. On EC2 I can just run:

$ sudo pip install django_facebook

Sweet. But on App Engine I'd have to include the django_facebook source code as a Python module that lives within my Django project. That's not the worst thing ever, but the various dependencies worry me.

django_facebook requires the Python Image Library (PIL) which turns out to be surprisingly difficult to install (though I did succeed on my MacBook). We're at the mercies of whichever version of PIL App Engine supports (assuming it supports it at all). As with all things with App Engine, it's totally out of our control.

I feel like I'm between a rock and a hard place here, but with Django 1.4 being a must-have, the decision swings instantly to EC2. All the sys admin-y crap required on EC2 sucks, but there is a lot of guidance out there (and I'll post my own setup steps here).

Scalable, load balanced EC2 instances hitting a MySQL instance on RDS seems like the winner thus far.

Now someone just help me with securing my EC2 instances!