Writing A Database: Part 1 — Skeleton Implementation

Code lives at https://github.com/danchia/ddb

After the requisite installing of things (golang, protoc, vim-go plugins), I put together a quick skeleton implementation of a key-value store.

I’ve often found that getting all the initial plumbing together can be a bit of a pain. Thankfully that wasn’t too much the case this time, although I have used gRPC / proto3 in the past, and have some familiarity with golang.

Thoughts on Go so far

  • Compiling is really snappy! Granted I don’t have much code yet, it will be interesting to see if this keeps up.
  • The vim-go plugin is really nice. Works out of the box and gives me auto-complete, auto format and auto import.
  • Go recommends not using any assertion library for tests. It’s an interesting choice, and I’m still on the fence. I think libraries like Truth are pretty useful. We’ll see.


The API is really simple right now:

I initially had key be of type bytes; it turns out in Go you can’t compare slices, which was a little surprising, and I made it a string instead mostly for convenience.

What’s Next

The current implementation accepts the request and sticks it into an in-memory map. This of course means on restart the server will lose all data, which isn’t very useful for a database.

Next up, I’ll delve a little into write-ahead logging, which will let us recover data on restart / crash.