这是设计非SQL数据库的好方法吗?

时间:2019-05-25 08:12:20

标签: database-design nosql key-value-store

我对关系的数据库有足够的经验,但是想尝试一种不使用SQL的方法(键值)。并为此制定了一项任务。这是与用户,广告系列和统计信息进行分组相关的另一个链接。而且它必须可以在高负载下工作=)

使用案例:

1. Generate short link
1.1. User is not logged, without a campaign.
  Put a pair to the bucket LINKS, don't put to USERS and CAMPAIGNS buckets.
1.2. User is logged, without a campaign.
  Put the pair to LINKS, update a counter in the bucket USERS, don't put to CAMPAIGN bucket.
1.3. User is logged and campaign is created.
  Put/update pairs to all the buckets.
2. Get statistics.
2.1. Get all links and its stats by user (must be logged).
2.2. Get all links and its stats by campaign (must be logged).
2.3. Get stats by short url (must be logged).
3. Redirect to a long url by short one (no matter logged user or not).

我如何使用关系数据库解决此任务。四个表:

  • 用户(id,名称);
  • 广告系列(owner_id,id,名称);
  • 网址(shortURL,campaign_id,long_url);
  • 统计信息(shortURL,get_counter,created_at,last_access_at)。

当然,我在这里跳过了索引和非规范化。

现在我正在考虑如何在无SQL DB(kv)中实现这一点。

图例:(b)-存储桶/子存储桶,(k)-键,(v)-值

/.
 |--- (b) USERS --- (k) user_id
 |              --- (v) { "name": "User", "settings": {}, "stats": {"link_count": 1}, "links": ["a","b"]}
 |--- (b) LINKS --- (k) short_link
 |              --- (v) { "long_link": "https://example.com", "stats" : {"counter": 1, "created_at": "2019-01-01T00:00:00Z, "last_access_at": "2019-01-01T00:00:01Z"}}
 |--- (b) CAMPAIGNS --- (b) USER_ID --- (k) campaign_id
 |                                  --- (v) { "name": "campaign", "links": ["a", "b"]}

这是解决问题的正确方法吗?

2.1。通过links数组中的user_id从USERS存储桶中获取所有链接,然后通过short_url一一获取统计信息来获取所有统计信息。

2.2。与上述相同。从CAMPAIGNS.USER_ID.links数组获取链接,并从LINKS存储桶中逐一获取统计信息。

还是kv数据库的设计完全错误?

0 个答案:

没有答案