Are in-memory dbs best for maintaining transient statistics

For example, incrementing the view count of a post on blind would be a good use case of redis or bitcask according to DDIA

eBay yam saltmn Nov 19, 2023

AtomicInteger

Sam's Club mlze34 Nov 19, 2023

How atomic integer is going to work if application has more than one instance?

Lockheed Martin bbdj78 OP Nov 19, 2023

AtomicInteger then periodically update the value in regular database without need for separate in-memory db?

Google smokering Nov 19, 2023

It’s a good optimization but you’re still gonna need persistent storage

Lockheed Martin bbdj78 OP Nov 19, 2023

Thanks. I guess bitcask does persist data but redis only does so periodically depending on your configuration? Have not used in-memory db before

Google smokering Nov 19, 2023

It’s worth considering why Redis is good but not enough in this case. If you use only in-memory storage, an outage would wipe out your data. It’s a non-starter really. If you use only disk storage, it’ll likely be too slow for something as write-heavy as a view counter. You’ll probably run into data contention. Using redis with periodic persistent writes means less writing to disk while still having fast read/writes to memory. And when your in-memory redis db goes bust, you still have a “backup” on disk

Capital One 1influence Nov 20, 2023

This is an in-memory cache not a DB. The increment will occur on server side cache then write through to a persistent store.

Lockheed Martin bbdj78 OP Nov 20, 2023

Are you talking about what eBay suggested above- using some concurrent friendly data type as the counter then periodically updating db? Or are you talking about bitcask and redis

Capital One 1influence Nov 20, 2023

i dont understand the use of atomic integer. That would just save the result to the JVM memory space right? If you want to retrieve post_count from another service wouldnt it be better to use an in-memory cache separate from your application? Sorry if i dont understand the questino