Playing with BeepBeep and Flickr

I love playing with Erlang. I don't have much occasion to use it, but then a perfect opportunity presented itself. Meg and I bought a house, and me being the eternal geek that I am thought it'd be fun to build a site that aggregates all of the content we generate on our blogs, flickr, etc., that have to do with the house. I could write a site in PHP that does this in a few hours, but where's the fun in that? Instead, I've decided to implement it in BeepBeep, a new Erlang, convention over configuration framework.

If you're not familiar with BeepBeep, don't worry—not many people are. It's the framework I would have built for Erlang had Dave Bryson not done it for me. It uses MochiWeb for HTTP, ErlyDTL—an Erlang version of the Django Template Language—for templating, and a router to translate URLs into a controller and action. The result? This:

Ok - so it doesn't look like much, but those 20 images are being generated off of this feed of photos from Flickr. It's nothing special, except that I had never worked with xmerl until this past week and it'd been nearly a year since I'd done anything with Mnesia. What do those have to do with Flickr? Well, there's no Flickr module for Erlang (yet), so I have to parse the raw XML that Flickr generates and I don't want to do that every request, so I'm using Mnesia to cache the photos from Flickr locally.

I had originally started out with an in-memory cache for the photos, but this evening I rewrote the entire lib_cache module of my app to use Mnesia. I still need to do the code that handles expiration, but that's coming. Once I have that in place, I'll be ready to rock. I don't have OmniGraffle installed on this computer or I would do up a diagram of the code. I'll save that for another post. :-)

Concurrency oriented programming is definitely fun. At Ning, we're always keeping an eye out for that sort of programming because of the volume of users we have to deal with. Why make a user wait when you can spawn off job in the background to do things like update caches, change data structures, and so on? The fact that we're doing this in a language such as PHP just goes to show that it really is what you're doing with the language, not the language itself, but there's a part of me that wonders what would happen if a site like Ning was coded in a language such as Erlang that's built for concurrency.

But I digress. I've got some cool plans for my little BeepBeep site. Keep an eye on this space for more articles as the site comes together.