Triplebyte Interview Question
Software EngineersCountry: United States
Interview Type: Phone Interview
Convert the object into a byte array and split the array into multiple arrays each equal to 1 MB (size - 1024*1024). Store each of the subarrays in the cache using their hashcode. Create a list which contains all such hashcodes of the subarrays and store it against the original key in the cache.
Have a wrapper class (kind of) that accepts entire object and internally splits the object into 1MB chunks and uses memCached methods to actually cache.
In order to logically retrieve the 1MB chunks, the "key" can be chosen such that it helps in consolidating the retrieved chunks. Ex- Hypothetically, if the data is simply a text of say huge words. then if we break into 1mb, some words might be broken. So if key can be selected such that it indicates if its part of same word or a different word altogether, it will help in retrieving the data. Say keys can be "1a, 1b, 1c, 2,3,4,5a ...".
The first thing that comes into my mind, divide the object (actually an array of bytes) into the parts by 1MB modulo. You'll get say N parts. Than create the memcache keys like _objectKey_Npart_Ntotal_ and put to the memcache each part of the array with the appropriate key. Also you need to create another level of abstraction (get and set methods) around memcache and encapsulate the logic above inside it
It will be more robust if we store the meta information by the original key
should return the meta information = N parts. Than you request each part by _objectOne_Npart_Ntotal (actually Ntotal not neccessary if we store metainformation by the original key) and combine that and return from the wrapped implementation
- Arseny Kovalchuk October 13, 2016