博客系统的架构思考(中)--静态与CQRS_html/css_WEB-ITnose
对于复杂的系统来说,上一篇的做法做确实很不错。但是对于一个简单地系统来说,这样做是不是玩过火了?如果我们要设计一个博客系统的话,那么我们是不是可以考虑将Write/Read分离就可以了?
CQS
命令和查询责任分离Command Query Responsibility Segregation(CQRS)是一种将系统的读写操作分离为两种独立模型的架构模式。
对于这个架构的深入思考是起源于之前在理解DDD。据说在DDD领域中被广泛使用。理解CQRS可以用分离Model和API集合来处理读取和写入请求开始,即CQS(Command Query Separation,命令查询分离)模式。CQS模式最早由软件大师Bertrand Meyer(Eiffel语言之父,面向对象开-闭原则 OCP 提出者)提出。他认为,对象的行为仅有两种:命令和查询。
这个类型的架构如下图所示:
除了编写优化的查询类型,它可以让我们轻松换API的一部分读一些缓存机制,甚至移动读取API的请求到另一台服务器。
对于读取和写入相差不多的应用来说,这种架构看起来还是不错的。而这种架构还存在一个瓶颈问题,使用同一个RDBMS。对于写入多、读取少的应用来说,这种架构还是存在着不合理性。
为了解决这个问题,人们自然是使用缓存来解决这个问题了。我们在我们的应用服务外有一个HTTP服务器,而在HTTP服务器之外有一个缓存服务器,用于缓存用户常驻的一些资源。如下图所示:
而实际上这样的服务器可能是多余的——我们为什么不直接生成HTML就好了?
编辑-发布分离
或许你听过Martin Folwer提出的编辑-发布分享式架构:即文章在编辑时是一个形式,而发表时是另一个形式,比如用markdown编辑,而用html发表。
而最典型的应用就是流行于GitHub的Hexo、Jekyll框架之类的静态网站。如下图所示的是Hexo的工作流:
我们在本地生成我们的项目,然后可以创建一个新的博客、开始编写内容等等。接着,我们可以在本地运行起这个服务,除了查看博客的内容,还可以修改样式等等。完成上面的工作后,我们就可以生成静态内容,然后部署我们的应用到GitHub Page上。
这一切看上去都完美,我们有两个不同的数据源——一个是md格式的文本,一个是最后生成的html。它们已经实现了读写/分离:
但是作为一个前端开发人员,没有JSON,用不了Ajax请求,我怎么把我的博客 做成一个单页面应用?
编辑-发布-开发分离
因为我们需要交我们的博客转为JSON,而不是一个hexo之类的格式。有了这些JSON文件的存在,我们就可以把Git当成一个NoSQL数据库。同时这些JSON文件也可以直接当成API来
其次,这些博客还需要hexo一样生成HTML。
并且,开发人员在开发的时候不会影响到编辑的使用,于是就有了下面的架构:
在这其中我们有两种不同的数据形式,即存储着Markdown数据的JSON文件和最后生成的HTML。
对博客数量不是很大的网站,或者说一般的网站来说,用上面的技术都不是问题。然而有大量数据的网站怎么办?使用EventBus
在我之前玩的一个Demo中,使用Python中的Scrapy爬虫来抓取现有的动态网站,并将其变成静态网站部署到AWS S3上。
但是如果仅仅只是如何,我们还存在一些问题:
-
搜索功能
-
AutoComplete
等等。
你有什么想法呢?我想你已经猜到下一篇的标题~~,这里就不透露了——我们都已经分析了动态博客和静态博客了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...
