Krzysztof has been working on our RavenDB Go Client for almost a year, and we are at the final stretch (docs, tests, deployment, etc). He has written a blog post detailing the experience of porting over 50,000 lines of code from Java to Go.
I wanted to point out a few additional things about the porting effort and the Go client API that he didn’t get to.
From the perspective of RavenDB, we want to have as many clients as possible, because the more clients we have, the more approachable we are for developers. There are over million Go developers, so that is certainly something that we want to enable. More important, Go is a great language for server side work and primary used for just the kind of applications that can be helped from using RavenDB.
RavenDB currently have clients for:
- .NET / CLR – C#, VB.Net, F#, etc.
- JVM – Java, Kotlin, Clojure, etc.
- Go – finalization stage
- C++ – alpha stage
We also have a Ruby client under wraps and wouldn’t object to having a PHP one.
We used to only run on Windows and really only pay attention to the C# client. That has changed toward the end of 2015, when we started the work on the 4.0 release of RavenDB. We knew that we were going to be cross platform and we knew that we were going to target additional languages and runtimes. That meant that we had to deal with a pretty tough choice.
Previously, when we had just a single client, we could do quite a lot in it. That meant that a lot of the functionality and the smarts could reside in the client. But we now have 6+ clients that we need to maintain, which means that we are in a very different position.
For reference, the RavenDB Server alone is 225 KLOC, the .NET client is 62 KLOC and the other clients are about 50 KLOC each (Linq support is quite costly for .NET, in terms of LOC and overall complexity).
One of the design guidelines for RavenDB 4.0 was that we want to move, as much as possible, responsibility from the client side to the server side. We have done a lot of stuff to make this happen, but the RavenDB client is still a pretty big chunk of code. With 50 KLOC, you can do quite a lot, so what is actually going on in there?
The RavenDB client core responsibilities are:
- Commands on the server / documents – About 12 KLOC. This provide strongly typed access to commands, including specific command error handling and handling.
- Caching, Failover & request processing – About 3 KLOC. Handles failover and recovery, topology handling and the client side portion of RavenDB’s High Availability features by implementing transparent failover if there is a failure. Also handles request caching as well as aggressive caching.
- JSON handling. About 3 KLOC. Type convertors, serialization helpers and other stuff related to handling JSON that we need client side.
- Exceptions – 1.5 KLOC. Type safe exceptions for various errors takes a lot of bit of code, mostly because we try hard to get good errors to the user.
But by far, the most complex part of the RavenDB client is the session. The session is the typical API you have for working with RavenDB and it is how you’ll usually interact with it. You can see the Go client above using the session to store a document and save it to the database.
The sessions is about 20 KLOC or so. By far the biggest single component that we have.
But why it is to big? Especially since I just told you that we spent a lot of time moving responsibilities away from the client.
Because the session implements a lot of really important behaviors for the client. Without any particular order, and off the top of my head, we have:
- Unit of Work
- Change Tracking
- Identity Map
- Lazy operations
The surface area of RavenDB’s client API is very important to me. I think that giving you a high level API is quite important to reduce the complexity that you have to deal with and making it easy for you to get things done. And that end up taking quite a lot of code to implement.
The good news is that once we have a client, keeping it up to date is relatively simple. And having the taken the onus of complexity upon ourselves, we free you from having to manage that. The overall experience of building application using RavenDB is much better, to the point where you can pretty much ignore the database, because it will Just Work.