Monday, March 26, 2007

Building a Haskell Web Service

This is the first post in a series about implementing the next major revision of the Openomy external API as a web service written in Haskell.

One of the cool things about having a website outside of your normal job is the ability to experiment with different technologies. We've done this pretty successfully with Openomy: it started out as a monolithic C# mod_mono + mysql application that stored files on the local disk and has now evolved into a much smaller mod_mono frontend, 4 services (3 in rails, 1 in java) and backed by Amazon S3 storage.

The next part of the original application we wanted to reimplement was the handlers for the Openomy API. The current implementation was inflexible, hard to extend, and was poorly suited to our new backend infrastructure.

We chose to implement the API bridge in Haskell for a few reasons:
  1. You can model the external API as two functions: one that maps the client's input to the XML we send to our services, and another for our services return XML to our external output. This made us think that it may be fun to do it in a functional style.
  2. We were worried about library support, but it turned out that Haskell had all of the libraries we needed: a web container, a powerful and flexible way to transform XML, an http client, and simple cryptography libraries.
  3. After reading the paper on HaXml, I was really looking forward to using their combinator library to produce the XML mapping functions we needed. It seemed like a very powerful and flexible framework, without being as tedious and error-prone as working with other XML libraries in other languages.
  4. Most importantly, it would be the most interesting: I've been wanting to learn Haskell for some time now.
However, there were also a few arguments against picking Haskell:
  1. It's one of those languages that will stretch your mind, especially if you're coming from a mostly object-oriented programming background. Picking it for a major project is a large risk and may delay getting the new service out the door.
  2. Haskell is mostly a research language: the community isn't very large and we didn't know any people that had successfully used it for a mainstream application.
  3. The API bridge is heavily IO dependent (making service calls over HTTP). Haskell's monadic IO system takes a little time to get used to and understand.
About a month ago, I bought a copy of the Haskell School of Expression and started learning the language. Shortly afterwards, I convinced Ian to start learning it as well, and soon we had started. We were both a little nervous about it-- the day we started working on it, we observed that this may be the beginning of the worst software project in the years we've been working together. We've also been tracking how many times we've said "we're f*cked" during development. I'm sure we're well into the double digits by now :)

After a few initial bumps on the road, the project is moving along nicely now. The problems we had getting started will be the subject of the next post.

UPDATE: Part 2 has been posted.

Labels: , , , ,

3 Comments:

At 12:42 PM, Blogger Keith Lancaster said...

I've been learning Haskell, and was wondering how well it would work for a web service (specifically, doing a REST interface). I look forward to hearing about your progress. BTW, you have a typo in your categories: funcitonal...

 
At 2:23 PM, Blogger Cale Gibbard said...

The Haskell community might not be terribly large, but it's full of extremely helpful and knowledgeable people who are willing to answer questions and help solve problems.

There's quite a lot of us hanging out on IRC (about 320 users with about 44 active at the time I'm writing this). You should join us in #haskell on irc.freenode.org if you haven't already. It's very beginner friendly, and questions are often answered in stereo.

The mailing lists are also pretty good for getting answers to questions.

 
At 9:08 PM, Blogger Maurice Codik said...

I didnt spend too much time in this post talking about the community, aside from what I had assumed about it before I actually started the project. I tried to keep it in chronological order, so there will be more in an upcoming post.

I've spent a good amount of time on #haskell and #happs on freenode in the past few weeks. Although I was a little concerned about the size of it at first, people have been extremely friendly and helpful that its totally made up for it.

 

Post a Comment

<< Home