Google App Engine

I’m still working on this iphone game with a fellow iphone developer and another guy doing the graphics. As we get closer to release, I’m looking into how to implement an online top scores engine. It’s quite a complex problem. Here’s a few considerations

  1. Do you always submit the user’s score to an online server?
  2. How do you submit the score so that no one can snoop the traffic and spoof fake top scores?
  3. What kind of resources are required to handle score submission and top score retrieval?

For point 1, so far I’m asking the user for a username and email address, and only submitting the score if the email is filled in. For point 2, I have something in mind using a hash function, but haven’t fully decided yet. Point 3 is the interesting one. I read a recent interview on Mobile Orchard with an iphone game developer, and he said that he was relieved to have chosen to implement his top score engine using Google App Engine. Once a few thousand people are using your game, the load on a scoring server can be quite high.

Google App Engine is a confusingly named google service, mainly because google also have ‘Google Apps‘ which is not the same as ‘Google App Engine’. ‘Google Apps’ is the name for the bundling of Gmail, google docs, google calendar, google sites etc. Google App Engine (AppEngine) is a virtualised service cloud thing, a bit like Amazon EC2,  except it uses google’s servers obviously, and perhaps the dealbraker for a lot of people; your app needs to be written in Python. I guess its a bit like if your web hosting provider only let you write cgi scripts in python … well sort of.

The really good stuff about AppEngine is that you can use it for free initially, though there are billing options if you use a lot of traffic or CPU time, and it seems quite fast. So I started looking into it as a platform for a topscores engine. I’d already hacked together some code for doing topscore submission and checking using PHP on a backend server of my own. So how to convert that into Python?

Well for starters I needed to learn Python. Yes, I am a sysadmin and I haven’t looked into Python at all in the past few years. Yes I too read that it was meant to be great 😉 So I had a look at the Oreilly Learning Python book. That got me started. The key observations about python;

  • looks very object oriented
  • indentation is important (this is about the only thing I knew already)
  • There is good doco on
  • Python noddies probably don’t like perl

For the AppEngine you download a small SDK that includes a demo web server that you can run on your own computer to test things out. There’s also a script to upload your app directory to google. Essentially you have a python script or two along with some static html/images or whatever you need for your app in a directory and just run the update process to update your app on google servers. I really like how a sort of version control is incorporated into this so that if you bump the version number up on your local copy, it won’t become the ‘production’ version of your app. There’s a dashboard control for specifying which version is the production one.

To get an app uploaded you first need to get an account with AppEngine. For starting off, you just use your gmail account (if you have one) and sign in. There’s a confirmation step that involves sending you an SMS with a magic number in it. I guess this is stop the AppEngine being abused and to also allow google to invite you round for dinner if they like your Python program. Google keeps track of the phone numbers used for these SMS’s and suffice to say you can only use a phone number once to receive an SMS.

You also can only create 10 applications. I imagine that might change in the future. You have to pick a unique name that no one else has picked. Your app becomes or whatever. You upload your python code and other related files and it just works.  If you don’t want to use the domain you need to sign up for google apps using your own domain name and then use your google apps admin account to sign up for the Google App Engine. Then it is reasonably flexible how you redirect subdomains to your app.

So within two days I’ve learnt a bit of python and set up a rudimentary top score engine on Google App Engine. I’m quite impressed. Note, that they have added in billable options recently and I’m not sure if the ‘free usage’ thresholds have dropped.

It’s actually encouraged me to look at Python more closely (a bit like how buying a Mac has enocuraged me to learn Objective C). All good so far.