查看: 7268| 回复: 19
跳转到指定楼层
上一主题 下一主题
收起左侧

[题目讨论] 一个重要的系统设计问题

   
🔗
匿名用户-U20WZ  2022-8-3 10:56:35 |倒序浏览

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
在设计系统的时候,具体问到数据库要怎么回答?  

1. 为何用NoSQL, 而不去用Relational SQL?
2. 分别会对系统的performance产生什么影响?
3. 他们分别对将来做scale有什么影响。
4. Trade off 具体在哪里?  


如何才能回答得让面试官服服帖帖?


就拿Glassdorr的网站举例子,如果设计这个网站的job subscribe功能的话。也可以用其他例子

感谢大家

评分

参与人数 1大米 +1 收起 理由
liudongtony + 1 赞一个

查看全部评分


上一篇:关于投票系统
下一篇:至今没想出来的系统设计题:匹配对手
全局:
现在是2022了,nosql都有事务了,rdbms也能做scale out 了。

个人认为选择数据库应该从这两个方面来看

1. 数据模型: 你的数据模型到底是schema还是schemaless 还是个图模型? 根据schema 的设计来决定用 rdbms nosql 还是 graphdb。
原因,现在2022了,rdbms是可以支持array,json 一类的type的,本质上数据模型和所谓的 document db, column family db 已经完全一致,除了你需要先定义schema。 而bfs like query因为你的query optimizer不知道 而且数据储存原因,虽然功能可以做到但是性能极差

2. 读写pattern:本质上现在只有两种流行的储存引擎,btree 和 lsm tree 分别对应读多和写多的场景。所以当你上面选择了数据模型之后,再根据你业务的query pattern选择一个储存引擎,如果再加上社区的考量,那基本上可以直接确定你需要什么
btree + rdbms=postgre
lsmtree + rdbms=mysql+myrocks
btree + nosql = mongodb
lsmtree + nosql = cassandra

如果你的pattern中出现了任何分析场景,尤其是大规模使用聚合函数,无脑选择postgre

如果你的pattern中出现了类似于linkedin n 度推荐的功能,大于三跳,无脑选择neo4j

以上仅限于OLTP场景,对于OLAP场景不使用。

没有大米了,认真写答案希望给点米吧



补充内容 (2022-08-03 21:32 +08:00):
再加一条特例,需要sacle out+强一致性的时候请选择spanner



补充内容 (2022-08-03 21:34 +08:00):
另外,再说到rdbms scale 的时候一定要先scale up,不要scale out。一个是实际中直接scale out情况很少,还有一个可以秀一波你对云服务 pricing model的了解

补充内容 (2022-08-04 06:06 +08:00):
赞比米多:( 😭😭😭😭

评分

参与人数 43大米 +64 收起 理由
dya233 + 1 很有用的信息!
张鱼 + 1 欢迎分享你知道的情况,会给更多积分奖励!
linglingnvnv + 2 赞一个!
ytsr + 1 赞一个
harvey1993 + 1 赞一个

查看全部评分

回复

使用道具 举报

全局:
rds 用在需要transaction的地方
nosql用在单row操作上
系统影响:
因为transaction的存在 rds普遍认为是1k qps 而nosql可以达到10qps

scale up:
很多nosql natively support scale up
rds则需要手动去配置

补充内容 (2022-08-03 13:10 +08:00):
trade off其实没有… 就是第一条: 你需不需要transaction (或者换句话说叫 一致性) 需要就必须sql 不需要就nosql…
你用nosql 自己做transaction在面试中是个很red flag的事情… 所以就看transaction就行了

补充内容 (2022-08-03 23:45 +08:00):
楼上说 nosql支持了transaction… 据我所知只有mongoDB4支持吧… 很多nosql 比如dynamo style的根本无法实现transaction,甚至single writing都可能导致数据nodes里面数据不一致…
回复

使用道具 举报

全局:
匿名用户 发表于 2022-8-2 21:03
Exactly why "modeling joins across tables also limits performance and horizontal scalability."?  
...

To maintain ACID property, relational databases have more overhead and limits scalability by design - when a transaction is committed, checks must be performed and changes rolled back if necessary. In a system with many nodes (horizontal scaling) this leads to higher performance overhead. Many systems use partitioning to try to minimize these situations.

There are many payment and even inventory systems that uses NoSQL even though transactions would make sense; that's why it's a trade-off instead of a rule. Perhaps the system needs high concurrency and there are separate mechanisms to deal with eventual consistency; think of buying things online for example. Sometimes you buy an item, and the system immediately tells you the item is out of stock. Sometimes you buy it and then the system cancels your order later telling you the item is out of stock. Both are valid workflows and the best solution depends on your situation.
回复

使用道具 举报

🔗
ghostbusters 2022-8-3 11:02:18 | 只看该作者
全局:
1. Relational database often requires fixed schema which makes it difficult to model some business needs; modeling joins across tables also limits performance and horizontal scalability.
回复

使用道具 举报

🔗
ghostbusters 2022-8-3 11:07:25 | 只看该作者
全局:
Trade-off includes eventual consistency vs ACID, and transactions support. Job subscriptions and notification are classic use cases where eventual consistency is okay and there's no need for transactions, so noSQL would be better choice.
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-U20WZ  2022-8-3 12:03:19
ghostbusters 发表于 2022-8-2 22:02
1. Relational database often requires fixed schema which makes it difficult to model some business n ...

Exactly why "modeling joins across tables also limits performance and horizontal scalability."?  

Any concrete reason behind?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-U20WZ  2022-8-3 12:04:08
ghostbusters 发表于 2022-8-2 22:07
Trade-off includes eventual consistency vs ACID, and transactions support. Job subscriptions and not ...

but I see some payment system also use NO SQL, for microservices. How to explain  that?

评分

参与人数 1大米 +1 收起 理由
最讨厌回南天啦 + 1 赞一个

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-LCTAZ  2022-8-3 13:58:21 来自APP
还是先搞清楚两者的区别吧,不然你只能针对glassdoor 的例子死记硬背
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-CTDLI  2022-8-3 14:17:00
本帖最后由 匿名 于 2022-8-2 23:30 编辑

1. 都行,即使没有transaction需求,上来直接NOSQL一把梭是个很忌讳的事. 更何况各种魔改MySQL的存在...比如vitess;

2. SQL/NOSQL都行的情况下,更多的是讨论哪个'方便'

3. 参考2, MySQL这种后期的scale无论是单纯的分库分表还是vitess核武器,都是魔改..只是魔改的疯狂程度...NoSQL一般是有现成的scale up配套.

结合这个glassdoor job subscribe..
侧重点应该是类似twitter/IG的follower, followee这张表...按照实际glassdoor的volume, Mysql也不是不能做啊,大不了直接Json干进去啊...当然了NoSQL比如Hbase可能更好点.

这题如果是我答,绝壁是MySQL开场....过早地把自己带进那个NoSQL默秒全的局面容易被人怼...而且不像Sr.
回复

使用道具 举报

全局:
需要强一致性就上关系数据库,需要大吞吐量就上非关系。前者小而精,不好scale但贵在consistent,后者能hold住海量数据批量处理的需求,但数据不一定是最新最准确的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表