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

我的问题是关于构建缓存的最佳方法&优化数据库以实现快速访问&许多人阅读,但仍保留历史数据,以便用户(如果他们愿意)看到旧帖子.这里的假设是,90%的用户只对新东西感兴趣,而旧东西偶尔会被访问.这里的另一个假设是,我们希望针对90%进行优化,如果旧的10%需要更长的时间来检索,这是可以的.

考虑到这一点,我的研究似乎有力地指向了一个方向,即对90%的用户使用缓存,然后将帖子也存储在另一个长期的持久系统中.到目前为止,我的 idea 是使用Redis进行缓存.其优点是Redis速度非常快,并且内置了pub/sub,非常适合向许多人发布帖子.然后,我考虑使用MongoDB作为一个更永久的数据存储,来存储那些在Redis到期后将被访问的帖子.

Questions:
1. Does this architecture hold water? Is there a better way to do this?
2. Regarding the mechanism for storing posts in both the Redis & MongoDB, I was thinking about having the app do 2 writes: 1st - write to Redis, it then is immediately available for the subscribers. 2nd - after successfully storing to Redis, write to MongoDB immediately. Is this the best way to do it? Should I instead have Redis push the expired posts to MongoDB itself? I thought about this, but I couldn't find much information on pushing to MongoDB from Redis directly.

推荐答案

把Redis和MongoDB联系起来其实是明智的:他们是很好的团队合作者.您可以在这里找到更多信息:

MongoDB with redis

一个关键点是你需要的弹性水平.Redis和MongoDB都可以配置为达到可接受的弹性水平,这些注意事项应该在设计时讨论.此外,它可能会限制部署选项:如果您想为Redis和MongoDB进行主/从复制,则至少需要4个框(Redis和MongoDB不应部署在同一台机器上).

现在,让Redis用于排队、wine 吧/wine 吧等可能更简单一些...并仅将用户数据存储在MongoDB中.理由是,您不必为两个具有不同模式的store 设计类似的数据访问路径(这项工作的困难部分).此外,MongoDB具有内置的水平可扩展性(副本集、自动分片等)而Redis只能自己动手.

关于第二个问题,写信给两家store 是最简单的方法.没有将Redis活动复制到MongoDB的内置功能.不过,设计一个监听Redis队列(活动将在其中发布)并写入MongoDB的守护程序并不难.

Mongodb相关问答推荐

Mongo如何找到字段排除特殊字符

$mod只支持数字类型,不支持MongoDb中的array和int

从两个相连的文件中获取电话和邮箱的渠道是什么?

联接不返回具有ObjectId和非ObjectId的结果

MongoDB:如何从数组中的所有对象中删除属性?

通过insertId MongoDB获取文档

TypeError:Cannot read property '_id' of undefined

MongoDB C# 驱动程序 2.0 InsertManyAsync 与 BulkWriteAsync

findOneAndUpdate 和 findOneAndReplace 有什么区别?

从 PHP 打印 MongoDB 日期

我怎样才能排序空值在 mongodb 中是最后排序的?

使用 MongoDB C# 驱动程序在嵌套数组上使用过滤器生成器进行查询

.NET 4 中是否有 mongodb C# 驱动程序支持 System.Dynamic.DynamicObject?

如何使用 MongoDB 建模 likes投票系统

在 MongoDB 中合并两个集合

带有 Java 驱动程序的 MongoDB 聚合

如何为 node.js 中的 MongoDB 索引指定 javascript 对象中的属性顺序?

使用 Jackson 与 Java Mongo DBObject 进行高效 POJO 映射

Java Mongodb 正则表达式查询

我们如何使用spring boot为mongodb创建自动生成的字段