﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-paulwong-随笔分类-ARCHITECTURE</title><link>http://www.blogjava.net/paulwong/category/55342.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 18 May 2022 10:24:20 GMT</lastBuildDate><pubDate>Wed, 18 May 2022 10:24:20 GMT</pubDate><ttl>60</ttl><item><title>12 Factor App Principles and Cloud-Native Microservices</title><link>http://www.blogjava.net/paulwong/archive/2022/05/18/450749.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 18 May 2022 07:59:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2022/05/18/450749.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/450749.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2022/05/18/450749.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/450749.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/450749.html</trackback:ping><description><![CDATA[<img src="https://dz2cdn1.dzone.com/storage/temp/13933804-12-factor-app-principles.png" width="600" height="336" alt="" /><br /><br /><a href="https://dzone.com/articles/12-factor-app-principles-and-cloud-native-microser" target="_blank">https://dzone.com/articles/12-factor-app-principles-and-cloud-native-microser</a><img src ="http://www.blogjava.net/paulwong/aggbug/450749.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2022-05-18 15:59 <a href="http://www.blogjava.net/paulwong/archive/2022/05/18/450749.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Enterprise Architect VS Solution Architect VS Software  Architect</title><link>http://www.blogjava.net/paulwong/archive/2021/10/11/436007.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 11 Oct 2021 07:29:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/10/11/436007.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436007.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/10/11/436007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436007.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436007.html</trackback:ping><description><![CDATA[<ul>
     <li>Enterprise Architect<br />
     定义企业的大概方向 </li>
</ul>
<ul><li>Solution Architect<br />
     定义系统使用哪些框架技术</li>
</ul>
<ul><li>Software&nbsp; Architect<br />定义系统行为</li></ul><div><ul><li>Technical&nbsp; Architect<br />定义有关部署所使用服务器</li></ul></div><ul>
</ul><br /><a href="https://stackoverflow.com/questions/524941/whats-the-difference-between-solutions-architect-and-applications-architect" target="_blank">https://stackoverflow.com/questions/524941/whats-the-difference-between-solutions-architect-and-applications-architect</a><br /><br /><a href="https://www.youtube.com/watch?v=zB9WuYE1REI" target="_blank">https://www.youtube.com/watch?v=zB9WuYE1REI</a><br /><img src ="http://www.blogjava.net/paulwong/aggbug/436007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2021-10-11 15:29 <a href="http://www.blogjava.net/paulwong/archive/2021/10/11/436007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>怎么提高自己的系统架构水平</title><link>http://www.blogjava.net/paulwong/archive/2021/08/04/435940.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 04 Aug 2021 03:05:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/08/04/435940.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435940.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/08/04/435940.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435940.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435940.html</trackback:ping><description><![CDATA[<a href="https://my.oschina.net/u/4662964/blog/5135740" target="_blank">https://my.oschina.net/u/4662964/blog/5135740</a><br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/435940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2021-08-04 11:05 <a href="http://www.blogjava.net/paulwong/archive/2021/08/04/435940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>21道系统设计+面向对象的面试题</title><link>http://www.blogjava.net/paulwong/archive/2020/08/02/435625.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Sun, 02 Aug 2020 08:54:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2020/08/02/435625.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435625.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2020/08/02/435625.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435625.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435625.html</trackback:ping><description><![CDATA[<h2><br /></h2><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">事不宜迟，我们马上来看这21道最受欢迎，提问率最高的系统设计+面向对象的面试题，这些问题的分析能让你轻松应对项目设计的面试。</p><h3><a href="http://blog.didispace.com/#1-%E5%A6%82%E4%BD%95%E7%94%A8Java%E8%AE%BE%E8%AE%A1%E8%87%AA%E5%8A%A8%E5%94%AE%E8%B4%A7%E6%9C%BA%EF%BC%9F-%EF%BC%88%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%89" title="1. 如何用Java设计自动售货机？ （解决方案）" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>1. 如何用Java设计自动售货机？ （解决方案）</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">你需要编写代码来设计自动售货机，该自动售货机售卖如巧克力，糖果，冷饮之类的产品，需要投入硬币进行购买，例如5分、10分、25分，50分、1元等。确保插入硬币获得产品 ，然后退回零钱。 另外，编写单元测试以证明这些常见用例有效。 如果遇到困难，可以阅读有关解决这些经典系统设计问题的两部分文章（第1部分和第2部分）。</p><h3><a href="http://blog.didispace.com/#2-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E7%B1%BB%E4%BC%BCGoo-gl%E6%88%96Bit-Ly%E7%9A%84URL%E7%BC%A9%E7%9F%AD%E6%9C%8D%E5%8A%A1%EF%BC%9F%EF%BC%88%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%89" title="2. 如何设计类似Goo.gl或Bit.Ly的URL缩短服务？（解决方案）" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>2. 如何设计类似Goo.gl或Bit.Ly的URL缩短服务？（解决方案）</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">这是一个常见的系统设计问题。 你给了一个普通长度的URL，你将如何设计为其生成较短且唯一的别名的服务？ 如果你不熟悉URL缩短程序服务，请查看一些常用的例子，例如Google的goo.gl和Twitter使用的bit.ly。确保在一些设计决策后提供数据库模式和基本原理，例如保留数据多长时间，如何获取统计信息和分析等。如果遇到问题，可以参照关于Educative上&#8220;系统设计面试课程&#8221;中给出的解决方案。</p><h3><a href="http://blog.didispace.com/#3-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E4%BA%A4%E9%80%9A%E6%8E%A7%E5%88%B6%E7%B3%BB%E7%BB%9F%EF%BC%9F" title="3.你如何设计交通控制系统？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>3.你如何设计交通控制系统？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">经典系统设计问题仍然提及频率。 确保你知道如何从一种状态过渡到另一种状态，例如从红色过渡到绿色，从绿色过渡到橙色再过渡到红色等。</p><h3><a href="http://blog.didispace.com/#4-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E9%99%90%E4%BB%B7%E5%8D%95%EF%BC%9F-%EF%BC%88%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%89" title="4. 如何设计限价单？ （解决方案）" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>4. 如何设计限价单？ （解决方案）</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">限价订单簿在证券交易所中用于根据价格和时间优先级将买入订单与卖出订单进行匹配。 你会怎么做？ 你将使用哪种数据结构？ 请记住，匹配的速度是关键，也是可靠的。 如果你需要复习数据结构，则可以查看Java课程中的数据结构和算法，如果你遇到困难，可以在这里查看我的解决方案。</p><h3><a href="http://blog.didispace.com/#5-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E7%B1%BB%E4%BC%BCPastebin%E7%9A%84%E7%BD%91%E7%AB%99%EF%BC%9F" title="5. 你如何设计类似Pastebin的网站？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>5. 你如何设计类似Pastebin的网站？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">Pastebin允许你粘贴文本或代码，然后在任意位置共享指向该代码的链接。它不是在线代码编辑器，但是你可以使用它来存储任何类型的文本。</p><h3><a href="http://blog.didispace.com/#6-%E4%BD%A0%E5%B0%86%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E8%87%AA%E5%B7%B1%E7%9A%84Instagram%EF%BC%9F-%EF%BC%88%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%89" title="6. 你将如何创建自己的Instagram？ （解决方案）" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>6. 你将如何创建自己的Instagram？ （解决方案）</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">Instagram是一个照片共享应用程序，它提供了一些自定义滤镜以提高照片质量。你的应用程序应该具有照片上传功能，为搜索标记照片以及一些基本的过滤器。如果你可以添加共享或社交网络，那就太好不过了。顺便说一句，如果你遇到困难，还可以在Educative的如何准备系统设计面试课程中看到免费的解决方案。</p><h3><a href="http://blog.didispace.com/#7-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E5%83%8FGoogle-Drive%E6%88%96Dropbox%E8%BF%99%E6%A0%B7%E7%9A%84%E5%85%A8%E5%B1%80%E6%96%87%E4%BB%B6%E5%85%B1%E4%BA%AB%E5%92%8C%E5%AD%98%E5%82%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%EF%BC%9F" title="7. 你如何设计像Google Drive或Dropbox这样的全局文件共享和存储应用程序？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>7. 你如何设计像Google Drive或Dropbox这样的全局文件共享和存储应用程序？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">这些用于存储和共享文件，照片和其他媒体。你如何设计诸如允许用户上传/查看/搜索/共享文件或照片之类的东西？跟踪文件共享的权限，并允许多个用户编辑同一文档？</p><h3><a href="http://blog.didispace.com/#8-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E7%B1%BB%E4%BC%BCWhatsapp%E6%88%96Facebook-Messenger%E7%9A%84%E8%81%8A%E5%A4%A9%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%EF%BC%9F" title="8. 你如何设计类似Whatsapp或Facebook Messenger的聊天应用程序？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>8. 你如何设计类似Whatsapp或Facebook Messenger的聊天应用程序？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">你肯定使用过WhatsApp和Facebook？没有？如果没有，我告诉你聊天应用程序允许你向你的朋友发送消息。这是点对点的连接。你保留一个朋友列表，查看他们的状态并聊天。在WhatsApp中，你也可以连接组，但适用于高级和经验丰富的开发人员。至少，你应该提供一种设计来保留好友列表并从中发送和接收消息。</p><h3><a href="http://blog.didispace.com/#9-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1Twitter%E5%85%8B%E9%9A%86%EF%BC%9F" title="9. 你如何设计Twitter克隆？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>9. 你如何设计Twitter克隆？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">Twitter是一种流行的消息服务，可让你向所有关注者广播消息。你发布推文，你的关注者可以看到这些消息，他们可以喜欢或转发。确保实现了诸如粉丝关注，主题标签，发博，删除等常用功能。如果你觉得自己有点困难，则可以按照如何应对系统设计面试的课程解决方案进行操作。</p><h3><a href="http://blog.didispace.com/#10-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E5%83%8FYouTube%E6%88%96Netflix%E8%BF%99%E6%A0%B7%E7%9A%84%E5%85%A8%E7%90%83%E8%A7%86%E9%A2%91%E6%B5%81%E6%9C%8D%E5%8A%A1%EF%BC%9F" title="10. 如何设计像YouTube或Netflix这样的全球视频流服务？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>10. 如何设计像YouTube或Netflix这样的全球视频流服务？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">设计像NetFlix或YouTube这样的视频流服务时，关键是顺畅和缓冲以及在低带宽连接上的功能，如何应对这些挑战？</p><h3><a href="http://blog.didispace.com/#11-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1ATM%E6%9C%BA%EF%BC%9F" title="11. 如何设计ATM机？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>11. 如何设计ATM机？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">ATM机允许用户存入和提取现金。它还允许用户查看其余额。你如何设计这样的系统？你面临的主要挑战是什么？</p><h3><a href="http://blog.didispace.com/#12-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1API%E9%80%9F%E7%8E%87%E9%99%90%E5%88%B6%E5%99%A8%EF%BC%9F" title="12. 如何设计API速率限制器？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>12. 如何设计API速率限制器？</strong></h3><h3><a href="http://blog.didispace.com/#13-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1Twitter%E6%90%9C%E7%B4%A2%EF%BC%9F" title="13. 你如何设计Twitter搜索？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>13. 你如何设计Twitter搜索？</strong></h3><h3><a href="http://blog.didispace.com/#14-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E7%B1%BB%E4%BC%BC%E4%BA%8EGoogle%E7%9A%84%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB%EF%BC%9F" title="14. 如何设计类似于Google的网络爬虫？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>14. 如何设计类似于Google的网络爬虫？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">网络搜寻器可以访问网站并像Google一样搜寻所有链接并将它们编入索引，以便它们以后可以出现在搜索结果中。爬网程序还可用于在一组目录中搜索特定文件，你如何设计此类文件？主要挑战是什么？</p><h3><a href="http://blog.didispace.com/#15-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1Facebook%E7%9A%84Newsfeed%EF%BC%9F%E4%BD%A0%E5%B0%86%E4%BD%BF%E7%94%A8%E5%93%AA%E7%A7%8D%E7%AE%97%E6%B3%95%EF%BC%9F" title="15. 如何设计Facebook的Newsfeed？你将使用哪种算法？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>15. 如何设计Facebook的Newsfeed？你将使用哪种算法？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">新闻源是Facebook的重要组成部分，它使用户可以查看他的世界正在发生的事情，包括朋友和家人，他喜欢的页面，他关注的组以及Facebook广告。</p><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">Newsfeed算法的作用是显示对用户来说最重要的消息，并且可以产生很高的参与度。显然，来自朋友和家人的消息应该优先处理。如果你觉得陷入困境，则可以按照如何做好系统设计面试的课程所提出解决答案。</p><h3><a href="http://blog.didispace.com/#16-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1Yelp%E6%88%96Nearby-Friends" title="16. 如何设计Yelp或Nearby Friends?" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>16. 如何设计Yelp或Nearby Friends?</strong></h3><h3><a href="http://blog.didispace.com/#17-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E5%85%A8%E7%90%83%E4%B9%98%E8%BD%A6%E6%9C%8D%E5%8A%A1E-G-Uber%EF%BC%8CGrab%E6%88%96Ola%E5%90%8E%E7%AB%AF%EF%BC%9F" title="17. 如何设计全球乘车服务E.G. Uber，Grab或Ola后端？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>17. 如何设计全球乘车服务E.G. Uber，Grab或Ola后端？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">优步（Uber）和奥拉（Ola）是最受欢迎的两种乘车服务，它将驾驶员和乘客都组合到一起。你如何设计让乘客看到附近的出租车并进行预订？</p><h3><a href="http://blog.didispace.com/#18-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1BookMyShow%EF%BC%9F" title="18. 如何设计BookMyShow？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>18. 如何设计BookMyShow？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">一个允许你预订电影院和活动门票的网站。这实际上是一家运转良好的印度创业公司。</p><h3><a href="http://blog.didispace.com/#19-%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1Quora%EF%BC%8CReddit%E6%88%96Hackernews%E7%AD%89%E7%A4%BE%E4%BA%A4%E7%BD%91%E7%BB%9C-%E7%95%99%E8%A8%80%E6%9D%BF%E6%9C%8D%E5%8A%A1%E7%BD%91%E7%AB%99%EF%BC%9F" title="19. 如何设计Quora，Reddit或Hackernews等社交网络+留言板服务网站？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>19. 如何设计Quora，Reddit或Hackernews等社交网络+留言板服务网站？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">Reddit，Quora和HackerNews是一些最受欢迎的社交网站，用户可以在其中发布问题或共享链接。其他用户可以回答问题或对共享链接发表评论。</p><h3><a href="http://blog.didispace.com/#20-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E7%B1%BB%E4%BC%BCAirbnb%E7%9A%84%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%EF%BC%9F" title="20. 你如何设计类似Airbnb的应用程序？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>20. 你如何设计类似Airbnb的应用程序？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">它允许某些用户上传房间出租，而其他用户则出租。某些功能仅适用于管理员，发布者和订阅者。</p><h3><a href="http://blog.didispace.com/#21-%E4%BD%A0%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1%E7%94%B5%E6%A2%AF%E7%B3%BB%E7%BB%9F%EF%BC%9F" title="21. 你如何设计电梯系统？" target="_blank" rel="noopener"  bluelink"="" tabindex="-1" style="border: 0px none; outline: none; color: #296bcc;"></a><strong>21. 你如何设计电梯系统？</strong></h3><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">我们大多数人都使用电梯，你在一些大型办公大楼中，你可以看到3到4部电梯。你需要为此设计软件，以便可以在不同楼层快速使用。你可以假设你有两部电梯和一栋10层楼的建筑。</p><p style="color: #1a2433; font-family: Merriweather, Georgia, serif; font-size: 16px; background-color: #fefefe;">如果你需要一些帮助，那么我建议你可在Udemy上学习如何做好系统设计面试课程，Rajat Mehta在那里有一个完整的案例研究来解决这个问题。你还将在那里学习高级系统设计，低级系统设计和数据库设计。</p><img src ="http://www.blogjava.net/paulwong/aggbug/435625.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2020-08-02 16:54 <a href="http://www.blogjava.net/paulwong/archive/2020/08/02/435625.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>淘宝千万级并发分布式架构的14次演进</title><link>http://www.blogjava.net/paulwong/archive/2019/08/16/434451.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 16 Aug 2019 02:05:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2019/08/16/434451.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/434451.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2019/08/16/434451.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/434451.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/434451.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>一、概述</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">本文以淘宝作为例子，介绍从一百个并发到千万级并发情况下服务端的架构的演进过程，同时列举出每个演进阶段会遇到的相关技术，让大家对架构的演进有一个整体的认知，文章最后汇总了一些架构设计的原则。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>二、基本概念</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在介绍架构之前，为了避免部分读者对架构设计中的一些概念不了解，下面对几个最基础的概念进行介绍：</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>1）分布式</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">系统中的多个模块在不同服务器上部署，即可称为分布式系统，如Tomcat和数据库分别部署在不同的服务器上，或两个相同功能的Tomcat分别部署在不同服务器上。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>2）高可用</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">系统中部分节点失效时，其他节点能够接替它继续提供服务，则可认为系统具有高可用性。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>3）集群</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">一个特定领域的软件部署在多台服务器上并作为一个整体提供一类服务，这个整体称为集群。如Zookeeper中的Master和Slave分别部署在多台服务器上，共同组成一个整体提供集中配置服务。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在常见的集群中，客户端往往能够连接任意一个节点获得服务，并且当集群中一个节点掉线时，其他节点往往能够自动的接替它继续提供服务，这时候说明集群具有高可用性。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>4）负载均衡</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">请求发送到系统时，通过某些方式把请求均匀分发到多个节点上，使系统中每个节点能够均匀的处理请求负载，则可认为系统是负载均衡的。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>5）正向代理和反向代理</strong></p>
<ul style="list-style-type: none; margin: 0px 0px 1em; padding: 0px; line-height: 0px;">
     <li style="margin: 0px; padding: 0px 0px 0px 9px; line-height: 28px; zoom: 1; background: url(&quot;img/bullet1.png&quot;) left 0.9em no-repeat;">系统内部要访问外部网络时，统一通过一个代理服务器把请求转发出去，在外部网络看来就是代理服务器发起的访问，此时代理服务器实现的是正向代理；</li>
     <li style="margin: 0px; padding: 0px 0px 0px 9px; line-height: 28px; zoom: 1; background: url(&quot;img/bullet1.png&quot;) left 0.9em no-repeat;">当外部请求进入系统时，代理服务器把该请求转发到系统中的某台服务器上，对外部请求来说，与之交互的只有代理服务器，此时代理服务器实现的是反向代理。</li>
</ul>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">简单来说，正向代理是代理服务器代替系统内部来访问外部网络的过程，反向代理是外部请求访问系统时通过代理服务器转发到内部服务器的过程。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>三、架构演进</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>单机架构</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5TRAP4kzbG" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">以淘宝作为例子。在网站最初时，应用数量与用户数都较少，可以把Tomcat和数据库部署在同一台服务器上。浏览器往<em>www</em>.taobao<em>.com</em>发起请求时，首先经过DNS服务器（域名系统）把域名转换为实际IP地址10.102.4.1，浏览器转而访问该IP对应的Tomcat。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">随着用户数的增长，Tomcat和数据库之间竞争资源，单机性能不足以支撑业务。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第一次演进：</strong><strong>Tomcat与数据库分开部署</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5ThIKTi6Dq" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">Tomcat和数据库分别独占服务器资源，显著提高两者各自性能。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">随着用户数的增长，并发读写数据库成为瓶颈。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第二次演进：</strong><strong>引入本地缓存和分布式缓存</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5TtIa6VPVc" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在Tomcat同服务器上或同JVM中增加本地缓存，并在外部增加分布式缓存，缓存热门商品信息或热门商品的html页面等。通过缓存能把绝大多数请求在读写数据库前拦截掉，<em>大大</em>降低数据库压力。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">其中涉及的技术包括：使用memcached作为本地缓存，使用Redis作为分布式缓存，还会涉及缓存一致性、缓存穿透/击穿、缓存雪崩、热点数据集中失效等问题。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">缓存抗住了大部分的访问请求，随着用户数的增长，并发压力主要落在单机的Tomcat上，响应逐渐变慢。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第三次演进：</strong><strong>引入反向代理实现负载均衡</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p3.pstatp.com/large/pgc-image/RSQI5U46rS0yEH" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在多台服务器上分别部署Tomcat，使用反向代理软件（Nginx）把请求均匀分发到每个Tomcat中。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">此处假设Tomcat最多支持100个并发，Nginx最多支持50000个并发，那么理论上Nginx把请求分发到500个Tomcat上，就能抗住50000个并发。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">其中涉及的技术包括：Nginx、HAProxy，两者都是工作在网络第七层的反向代理软件，主要支持http协议，还会涉及session共享、文件上传下载的问题。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">反向代理使应用服务器可支持的并发量<em>大大</em>增加，但并发量的增长也意味着更多请求穿透到数据库，单机的数据库最终成为瓶颈。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第四次演进：</strong><strong>数据库读写分离</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5UGC3HaOFm" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">把数据库划分为读库和写库，读库可以有多个，通过同步机制把写库的数据同步到读库，对于需要查询最新写入数据场景，可通过在缓存中多写一份，通过缓存获得最新数据。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">其中涉及的技术包括：Mycat，它是数据库中间件，可通过它来组织数据库的分离读写和分库分表，客户端通过它来访问下层数据库，还会涉及数据同步，数据一致性的问题。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">业务逐渐变多，不同业务之间的访问量差距较大，不同业务直接竞争数据库，相互影响性能。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第五次演进：数据库按业务分库</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5Ys1VzwsKT" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">把不同业务的数据保存到不同的数据库中，使业务之间的资源竞争降低，对于访问量大的业务，可以部署更多的服务器来支撑。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">这样同时导致跨业务的表无法直接做关联分析，需要通过其他途径来解决，但这不是本文讨论的重点，有兴趣的可以自行搜索解决方案。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">随着用户数的增长，单机的写库会逐渐会达到性能瓶颈。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第六次演进：</strong><strong>把大表拆分为小表</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p3.pstatp.com/large/pgc-image/RSQI5Z615L3Uqz" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">比如针对评论数据，可按照商品ID进行hash，路由到对应的表中存储；针对支付记录，可按照小时创建表，每个小时表继续拆分为小表，使用用户ID或记录编号来路由数据。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">只要实时操作的表数据量足够小，请求能够足够均匀的分发到多台服务器上的小表，那数据库就能通过水平扩展的方式来提高性能。其中前面提到的Mycat也支持在大表拆分为小表情况下的访问控制。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">这种做法显著的增加了数据库运维的难度，对DBA的要求较高。数据库设计到这种结构时，已经可以称为分布式数据库，但是这只是一个逻辑的数据库整体，数据库里不同的组成部分是由不同的组件单独来实现的。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">如分库分表的管理和请求分发，由Mycat实现，SQL的解析由单机的数据库实现，读写分离可能由网关和消息队列来实现，查询结果的汇总可能由数据库接口层来实现等等，这种架构其实是MPP（大规模并行处理）架构的一类实现。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">目前开源和商用都已经有不少MPP数据库，开源中比较流行的有Greenplum、TiDB、Postgresql XC、HAWQ等，商用的如南大通用的GBase、睿帆科技的雪球DB、华为的LibrA等等。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">不同的MPP数据库的侧重点也不一样，如TiDB更侧重于分布式OLTP场景，Greenplum更侧重于分布式OLAP场景。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">这些MPP数据库基本都提供了类似Postgresql、Oracle、MySQL那样的SQL标准支持能力，能把一个查询解析为分布式的执行计划分发到每台机器上并行执行，最终由数据库本身汇总数据进行返回。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">也提供了诸如权限管理、分库分表、事务、数据副本等能力，并且大多能够支持100个节点以上的集群，<em>大大</em>降低了数据库运维的成本，并且使数据库也能够实现水平扩展。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">数据库和Tomcat都能够水平扩展，可支撑的并发大幅提高，随着用户数的增长，最终单机的Nginx会成为瓶颈。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第七次演进：</strong><strong>使用LVS或F5来使多个Nginx负载均衡</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5ZHDxQFS1r" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">由于瓶颈在Nginx，因此无法通过两层的Nginx来实现多个Nginx的负载均衡。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">图中的LVS和F5是工作在网络第四层的负载均衡解决方案，其中LVS是软件，运行在操作系统内核态，可对TCP请求或更高层级的网络协议进行转发，因此支持的协议更丰富，并且性能也远高于Nginx，可假设单机的LVS可支持几<em>十万</em>个并发的请求转发；F5是一种负载均衡硬件，与LVS提供的能力类似，性能比LVS更高，但价格昂贵。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">由于LVS是单机版的软件，若LVS所在服务器宕机则会导致整个后端系统都无法访问，因此需要有备用节点。可使用keepalived软件模拟出虚拟IP，然后把虚拟IP绑定到多台LVS服务器上，浏览器访问虚拟IP时，会被路由器重定向到真实的LVS服务器，当主LVS服务器宕机时，keepalived软件会自动更新路由器中的路由表，把虚拟IP重定向到另外一台正常的LVS服务器，从而达到LVS服务器高可用的效果。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">此处需要注意的是，上图中从Nginx层到Tomcat层这样画并不代表全部Nginx都转发请求到全部的Tomcat。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在实际使用时，可能会是几个Nginx下面接一部分的Tomcat，这些Nginx之间通过keepalived实现高可用，其他的Nginx接另外的Tomcat，这样可接入的Tomcat数量就能成倍的增加。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">由于LVS也是单机的，随着并发数增长到几<em>十万</em>时，LVS服务器最终会达到瓶颈，此时用户数达到千万甚至上亿级别，用户分布在不同的地区，与服务器机房距离不同，导致了访问的延迟会明显不同。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第八次演进：</strong><strong>通过DNS轮询实现机房间的负载均衡</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p9.pstatp.com/large/pgc-image/RSQI5ZS2uQgqcv" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在DNS服务器中可配置一个域名对应多个IP地址，每个IP地址对应到不同的机房里的虚拟IP。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">当用户访问<em>www</em>.taobao<em>.com</em>时，DNS服务器会使用轮询策略或其他策略，来选择某个IP供用户访问。此方式能实现机房间的负载均衡，至此，系统可做到机房级别的水平扩展，千万级到亿级的并发量都可通过增加机房来解决，系统入口处的请求并发量不再是问题。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">随着数据的丰富程度和业务的发展，检索、分析等需求越来越丰富，单单依靠数据库无法解决如此丰富的需求。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第九次演进：</strong><strong>引入NoSQL数据库和搜索引擎等技术</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p3.pstatp.com/large/pgc-image/RSQI5Zg6I1Hn9B" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">当数据库中的数据多到一定规模时，数据库就不适用于复杂的查询了，往往只能满足普通查询的场景。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">对于统计报表场景，在数据量大时不一定能跑出结果，而且在跑复杂查询时会导致其他查询变慢，对于全文检索、可变数据结构等场景，数据库天生不适用。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">因此需要针对特定的场景，引入合适的解决方案。如对于海量文件存储，可通过分布式文件系统HDFS解决，对于key value类型的数据，可通过HBase和Redis等方案解决，对于全文检索场景，可通过搜索引擎如ElasticSearch解决，对于多维分析场景，可通过Kylin或Druid等方案解决。</p>
<div ap_container"="" style="text-align: center; width: 862px; height: auto; clear: none;"><iframe width="862" height="200" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_5" name="aswift_5" style="max-width: 100%; margin: 0px auto; display: block; left: 0px; position: absolute; top: 0px; border-width: 0px; border-style: initial; width: 862px; height: 200px;"></iframe></div>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">当然，引入更多组件同时会提高系统的复杂度，不同的组件保存的数据需要同步，需要考虑一致性的问题，需要有更多的运维手段来管理这些组件等。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">引入更多组件解决了丰富的需求，业务维度能够极大扩充，随之而来的是一个应用中包含了太多的业务代码，业务的升级迭代变得困难。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第十次演进：</strong><strong>大应用拆分为小应用</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p3.pstatp.com/large/pgc-image/RSQI5ja85PZxO1" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">按照业务板块来划分应用代码，使单个应用的职责更清晰，相互之间可以做到独立升级迭代。这时候应用之间可能会涉及到一些公共配置，可以通过分布式配置中心Zookeeper来解决。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">不同应用之间存在共用的模块，由应用单独管理会导致相同代码存在多份，导致公共功能升级时全部应用代码都要跟着升级。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第十一次演进：</strong><strong>复用的功能抽离成微服务</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p1.pstatp.com/large/pgc-image/RSQI5jp81TqVsj" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">如用户管理、订单、支付、鉴权等功能在多个应用中都存在，那么可以把这些功能的代码单独抽取出来形成一个单独的服务来管理，这样的服务就是所谓的微服务。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">应用和服务之间通过HTTP、TCP或RPC请求等多种方式来访问公共服务，每个单独的服务都可以由单独的团队来管理。此外，可以通过Dubbo、SpringCloud等框架实现服务治理、限流、熔断、降级等功能，提高服务的稳定性和可用性。</p>
<div ap_container"="" style="text-align: center; width: 862px; height: auto; clear: none;"><iframe width="862" height="200" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_6" name="aswift_6" style="max-width: 100%; margin: 0px auto; display: block; left: 0px; position: absolute; top: 0px; border-width: 0px; border-style: initial; width: 862px; height: 200px;"></iframe></div>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">不同服务的接口访问方式不同，应用代码需要适配多种访问方式才能使用服务，此外，应用访问服务，服务之间也可能相互访问，调用链将会变得非常复杂，逻辑变得混乱。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第十二次演进：</strong><strong>引入企业服务总线ESB屏蔽服务接口的访问差异</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p3.pstatp.com/large/pgc-image/RSQI5k1JJ6WBJC" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">通过ESB统一进行访问协议转换，应用统一通过ESB来访问后端服务，服务与服务之间也通过ESB来相互调用，以此降低系统的耦合程度。这种单个应用拆分为多个应用，公共服务单独抽取出来来管理，并使用企业消息总线来解除服务之间耦合问题的架构，就是所谓的SOA（面向服务）架构，这种架构与微服务架构容易混淆，因为表现形式十分相似。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">个人理解，微服务架构更多是指把系统里的公共服务抽取出来单独运维管理的思想，而SOA架构则是指一种拆分服务并使服务接口访问变得统一的架构思想，SOA架构中包含了微服务的思想。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">业务不断发展，应用和服务都会不断变多，应用和服务的部署变得复杂，同一台服务器上部署多个服务还要解决运行环境冲突的问题，此外，对于如大促这类需要动态扩缩容的场景，需要水平扩展服务的性能，就需要在新增的服务上准备运行环境，部署服务等，运维将变得十分困难。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第十三次演进：</strong><strong>引入容器化技术实现运行环境隔离与动态服务管理</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p9.pstatp.com/large/pgc-image/RSQI5kDBnIQByQ" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">目前最流行的容器化技术是Docker，最流行的容器管理服务是Kubernetes(K8S)，应用/服务可以打包为Docker镜像，通过K8S来动态分发和部署镜像。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">Docker镜像可理解为一个能运行你的应用/服务的最小的操作系统，里面放着应用/服务的运行代码，运行环境根据实际的需要设置好。把整个&#8220;操作系统&#8221;打包为一个镜像后，就可以分发到需要部署相关服务的机器上，直接启动Docker镜像就可以把服务起起来，使服务的部署和运维变得简单。</p>
<div ap_container"="" style="text-align: center; width: 862px; height: auto; clear: none;"><iframe width="862" height="200" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_7" name="aswift_7" style="max-width: 100%; margin: 0px auto; display: block; left: 0px; position: absolute; top: 0px; border-width: 0px; border-style: initial; width: 862px; height: 200px;"></iframe></div>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在大促的之前，可以在现有的机器集群上划分出服务器来启动Docker镜像，增强服务的性能，大促过后就可以关闭镜像，对机器上的其他服务不造成影响（在3.14节之前，服务运行在新增机器上需要修改系统配置来适配服务，这会导致机器上其他服务需要的运行环境被破坏）。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">使用容器化技术后服务动态扩缩容问题得以解决，但是机器还是需要公司自身来管理，在非大促的时候，还是需要闲置着大量的机器资源来应对大促，机器自身成本和运维成本都极高，资源利用率低。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>第十四次演进：</strong><strong>以云平台承载系统</strong></p>
<figure style="max-width: 100%; margin-bottom: 1em; margin-left: 0px; margin-right: 0px;"><img src="http://p3.pstatp.com/large/pgc-image/RSQI5kOBZT6v6I" alt="淘宝千万级并发分布式架构的14次演进" style="height: auto; max-width: 100%; width: auto;" /></figure>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">系统可部署到公有云上，利用公有云的海量机器资源，解决动态硬件资源的问题，在大促的时间段里，在云平台中临时申请更多的资源，结合Docker和K8S来快速部署服务，在大促结束后释放资源，真正做到按需付费，资源利用率<em>大大</em>提高，同时<em>大大</em>降低了运维成本。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">所谓的云平台，就是把海量机器资源，通过统一的资源管理，抽象为一个资源整体。在之上可按需动态申请硬件资源（如CPU、内存、网络等），并且之上提供通用的操作系统，提供常用的技术组件（如Hadoop技术栈，MPP数据库等）供用户使用，甚至提供开发好的应用。用户不需要关系应用内部使用了什么技术，就能够解决需求（如音视频转码服务、邮件服务、个人博客等）。在云平台中会涉及如下几个概念：</p>
<ul style="list-style-type: none; margin: 0px 0px 1em; padding: 0px; line-height: 0px;">
     <li style="margin: 0px; padding: 0px 0px 0px 9px; line-height: 28px; zoom: 1; background: url(&quot;img/bullet1.png&quot;) left 0.9em no-repeat;"><strong>IaaS：</strong>基础设施即服务。对应于上面所说的机器资源统一为资源整体，可动态申请硬件资源的层面；</li>
     <li style="margin: 0px; padding: 0px 0px 0px 9px; line-height: 28px; zoom: 1; background: url(&quot;img/bullet1.png&quot;) left 0.9em no-repeat;"><strong>PaaS：</strong>平台即服务。对应于上面所说的提供常用的技术组件方便系统的开发和维护；</li>
     <li style="margin: 0px; padding: 0px 0px 0px 9px; line-height: 28px; zoom: 1; background: url(&quot;img/bullet1.png&quot;) left 0.9em no-repeat;"><strong>SaaS：</strong>软件即服务。对应于上面所说的提供开发好的应用或服务，按功能或性能要求付费。</li>
</ul>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">至此，以上所提到的从高并发访问问题，到服务的架构和系统实施的层面都有了各自的解决方案，但同时也应该意识到，在上面的介绍中，其实是有意忽略了诸如跨机房数据同步、分布式事务实现等等的实际问题，这些问题以后有机会再拿出来单独讨论。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>四、 架构设计总结</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>架构的调整是否必须按照上述演变路径进行？</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">不是的，以上所说的架构演变顺序只是针对某个侧面进行单独的改进，在实际场景中，可能同一时间会有几个问题需要解决，或者可能先达到瓶颈的是另外的方面，这时候就应该按照实际问题实际解决。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">如在<em>政府</em>类的并发量可能不大，但业务可能很丰富的场景，高并发就不是重点解决的问题，此时优先需要的可能会是丰富需求的解决方案。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>对于将要实施的系统，架构应该设计到什么程度？</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">对于单次实施并且性能指标明确的系统，架构设计到能够支持系统的性能指标要求就足够了，但要留有扩展架构的接口以便不备之需。对于不断发展的系统，如电商平台，应设计到能满足下一阶段用户量和性能指标要求的程度，并根据业务的增长不断的迭代升级架构，以支持更高的并发和更丰富的业务。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>服务端架构和大数据架构有什么区别？</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">所谓的&#8220;大数据&#8221;其实是海量数据采集清洗转换、数据存储、数据分析、数据服务等场景解决方案的一个统称。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在每一个场景都包含了多种可选的技术，如数据采集有Flume、Sqoop、Kettle等，数据存储有分布式文件系统HDFS、FastDFS，NoSQL数据库HBase、MongoDB等，数据分析有Spark技术栈、机器学习算法等。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">总的来说大数据架构就是根据业务的需求，整合各种大数据组件组合而成的架构，一般会提供分布式存储、分布式计算、多维分析、数据仓库、机器学习算法等能力。而服务端架构更多指的是应用组织层面的架构，底层能力往往是由大数据架构来提供。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>有没有一些架构设计的原则？</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>1）N+1设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">系统中的每个组件都应做到没有单点故障。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>2）回滚设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">确保系统可以向前兼容，在系统升级时应能有办法回滚版本。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>3）禁用设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">应该提供控制具体功能是否可用的配置，在系统出现故障时能够快速下线功能。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>4）监控设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">在设计阶段就要考虑监控的手段。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>5）多活数据中心设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">若系统需要极高的高可用，应考虑在多地实施数据中心进行多活，至少在一个机房断电的情况下系统依然可用</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>6）采用成熟的技术</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">刚开发的或开源的技术往往存在很多隐藏的bug，出了问题没有商业支持可能会是一个灾难。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>7）资源隔离设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">应避免单一业务占用全部资源。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>8）架构应能水平扩展</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">系统只有做到能水平扩展，才能有效避免瓶颈问题</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>9）非核心则购买</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">非核心功能若需要占用大量的研发资源才能解决，则考虑购买成熟的产品。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>10）使用商用硬件</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">商用硬件能有效降低硬件故障的机率。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>11）快速迭代</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">系统应该快速开发小功能模块，尽快上线进行验证，早日发现问题<em>大大</em>降低系统交付的风险。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>12）无状态设计</strong></p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">服务接口应该做成无状态的，当前接口的访问不依赖于接口上次访问的状态。</p>
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;">设计到此结束，其实，解决方案有很多，但是这个只是我采用的，觉得最轻便的一个。</p>
<div style="margin-top: 15px; font-style: italic;">
<p style="margin: 0px 0px 1em; padding: 0px; line-height: 35px;"><strong>原创文章，转载请注明：</strong>&nbsp;转载自<a href="http://ifeve.com/" style="outline: none; color: #00a19e;">并发编程网 &#8211; ifeve.com</a><strong>本文链接地址:</strong>&nbsp;<a href="http://ifeve.com/%e6%b7%98%e5%ae%9d%e5%8d%83%e4%b8%87%e7%ba%a7%e5%b9%b6%e5%8f%91%e5%88%86%e5%b8%83%e5%bc%8f%e6%9e%b6%e6%9e%84%e7%9a%8414%e6%ac%a1%e6%bc%94%e8%bf%9b/" style="outline: none; color: #00a19e;">淘宝千万级并发分布式架构的14次演进</a></p>
</div><img src ="http://www.blogjava.net/paulwong/aggbug/434451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2019-08-16 10:05 <a href="http://www.blogjava.net/paulwong/archive/2019/08/16/434451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>