The goal of this post is to build a real-time database. For simplicity we limit our scope to:

  • persistent key value store.
  • each client must have its own version of store.
  • sync with events made by other clients.

Here is how I approached the problem.

V1: Simple KV store using a hashmap

Let’s start with a simple hashmap and build an abstraction over it.

type Store struct {
db map[string]string
func NewStore() *Store {
store := &Store{db: map[string]string{}}
return store
func (k Store) Get(key string) string {
return k.db[key]
func (k Store) Put(key string, value string) {
k.db[key] = value

Now while this…

Photo by Murilo Silva on Unsplash

Dependency Injection(DI) is a set of software design principles that enable engineers to develop loosely coupled code. This stack overflow post is the best ELI5 description of DI:

When you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, you might get something Mommy or Daddy doesn’t want you to have. You might even be looking for something we don’t even have or which has expired.

What you should be doing is stating a need, “I need something to drink with lunch,” and then we will make sure you…

Image by Julius Silver from Pixabay

Brendan Burns in his paper Design Patterns for Container-Based Distributed Systems lays out 3 single node patterns that are used in a micro-services architecture. There is some documentation available with examples for implementing these patterns with Kubernetes. However, I couldn’t find a lot of examples using HashiCorp’s Nomad. My goal is to work through them with examples using Nomad as our job scheduler. All the code used here is available in the Github Repository

Quick Introduction to Nomad

Nomad is: A simple and flexible workload orchestrator to deploy and manage containers and non-containerized applications across on-prem and clouds at scale. It uses HCL to…

Photo by Fotis Fotopoulos on Unsplash

The circuit breaker is a design pattern, used extensively in distributed systems to prevent cascading failures. In this post, we’ll go through the problem of cascading failures and go over how the circuit breaker pattern is used.

Motivation: The problem of cascading failures

Before jumping into the circuit breaker pattern, let’s try and understand what problem it tries to solve.
When service A tries to communicate with service B it allocates a thread to make that call. There are 2 kinds of failures that can occur while making the call. We use the example of a user service making a call to friends service.

''' user…

Ganesh Iyer

AI in healthcare @ MGH and BWH Center for Clinical Data Science. (Notes on systems, software and scaling)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store