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:
- 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.
- 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.
- 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.
- 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:
- 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.
- 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.
- 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: functional programming, haskell, openomy, web services, xml