node.js - MongoDB and Redis as cache layer architecture -
suppose have social network app (using nodejs, express) , mongodb primary database engine.
in of api calls clients (mobile app, web app, etc.) don't want make complex query each request. these sort of requests can replied cache layer, redis instance.
but question how/when should update cache layer, because write operations performed in mongodb database, not cache layer (redis). correct approach/architecture address problem?
it depends on needs, here's common one:
on_get_request if data_in_redis serve_data_from _redis else get_data_from_mongo set_data_in_redis set_expire_in_redis serve_data_from_memory
the data bit stale @ times, that's ok use cases. works in combination cache invalidation when important data written:
on_important_data delete_invalid_redis_keys
but assumes low write, high read, , stable set of queries.
what high load use case like?
Comments
Post a Comment