Colossus

Service I/O Framework


Colossus is a lightweight framework for building high-performance network I/O applications in Scala. In particular Colossus is focused on low-latency microservices, single-feature stateless applications with a RESTful API. Colossus aims to maximize performance while keeping the interface clean and concise.


See it in Action

The obligatory 5 line Hello-world Service:
object Main extends App {
  
  implicit val system = IOSystem()

  Server.basic("example-server", 9000){ new HttpService(_) {
    def handle = {
      case request @ Get on Root => request.ok("Hello world!")      
      case request @ Get on Root / "echo" / str => request.ok(str)
    }
  }}
}
For a more substantial example, here's a simple http proxy using Memcached for caching:
object Main extends App {

  implicit val system = IOSystem()

  Server.start("proxy", 9000) { new Initializer(_) {

    val remoteHost     = Http.client("remote.host", 8080)
    val memcacheClient = Memcache.client("memcache.host", 11211)

    def onConnect = new HttpService(_) {

      def handle = {
        case request => memcacheClient.get(request.head.bytes).flatMap{
          case Some(responseBytes) => HttpResponse.fromBytes(responseBytes)
          case None => for {
            response    <- remoteHost.send(request)
            memcacheSet <- memcacheClient.set(request.head.bytes, response.bytes)
          } yield response
        }
      }
    }
  }

}

How It Works

Colossus is a low-level event-based framework. In a nutshell, it spins up multiple event loops, generally one per CPU core. TCP connections are bound to event loops and request handlers (written by you) are attached to connections to transform incoming requests into responses. I/O operations (such as making requests to a remote cache or another service) can be done asynchronously and entirely within the event loop, eliminating the need for complex multi-threaded code and greatly reducing the overhead of asynchronous operations.

Built at Tumblr

Colossus was built to address many of the challenges we've faced at Tumblr when writing Scala services. It has greatly simplified the development process, allowing engineers to rapidly build services that are production-ready with minimal effort. Colossus is currently used in several production systems throughout Tumblr's infrastructure.

We need your help!. Colossus is still in the early stages of development and while we've met many of the goals we set out to achieve, there's still much to be done. Features need to be implemented, bugs needs to be fixed, optimizations need to be optimized. If you find a bug or have a cool idea, let us know and get involved!