Lessons Learned: Building a simple Ad Host with Grails on the Google App Engine

In this post, I share my experiences building a simple Content Host with Grails and the Google App Engine.


We’ve been pumping up the volume at Pixsta promoting Empora – our visual search engine for fashion items written in Grails.

One of the recent tasks I’ve worked on was to build a series of banner ads in Flash to showcase the colour search feature. Within the site, you can specify a colour or category, and it would let you browse similar items via our unique PhD-powered visual search algorithms.

It was very interesting that nobody in our teams had worked with ads or ad networks before. So we had to quickly learn all about this business very quickly. Fortunately, it also meant that we could make some mistakes – which fortunately there were few – and learn from them.

Building the Ads

The final ad that Mike, our graphic designer, and our product team came up with looks like this. ( Warning – flash file, original size is 300 x 250pxs ). You can see one in action at my lovely big feet.

The ads themselves were not difficult and took less than a couple of days to do in Flash. I used the standard Flash components for the display objects and the Tweener library to animate the transitions.

What was challenging was really meeting the different and undocumented requirements from different ad networks about Flash ad formats. It was hard not to lose your temper after getting two or three conflicting versions from the same company, or getting documentation sent to you by an ad network a couple of days after you have finished building your flash files. I definitively learned a lot more about clickTags, flash versions and the world of ad networks than I ever really wanted to know.

I had built an initial prototype in Flex, but quickly rewrote it in Flash as we couldn’t get file sizes small enough even after using the RSL mechanism. Flex still has a lot of work to do to make Swf files smaller.

Hosting the Ads.

Most of the bigger ad networks had their own tracking mechanisms and would host our ads on their networks as long as they met certain size restrictions ( 40k and 100k ). Some of our ads needed to be retooled to fit within certain guidelines, and I had to create several versions of each ad in different sizes, colour combinations and click out requirements.

For smaller blogs, they requested that we host the swf and backup image files ourselves. We had to come up with a solution that was quick, efficient and powerful enough to handle large amounts of traffic.

I had come across an article about using the google app engine as a content delivery network about a few months ago and have been wanting to try out this approach on Flex / Flash files. I’ve been playing with Grails and the App Engine a lot on my spare time, and suggested this to the team.

Google App Engine – Advantages

There were several advantages I saw to using the App Engine that made it perfect for our simple ad server:

  • Almost unlimited bandwidth on demand: We could always buy more, and with an initial allotment of 4 gigabytes free a day (paid quota ) and $.12 per gigabyte transfer over that, it seemed like a perfect solution for us. We weren’t sure how much traffic we were gong to use, so the app engine provided a no-commitment answer for our ad hosting.

    Compared to cloud solutions like Amazon ( $70 per month ) or  content hosting like Akami ( contracts / service terms required ), the app engine made sense as an initial testing bed for our ad hosting.

  • No Server Setup Required: With a traditional hosting solution, we would have had to set up a FTP account or an Apache server to deliver this content. If we wanted any sort of server side scripting, this would have had to been set up and would have taken time away from our system administrator.
  • Grails integration: We have a lot of in-house expertise in Grails – and it was nice that the AppEngine plugin allowed us to use this expertise, just in case we needed to add something more robust. With this project, we were uncertain about some of the  tracking requirements, so it was nice to have the option of having GSPs, templates and all the other Grails goodies just in case we needed to expand the functionality of the ad host. It’s never a bad idea to have an enterprise level solution in the back pocket, just in case.
  • Quick deployment: The app engine plugin allowed us to quickly add our content to be hosted, package it into a war file and have it running on the server within less than 20 minutes of creating the initial application.
  • Ease of Administration: Compared to many build-your-own solutions, it was very easy to add additional developers into the application.

Embedding Flash Files

In the code we provided our ad hosts, we simply used SWFObject to include our SWF file. Using SWFObject allowed our ads to fallback into gif files in the case where Flash or JavaScript was disabled. We wrote a little bit of additional javascript so that we could differentiate which client and campaign were being tracked.

Ad Tracking

I wrote a simple grails page that would invoke google analytics with the correct tracking details. We were already using Google Analytics to track clicks, and it was very easy to just include a piece of javascript that would track all our ad impressions. [ code here ]

Did it Work?

What started as a simple experiment in hosting a few flash files that had to go up quickly rapidly became a test of how the Google App Engine would perform as a RIA hosting server.

Our marketing team got our banners on one of the newspapers websites, and we went from serving about one thousand ads a day to five digits ad impressions in one day.

The App Engine performed admirably. The only hiccup we experienced was setting the initial quota too low, and we quickly ran out of bandwidth. After a simple billing change on the server that took effect in 15 minutes, the ad serving continued.

On some days, the outbound traffic would hit more than fifteen gigabytes, but we had not had to restart our Grails server at all since the initial deployment and while we see spikes in memory and CPU use, there seems to be very few issues with the app engine as a content delivery server. Also, it is reassuring to see that fifteen gigabytes cost less than $2 in the billing reports.

It was definitively a good choice to do this in Grails. We had vague tracking requirements at the beginning of the project, and were able to implement a fairly robust if simple tracking system in less than a day.

Going Forward

This project shows that the Google App Engine is a solid solution for hosting dynamic, high bandwidth content such as Flash movies. Given the ease by which we can develop Grails applications, it would be interesting to build out a nice simple GUI for managing and uploading ads into the Engine without requiring a server restart.

One of my main frustrations working with Rich Media ads is that the specs given by current ad hosts make them nothing more than glorified animated gifs. It would be interesting to explore the building of more robust tracking and clickTag mechanisms for RIAs and widgets. It would also be interesting to explore alternative ways of displaying ads such as via HTML5’s canvas and video tags and see how they compare to Flash.

The prices of the ad engine definitively make it a very good candidate for rich, dynamic content. We see that Grails is able to scale up to many clients for simple GSPs that spit out data. However, it is still unclear as to how versatile dynamic flex applications with a complex domain model would perform on a platform such as the App Engine. Given that the app engine would time out a request if it takes too long to complete, it would be interesting to see how data-heavy RIAs would perform in this environment.


2 thoughts on “Lessons Learned: Building a simple Ad Host with Grails on the Google App Engine

  1. Mike

    Great idea, thanks for sharing. 6 months ago I developed a fairly large Grails site and integrated in Google Ad Manager. The results were disappointing to say the least. It was very hard to predict when changes would take effect and sometime criteria for serving ads would be ignored. The app is hosted on EC2 and we used cloudfront and S3 for simple CDN capability. Had considered building custom or running Openx on EC2 but that would have incurred greater EC2 cost. Note that this was a little different, primarilly for serving ads within the site.

    How is the latency and downstream bandwidth performance in general on GAE?



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s