Design Assignment | Implement a distributed Key-Value (KV) store | SE Role - Avalara

Problem Statememt :

KV store should be running as (at least) 2 different processes that replicate data between them (ie) we should be able to put in a Key and Value to Process 1 and query for the same Key on Process 2, for which we should get the corresponding Value.

Using a common backend to processes / using an existing open source KV stores like redis, etc is not allowed
Your solution should work even when we run two (or more) processes on multiple machines / containers connected over a network.

We would like you to expose the store via a HTTP service that would allow us to GET / SET
key-value pairs.
curl -H “Accept: application/json” http://localhost:4466/get/key
“value”

My Approach / Solution :

It is a in memory key-value store using hashmap internally. In the implementation , I developed a jar which takes a configuration file that has the information about the peers end points, replication factor, port number to open etc., Once the process starts it starts serving the requests over HTTP endpoint. All the incoming put requests will be written to log structure(appended to list along with timestamp), this is used to replicated the data to peers, every put request ensures that key is written to replication factor number of peers. And the separate replicator thread runs in the process to replicate this log to all the peers excluding replicas along with the check pointing to be in sync with peers. If the get request is made to any peer and key is not available in that process, it will request the peer process for the key and updates the value locally and returns that to client. If the key is already available , it returns directly the value. In this case if the same key is updated in other peer and replication snapshot is not done yet, this will result in incorrect return value(limitation). Whenever the process goes down and comes back, it will not have any data and request for any old keys will result in requests to peers.

Excuse me if I am not clear with explanation as it is my first post here, i will answer/edit the post on further questions/suggestions.

Some how, my design is not accepted. I want to hear from you on the possible reasons. Thank you.

Comments (3)