Business logic/rules - processing in the database or in memory
because of my over abundance of hubris, I am working on a program that would process some of the data better than the current system we are currently using. My question is when the implementing business rules (i.e. if this piece of data matches this pattern send to this que) is it best practice to:
simply load all th开发者_如何学Ce rules into memory from a DB when the program starts
positive: very fast
negative: this program would have allot of rules so could be a memory hog
have all the rules into a database and allow the matching to be done in the database
positive: not using a ton of memory
negative: lots of database calls
have a flag in memory that would call to a specific rule in the database.
positive: not a ton of memory
negative: still a lot of database calls
Any thoughts
You forgot about the hybrid of your two extremes -- a smarter cache (smarter than everything in memory).
Initialize the cache with no rules (or a few of the most popular).
The app requests a rule from the cache.
If it exists in the cache, return it.
If not, load it from the database, store it in cache, and return it to the user.
As with everything performance-related, you need to try options and measure their performance. It is very hard to tell in advance which one will work best for you.
One of the latest trends is in-memory databases. Doing BI and analytics in the database which holds the entire needed dataset in memory. We're talking about gigabytes of RAM.
You could consider this option knowing it is not exotic any more. RAM is cheap these days. Maybe it will work for you. You need to try it out.
精彩评论