My scenario is I prefer to stay in a relational database storage system like SQL Server because I would need to work with complex queries.
And then, because some calculations would be better to be done overtime and just store the results into something like Redis or maybe a more traditional NoSQL solution.
That's the point where I thought: and what happened with the second-level cache on NHibernate?.
I did a very small research and I found that there's a Redis second-level cache provider, and now I got "confused".
I mean, if I use NHibernate's second-level cache most of object access should be very fast as it should be no database roundtrip, thus most accessed objects would be retrieved from the in-memory Redis store.
Why I'm considering this instead of just using Redis directly? Because I need actual atomic transactions within my solution's domains.
Is relying on NHibernate's second-level cache Redis provider a good idea in order to get the best of relational and schema-less worlds?
What's your advice?
I see two different things as a summary of your view:
Use redis as second level cache above NHB. This make perfect sense as SLC stores separated fields of objects and redis is key/value store. As I remember, SLC contain results of scalar queries or mapped and fetched objects but what's important, the data are taken (cached) from performed queries.
IMHO if you would use redis this way, all cached values must result from NHB queries. This brings you some kind of transaction atomicity, how did you already described, but as far as I know, we found couple bugs when SCL returned stale data or data from uncommitted transactions.
Note that this approach says that someone (NHB) still needs to somehow guarantee business transaction between RDBMS and Redis, which is not simple and buggy.
Also note that SLC itself is not incredibly fast pattern. As SLC contain field of object and not object itself, every hit results into new object creation. So what happen is fetching data from Redis instead of resultset obtained from executed SQL query. So, when you use prepared statements and RDBMS typically makes caching for you, you can find out that this does not bring very large performance improvement for you.
Redis as a separated business store. You managed data completely on you own, you can make their computation within native (C#) code (contrary to SQL query or mapped object). You need to guarantee fresh data and some transaction approach.
What I would choose? Separated redis. Why?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With