W7D3 - Functional Redis Integration in Project (19june)
W7D3 - Functional Redis Integration in Project (19june)
Funtional requirement.
Validation service.
120mins, 20payment
--
50 business validations.
10 rules we want to inactive. it should not run.
Sure, based on the image you sent, it appears to be a diagram illustrating a cache validation
mechanism used to improve data retrieval performance in a web application. Here's a breakdown
of the components involved:
Validation Cache:
This is a temporary storage layer located in-memory (RAM) closer to the application
server.
It stores a copy of frequently accessed data retrieved from the database.
The validation cache also stores metadata associated with the cached data, such as
timestamps or version numbers.
Database:
This is the primary data store where all the original data resides.
The database is responsible for maintaining data integrity and consistency.
Process:
1. Client Request: The user interacts with the web application, triggering a request for
specific data.
2. Cache Lookup: The application first checks the validation cache to see if the requested
data is present.
3. Cache Hit (Valid Data):
o If the data is found in the cache and the validation metadata (timestamp or version
number) indicates it's current, the cached data is retrieved and served directly to
the client. This is the most efficient scenario as it avoids a potentially slower
database access.
4. Cache Miss or Invalid Data:
o If the requested data is not found in the cache, or the cached data is considered
invalid (outdated), the application proceeds to the database.
5. Database Access: The application retrieves the latest data from the database.
6. Cache Update: The application typically updates the validation cache with the fresh data
retrieved from the database, along with the corresponding updated metadata. This ensures
subsequent requests for the same data can be served faster from the cache.
7. Data Delivery: The application delivers the data (either from cache or database) to the
client.
Benefits of Validation Cache:
Improved Performance: By serving data from the faster in-memory cache, the
application reduces response times and improves overall user experience.
Reduced Database Load: By offloading frequently accessed data from the database, the
cache can significantly decrease the load on the database server.
Cache Validation:
The validation mechanism ensures that the cached data remains consistent with the actual
data in the database. This is typically achieved using timestamps or version numbers
stored alongside the cached data.
If the cached data's validation metadata indicates it's outdated, the cache is bypassed, and
the application retrieves fresh data from the database.
Additional Notes:
The specific cache invalidation strategies and cache update mechanisms can vary
depending on the chosen caching solution and application requirements.
Some caching solutions offer write-through or write-behind mechanisms to keep the
cache in sync with the database during data updates.
I hope this explanation clarifies the caching mechanism with validation cache and database. If
you have any questions or would like to know more about specific aspects of cache validation,
feel free to ask!
===
1. Db table design
select:
select validatorName from validations.`validation_rules`
where isActive = true order by priority
List<String>
Redis
LIST
listOperations.rightPush("PAYMENT_VALIDATORS", value);
List<String> myvalues = null;
listOperations.rightPushAll(key, myvalues);
5-
Any rule, can have any number of parameters.. and any type of parameters...
1. PAYMENT_ATTEMPT_VALIDATION_RULE `paramName`
paymentAttemptThreshold `paramName` 5
2. PAYMENT_ATTEMPT_VALIDATION_RULE `paramName` timeInMins
`paramName` 60
..
..
..
.
PAYMENT_ATTEMPT_VALIDATION_RULE
Map<String, String>
RULE1
Map<String, String>
Redis Hashes
HMSET PAYMENT_ATTEMPT_VALIDATION_RULE paymentAttemptThreshold 5
timeInMins 60 ...:
RestTemplate
HashOperations<String, String, String> hashOps
@PostConstruct
public void processInit() {
//
/*
* Check value in redis
* if not there
* then use DAO class read value.
* Store in Redi
*/
}
2. When service comes up, then automatically check if data is in redis. If not
there, then load the data.
=> Power of simple IF check
on every restart it would try to read DB & store in redis.
every autoscaled ec2 instance.
duplication is possible
IF is mandatory.
Cache
Eviction/expiry - removal from cache
LRU, expiry time.
YES No eviction
10 yes
5 No (I support)
10 AM load fresh values from DB.
10:05 - modifies params.
2hrs
12
1. LIST OF ValidationRules
DB: RULE1, RULE2, RULE3
Redis: RULE1, RULE2, RULE3
RULE3 - INACTIVE
inputs: RULE_NAME
refresh the entire data:
RULE_NAME, parameter
RULE_NAME, LIST<parameter>
100 people
YOU WILL NOT GET JOB, based of whether you WANT IT.
YOU WILL GET JOB, if you DESERVE