Dynamo Db表的模式设计或讨论论坛的等效Nosql Db

时间:2016-12-01 01:09:22

标签: json amazon-dynamodb database-schema sharepoint-discussion-board nosql

我有兴趣设计一个简单的讨论论坛,用户可以发布帖子,评论帖子并回复特定评论。

我发现很难提出架构/数据库模型来实现评论和回复功能

用户和线程的架构

    {
      name      : "Krishnakanth",
      username  : "krish", (-)
      password  : "rbswew424",
      age       :  21,
      hometown  :  "abc",

    }
       *Threads*
    {
      name           : "someName",
      threadId       : "someID",(-)
      username       : "someName,
      timeOfCreation : "time in some standard format" (--)
    }
  • ( - )=>分区键*
  • ( - )=>排序键*
  • 请帮助提出一个架构设计来实现评论和回复功能*

如果您来自非Dynamo数据库背景,只需发布​​评论和回复功能的JSON格式..!

提前致谢。

1 个答案:

答案 0 :(得分:1)

我提出了两种不同的方法,它们都有自己的优点和余量,

1)没有StringSet的架构

threadMaster(threadId-hash, timestamp, otherAttributes)
threadDetails(threadId- hash, replyId-range, timestamp, otherAttributes)

此架构中的数据如下所示:

threadMaster:
t1, 31-11-2016:10:30
t2, 31-11-2016:09:34
t3, 31-11-2016:11:30

threadDetails:
t1, r1, 31-11-2016:10:33
t1, r2, 31-11-2016:11:09
t1, r3, 31-11-2016:13:20
r1, r1, 31-11-2016:10:38  **
r1, r2, 31-11-2016:10:44  **

在上面的模式中,theadMaster将保存主threadId,它将被传递给detail表以获取该特定threadId的所有回复。

**您的回复又有回复,将在详细信息表中维护,您可以在详细信息表中添加另一个属性,其中包含true / false值,该值将显示该评论是否有回复以避免扫描表。

上述架构的问题是,如果其中一个线程有数百万的回复,则会对性能产生影响。

2)使用StringSet

threadMaster(threadId-hash, replyId(Set of Ids), timestamp, otherAttributes)
threadDetails(replyId- hash, timestamp, otherAttributes)

此架构中的数据如下所示:

threadMaster:
t1, [r1,r2,r3..rn], 31-10-2016:10:18
t2, [r11,r12,r13..r1n], 11-11-2016:20:00
t3, [r21,r22,r33..r2n], 21-11-2016:00:30
r4, [r99,r98]  **

threadDetails:
r1 31-11-2016:10:30
r2 31-11-2016:11:20
r99 01-11-2016:11:20

在上面的模式中,master表将包含有关线程及其回复的信息。

**当你回复评论时,你会在master中作为一个帖子自​​己做另一个条目。

上述架构的问题是添加/删除注释会很繁琐,每次回复都需要更新主线程。

您可以在应用程序级别使用timestamp属性来相应地对注释进行排序。

希望有所帮助