Wednesday, November 18, 2009

NuGram - an architecture worth pondering

Dominique Boucher was kind enough to document the architecture of the NuGram web service. It's an interesting mixture of Scheme and Erlang, and serves as an excellent reminder that there's more approaches to developing scalable software than just Apache + MVC (aka: PHP, Ruby, Java, etc.).

The part that really got my attention, though was:

Most requests to the RESTful API are done in the context of a session. Each session is associated with an Erlang process and the application keeps a mapping between the session ID and the process for the session in the Mnesia database (it is rather cool to store things like process IDs in a database!). So when the application receives a request, it extracts the session ID from the request URI, finds the corresponding process in the database, and simply forwards the request to that process.

Think about that: a request comes in, and you find the running process that is sitting around, ready to serve it. No process yet? Then create a fresh one. And when a session expires, you kill the process.

What a remarkable architecture (and so perfect for Erlang)! It provides an usual level of modularity, as you can effectively program a single process for a single interaction, and then let Erlang scale it all up.

From a scalability perspective, this is huge, as the system is designed from the ground up to work with individual processes - whether those processes are running on a single machine, or spread out among machines, I assume could be transparent.

As an experiment, it would be interesting to compare traditional session programming, versus 1-session-per-process (like above), versus web continuations. I wonder if one of those models is easier to program with than the other. And I wonder if one scales better than the other.

If nothing else, it makes for an excellent thought experiment.

Thanks Dominique!

Update: Dominique was kind enough to address the thoughts above on his blog. So check it out, he's got some excellent points.

2 comments:

  1. Hi Ben! I wrote a few more comments in reaction to your post:

    http://theschemeway.blogspot.com/2009/11/1-session-per-process-some-comments-on.html

    ReplyDelete