Cal*_*oiu 9 reddit cassandra database-schema
Reddit目前正在将其数据库从PosgreSQL迁移到Apache Cassandra.有人知道Reddit在Cassandra中使用了什么数据库模式吗?
Ken*_*but -2
我也不知道确切的 Reddit 模式,但对于您想要存档的内容,您的方法是正确的,将评论层次结构保存在基于文档的数据库而不是关系数据库中。我建议为每个根评论保留一份文档,然后将所有子评论(以及子评论的子评论)添加到该评论中。
在 CouchDB 和 MongoDB 中,您可以直接存储 JSON 文档。在 Cassandra 中,我会将 JSON 保存为 String。所以数据结构只有
root-comments
{
root-comment-id
root-comment-json-string
}
Run Code Online (Sandbox Code Playgroud)
每个 root-comment-json-string 看起来像这样:
{
comment : "hello world"
answers :
[
{
comment : "reply to hello world"
answers :
[
{
comment : "thanks for the good reply"
answers : []
},
{
comment : "yes that reply was indeed awesome"
answers : []
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
另外,您可能想在每个评论的结构中添加用户名、用户 ID、时间戳等。
如果您有大量数据,那么与规范化关系结构相比,这种“非规范化”结构将使查询速度非常快。
在任何情况下,您都必须处理所有异常,当您为大用户规模实现这样的系统时可能会发生这种情况,例如。如果有人用评论 B 回复评论 A,但同时(或稍后)评论 A 被删除,会发生什么情况?
如果您在互联网上搜索“cassandra 分层数据”,您会发现一些其他方法,但它们都会回到标准化,或者对于“无限”层次结构来说并不完整。
| 归档时间: |
|
| 查看次数: |
2881 次 |
| 最近记录: |