I have about 100K products that I want to keep in memory. These products can change at a high rate per hour, but at the same time reads will be the majority of the calls, and there can be a delay with getting the most recent version.
I want to create 1 actor per product, but have a shared in-memory store of the product.
Is it safe to use a concurrenthashmap and pass it as a prop to 100K actors?
val products = new ConcurrentHashMap[ProductId, Product](initialCapacity)
So in my actor I will have something like:
def recieve = {
case GetProduct(id: ProductId) =>
// lookup in products concurrenthashmap, if not there, read from datastore and return
//
case UpdateProduct(id: ProductId) => ???
}
When there are updates, there could be 100-500K per hour. There can be a delay in the update, that's not an issue. So to distribute the updates and prevent locks, 1 actor per product is what I am thinking. I just want to make the cache global across all actors.
Is this design sound?