I have a dataset in a key value store (similar to Cassandra). The data model is -

Key - ServiceName / timestamp_in_milliseconds
value - operation

In the write side I get some operations for a service and I store them as the key value model above. These operations can come at any frequency, once a day, once an hour or few thousands in a minute.

On read path, I get requests where I need to aggregate all the operations from a time range. The key value store allows me to search through the range.

The latency of getting to key value store is quite high and I want to cache the results in a distributed cache (Similar to Redis) to improve performance.

My dilemma is when I get a request for a particular time range, I have no way of knowing whether there was any data for this time range. Since operations do not necessarily have to exist for every datapoint (millisecond timestamp), if an operation is not found in cache it might mean that either we have to fetch it from key-value store or there was no operation for that timestamp. This would make the application to essentially go to the key value store for every request, rendering the cache useless.

Is there any way to design the cache such that I can reliably fetch the values from cache while reloading it at a genuine cache miss (that is when value is present in store but not in cache) ? Also the scale of data is such that I can not store some nil value for every millisecond.

  • 1
    There's a difference between not having something in the cache, and having it in the cache but being empty. Why can you not store cached, empty results? – 1201ProgramAlarm Jul 10 '19 at 1:39
  • Mostly because of granularity, it would require me to store an empty value for every millisecond to show that the value is not present in the cache or in the underlying K-V store. – ocwirk Jul 10 '19 at 3:09
  • 1
    Would it not be possible to aggregate the data as it is streamed in and provide a cachable hyper index? Something coarse like an event occurred within this ten minute time interval. 6 intervals per hour 24 hours per day that's a max of 144 records per operation grouping per day. The first event would create the ten minute bookmark. Subsequent events would either increment the count, or be no ops until the ten minute window was over. Then they would be the first event, rinse and repeat. There is only a very small amount of online processing here, which drastically improves read speed. – Kain0_0 Jul 10 '19 at 5:26
  • @Kain0_0 Thanks, that sounds like the best option at the moment. I am going to give it a try. – ocwirk Jul 10 '19 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.