Rippling | PhoneScreen | KeyValue Datastore
Anonymous User
5735

KeyValue datastore with begin,commit and rollback.
Question is the same as discussed here. It also has some good solutions in the discussion forum.
https://leetcode.com/discuss/interview-question/279913/bloomberg-onsite-key-value-store-with-transactions
You are expected to implement and run the code with a few test cases.
Please Note-> They made it very clear at the beginning that they want the code to run or there will be a reject, so please keep that in mind when you start implementing.
My advice is to run the code after writing small logic of code in incremental way to make sure that you always have an executable code and you are not inroducing bugs and making it non-runnable as running the code without exceptions is of prime importance for this company.
The solution to this question is easily available in various discussion forums.
However in short it can be implemented as the psuedo code below.

  1. Declare a Permament keyvalue hashmap
  2. Decalre a Temporary keyvalue HashMap to store the temp transactions when begin is called
  3. If rollback is called, you will delete the temporary HashMap.
  4. If commit is called, you will copy the values from temporary HashMap to permanent hashmap
  5. Please note, if you need to delete a value in the HashMap you need to mark it with some unique value to identify that this key needs to be deleted, otherwise if you delete it from the temphashmap, you will never know that it needs to be deleted from the permanent hashmap when commit is called.
  6. For Nested Transactions , you will need to store the temporary hashmaps in a stack.

However, for senior candidates, I would recommend reading DDIA(Designing Data Intensive Applications) Chapter 3 as that will help you to understand the fundamentals behind this question.
This question can be also asked as a System Design Question in Onsite and the expectation from Senior/Staff would be to know the details explained in DDIA Chapter 3 Storage and Retrieval and bonus points if you can also explain the bits explained in Chapter 7 Transactions.

Comments (9)