Monday, August 04, 2008

Erlang as middleware

Delicious is also using Erlang. Well, that's yet another addition to the Erlangy list of Facebook, SimpleDB, CouchDB, Twitter and many more. All these applications/services rely on the intrinsic scalability of Erlang as a platform. RabbitMQ provides an implementation of AMQP based on Erlang, ejabberd, an XMPP implementation is also Erlang based. EngineYard is also betting on Erlang for Vertebrae, its platform for Cloud Computing. It's like Erlang is carving out it's own niche as the dominant choice of service based backends.

I can make my application scale using distributed hashmap technologies of memcached or in-process JVM clustering techniques of Terracotta or a host of other techniques that treat distribution and scalability as a concern separate from the core application design. But with Erlang/OTP, I start with shared nothing concurrency oriented process design, which can naturally be distributed across the cores of your deployment server. What is a module in the codebase can be made to map to a process in the runtime, instances of which can be distributed transparently to the nodes of your cluster.

Why Erlang ?

Erlang is naturally concurrent, with ultralightweight processes based on green threads that can be spawned in millions on a cluster of commodity hardware. As a functional language, Erlang applications are designed as shared nothing architectures that interact with each other through asynchronous message passing primitives - as if the whole code can be mathematically analyzed. This is unlike an imperative language runtime that offers shared state concurrency through threads and mutexes. Erlang runtime offers dynamic hotswapping of code, you can change code on-the-fly, converting your application to a non stop system. Finally Erlang processes can be organized into supervisor hierarchies that manage the lifetimes of their child processes and automatically restart in case of exceptions and failures. And almost all of these come out of the box through the goodness of platforms like OTP.

But do we find enough Erlang programmers ? Well, the syntax .. umm ..

Isn't your OS mainstream ?

Then why don't you find chores of developers programming with the kernel APIs that your OS publishes ? The OS offers the service which developers use everyday when they open up a host of windows, manage their filesystems, send out an IM or open up the browser to get the latest quotes on their tickers. And all these, being completely oblivious of how the kernel handles scheduling of native threads to serve up your long running requests.

Erlang is becoming mainstream in the same context.

I do not need to know a bit of Erlang to design my trading service that can process millions of messages from my AMQP endpoints in real time. In fact while prototyping for the next version of a trading back-office system, I cooked up all my services using Scala actors, that happily could use RabbitMQ's Erlang based queue and exchange implementation through well-published Java APIs of the client.

I can still architect scalable websites that need not poll Flickr 3 million times a day to fetch 6000 updates, without an iota of Erlang awareness. The technology is called XMPP application server, which scaffolds all the Erlang machinery underneath while exposing easy-to-use client interfaces in your favorite programming language ..

Erlang is becoming mainstream as a middleware service provider. And, one could feel the buzz in OSCON 2008.

10 comments:

Anonymous said...

Any sources confirming that Twitter Facebook and Delicious use Erlang? (and no, Erlang blogs don't qualify :-))

Surely this can be traced back to the eng teams themselves? If not, I call shenanigans :-)

Anonymous said...

I'm an engineer at Twitter, and we no longer use Erlang. We were using Erlang as part of Ejabberd (the Erlang Jabber Daemon), but we don't at present. Please correct your post.

Anonymous said...

Sources for Erlang usage at Facebook:

http://www.facebook.com/jobs/engineering.php

http://www.facebook.com/notes.php?id=9445547199

Nick said...

At CUFP this year, there is a presentation by the engineers who developed the production Erlang code for delicious.

http://cufp.galois.com/2008/abstracts.html

alexis said...

thanks for mentioning RabbitMQ, here are some slides about our use of erlang: http://www.lshift.net/blog/2008/07/01/slides-from-our-erlang-exchange-talk

Thomas Lindgren said...

Erlang in del.icio.us: http://blog.socklabs.com/2008/07/delicious_is_gone_long_live_de/

Jörg W Mittag said...

A couple of other examples: Fuzed was originally conceived as a scalable replacement for Mongrel for Rails deployment but has now been expanded to a generic self-configuring cloud infrastructure. Fuzed is currently used heavily at Powerset.

And the GitHub guys (one of whom also works at Powerset) wrote an Erlang replacement for git-daemon called egitd which they deployed domething around two weeks ago.

Anonymous said...

We are using Erlang as our middleware "bus" and for mapreduce scatter-gather data crunching. It's awesome.

Unknown said...

@alex payne: I must have missed this move! Is there any post that I can point to that discusses Twitter's move away from Ejabberd ? Just curious, what does Twitter use now for real time message distribution to users ?

Anonymous said...

debasish: Haven't you noticed? Twitter hasn't had any real time message distribution to users for a while now.