Byzantine Reality

Searching for Byzantine failures in the world around us

Active Cloud DB - Go Edition

One of the big problems I have as a programmer is that I don’t have great UI skills, so whenever I have to make a UI for an app, it tends to look like crap. Lo and behold, to my amazement, that Twitter has taken a huge step towards fixing this problem for me with Bootstrap. Who would have guessed that all I needed was a single CSS file to make my web apps look pretty?

Having seen what Bootstrap can do (and if you haven’t looked at that link, go check it out), I decided to take on a small project to give it a test drive. With that, let’s talk about Active Cloud DB – Go Edition!

Last year I put together Active Cloud DB, a REST interface to any database that supports the Google App Engine Datastore API. That means that your client (in whatever language you want) can make REST calls to save and retrieve data without having to know how the underlying database works or how to optimize it. Naturally you may assume that the Google App Engine Datastore API is only supported by Google App Engine, and therefore you’d only be able to utilize a single database. But you’d be wrong! Since AppScale implements the Datastore API for all its databases, you can now save and retrieve data to any of the nearly dozen databases it supports. For example, you can save data from your Haskell application to Active Cloud DB and have Cassandra running via AppScale, which I think is pretty cool.

Active Cloud DB is written in Python, and I’ve been itching for a project to undertake with the sexy new Go App Engine runtime. It couldn’t be better reflected in the name – Active Cloud DB – Go Edition! Here’s how it all meshes together. All the Datastore communication is done in Go, so querying is done in the usual manner:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
func query(w http.ResponseWriter, r *http.Request) {
  c := appengine.NewContext(r)
  q := datastore.NewQuery("Entity")

  result := map[string] string {}
  for t := q.Run(c); ; {
    var entity Entity
    key, err := t.Next(&entity)
    if err == datastore.Done {
      break
    }
    if err != nil {
      result["error"] = fmt.Sprintf("%s", err)
    }
    keyString := fmt.Sprintf("%s", key)
    result[keyString] = entity.Value
  }

  fmt.Fprintf(w, "%s", mapToJson(result))
}

As you can see from the above snippet, all the Go methods that we have output JSON that AJAX requests can easily consume. We have a small set of Go methods (put/get/delete/query) to keep the interface nice and simple. The app is simple enough to need only a single HTML page, and Bootstrap makes it look damn nice (if I do say so myself). It’s got some nice pretty buttons, flash messages, and other things you’ve seen for years now but look just flawless with Bootstrap. To wrap it all up, there’s AJAX that intercepts most of the button clicks and talks to the Go backend. Here’s a screenshot of Active Cloud DB in action:

The Python version is still a bit ahead as far as feature support goes – it has caching optimizations from our CloudComp paper that speed up most of the operations via the Memcache API. We’ll get to implementing those soon, and that will necessitate a follow-up post. In the meanwhile, go get coding with Go, App Engine, and Bootstrap!