Justin Santa Barbara’s blog

Databases, Clouds and More

Jetcd: Java Binding for Etcd

etcd is a great distributed state store that is part of CoreOS (definitely a project-to-watch). It offers similar functionality to Zookeeper, but is written in Go instead of Java and uses a different non-Paxos coordination algorithm, called Raft.

I mention Go not because it is this year’s cool new language (sorry, Ruby Erlang Node!), but because it means that etcd has a smaller memory overhead than Zookeeper. So, if you need to store a small number of items in a distributed state store, say for leader election or cluster discovery, then it’s much lighter-weight than Zookeeper. It’s light-weight enough that you could think about running etcd on every instance in a cluster, where it’s hard to justify doing that with Zookeeper unless you’re storing more data.

But, despite the fact that Go is great, some people - myself included - will still want to use Java for more complicated tasks. So, I’m open-sourcing my Java binding to etcd under the Apache license: jetcd. It’s still very-early code, so test thoroughly before rolling out into production!

The trickiest thing is that etcd uses HTTP long-polling for change notification; that is then exposed as a Java Future for use in async code (or just call get() on it if you want to be synchronous). It’s actually exposed as a ListenableFuture from Google’s Guava, because that’s usually much more useful.

We don’t really want to tie up a Java thread for each watch, so that means using one of the async HTTP libraries. I chose the Apache HttpAsyncClient, even though it’s still in beta. If you hate that and love library X, then please submit a pull-request. In general, pull requests are very welcome!

Check out jetcd on Github