Architecture for Redis cache & Mongo for persistence

前端 未结 1 567
别跟我提以往
别跟我提以往 2021-01-29 18:52

The Setup:
Imagine a \'twitter like\' service where a user submits a post, which is then read by many (hundreds, thousands, or more) users.

My question is regardi

相关标签:
1条回答
  • 2021-01-29 19:07

    It is actually sensible to associate Redis and MongoDB: they are good team players. You will find more information here:

    MongoDB with redis

    One critical point is the resiliency level you need. Both Redis and MongoDB can be configured to achieve an acceptable level of resiliency, and these considerations should be discussed at design time. Also, it may put constraint on the deployment options: if you want master/slave replication for both Redis and MongoDB you need at least 4 boxes (Redis and MongoDB should not be deployed on the same machine).

    Now, it may be a bit simpler to keep Redis for queuing, pub/sub, etc ... and store the user data in MongoDB only. Rationale is you do not have to design similar data access paths (the difficult part of this job) for two stores featuring different paradigms. Also, MongoDB has built-in horizontal scalability (replica sets, auto-sharding, etc ...) while Redis has only do-it-yourself scalability.

    Regarding the second question, writing to both stores would be the easiest way to do it. There is no built-in feature to replicate Redis activity to MongoDB. Designing a daemon listening to a Redis queue (where activity would be posted) and writing to MongoDB is not that hard though.

    0 讨论(0)
提交回复
热议问题