Pergunta de entrevista da empresa Rippling

Design a SQL transaction system for a key-value store. So have a way to commit and rollback data from the DB, but also be able to update the DB without using commit and rollback (just write straight to it). Step two was to enable this in a nested manner (one level deep).

Resposta da entrevista

Sigiloso

28 de mai. de 2024

The solution is two use two hash-maps. One to track the actual data, and the second to track changes for when you want to rollback a commit. The tricky part is coding delete functionality, so in that case I simply set the value to NULL when tracking changes. After committing, you simply loop through the hash-map and if the value is NULL, then you remove the value from the original hash-map. To do this in a nested manner, you simply apply the same logic as above, but you need to keep track as to which hash-map you're writing to