Serverless architecture without understanding the principles of service (a)

Read catalog

One: What is a serverless no service?

Serverless Chinese meaning is "serverless" but it really means is that developers no longer have to give much thought to the problem server, but it does not mean the removal of the server, but we rely on third-party back-end server resources, such as using Amazon Web services (AWS) Lambda. computing services to execute code, then Serverless architecture is divided into Backend as a service (BaaS) and Functions as a service (FaaS) two technologies, Serverless it is run server-side logic implemented by the developer at stateless computing container, which is triggered by an event, completely managed by third parties.

What is BaaS?

Baas in English, translated into Chinese meaning: that is the back-end services, its application architecture consists of a large number of third-party cloud server and API consisting of the application logic and state on the server by the service provider to manage. For example, our typical single-page application SPA and mobile APP rich client applications, mainly in the front and rear end interactive RestAPI calls based. Just call the service provider to complete the appropriate API functions, such as common authentication, cloud data / file storage, message push, application data analysis.

What is FaaS?

FaaS can be called: a service function. Developers can directly deploy the service business logic code, running in stateless computing container provided by third parties, developers only need to write code to business, without paying attention to the server, and execute the code it is triggered by an event. AWS Lambda which is one of the best FaaS achieved.

Serverless application architecture is BaaS and FaaS together applications, users only need to focus on the business logic of the application code, written as a function of particle size will run on FaaS platform and third-party services and BaaS together, and finally build a complete system. The whole system is completely without concern for the server process.

Two: the difference between architecture and the traditional model?

Traditional architectures mode is to use C / S architecture, in a typical web application, the server receives HTTP request processing front-end, or before saving the database query, data may be applied through a plurality of layers, eventually returns a backend response. For example it may be other formats as JSON or the like. He then will respond back to the client, such as shown below:

In the traditional development model, the development process: designer page -> server-side and front-end developers are developing, developed after a server -> Service Deployment -> service after deployment is complete, that is, the front and rear ends of the FBI -> the front and rear ends of the FBI -> the front and rear ends of the test is completed FBI, -> test, the test needs to complete the line, so -> on-line, on-line after the completion of required maintenance operation and maintenance, and therefore -> operation and maintenance. In the traditional development mode, developing an application, do from the beginning to the on-line requires different roles of different things, communication costs are very large, and the operation and maintenance process needs to take into account the load balancing servers, services, clustering, caching,
messaging redundant data transmission and so on these things, the presence of the above problems in the conventional current mode. You can use the following schematic view of the process described above. As shown below:

In Serverless architecture, application business logic architecture is based FaaS forming a plurality of independent functional components. And in the form of API services to provide services outside, in FaaS, the back-end application is split into a functions, we only need to write to deploy to serverless service after the completion of the function. We do not care about the subsequent operation of any server. Then the whole process would only role we need a front-end engineers to complete all the development work, the communication costs reduced. Therefore, we can use the following procedure project Schematically, as shown below:

Front-end engineers are living in serverless to write back-end services, typical is living writing code in AWS Lambda, AWS in support different languages.
Lambda computing services it is able to execute code in a massively parallel fashion in response to events. By using Lambda and the use of a variety of powerful API and Web services, developers can quickly build loosely coupled, scalable and efficient architecture system.

注意:Lambda是什么?它是一种计算服务,它在AWS基础上执行用javascript、node.js、Python、C#或java编写的代码,源代码将被打包并部署到孤立的容器中,该容器有单独分配的内存、磁盘空间和处理器。代码、配置和依赖项的组合被称作为Lambda函数。

三:serverless优缺点?

优点有如下:

1. 降低创业公司启动成本

当一家创业公司的时候,在开发web的时候,我们需要版本管理服务器、持续集成服务器、测试服务器、应用版本管理仓库等作为基础服务。
线上运行的时候,为了应对大量的请求,我们还需要一个好的数据库服务器。当我们应用面向普通的用户时,我们需要:

1.1 邮件服务,用于发送提醒,注册等服务。
1.2 短信服务,用于注册,登录等用户授权操作。

如上一些对于大公司来讲,都有现成的基础设施。可是对于创业公司来讲。这都需要一些启动成本。但是如果我们使用serverless就可以降低这些成本。

2. 减少运营成本

对于创业公司来讲,他们没有基础设施,没有财力,也可能没有能力去建设基础设施,采用云服务是最好的选择,可以为他们节省大量的资金。
他们只要将精力放在对用户价值的产品之上即可,他们不需要自己去搭建服务器,因此会有更多的时间去开发业务功能。而采用函数计算的serverless与云服务器最大的区别是:云服务器需要一直运行,比如说月费或年费要多少钱租,但是serverless是按需计费的,如果有请求到来的时候,才运行函数,否则的话,是不需要钱的。

3. 降低开发成本

serverless会提供一系列的配套服务,比如 我们只需要在配置文件上写下数据库的表名,那么数据就会存储到对应的数据库里面,并且会提供一系列的函数计算模板,我们只需要写好我们的配置即可,那么这一系列的东西都可以自动,高效的完成任务。

4. 实现快速上线

对于一些传统项目来讲,我们在本地开发需要部署环境,到开发环境或测试环境,我们还是需要部署环境。但是serverless可以在部署上有优势,并且很轻松的实现上线。因为serverless内部相当于有 内建自动化部署功能,并且在该里面都是由供应商提供的功能,每次我们写完业务代码后,我们只需要运行下即可,在AWS Lambda 函数计算里面,函数一般在上传后几秒钟内,就能做好调用准备。

5. 系统安全性更高。

要保持服务器一直运行不是件容易的事情,并且还需要考虑黑客不同类型的攻击,但是有serverless后,我们不需要考虑这些问题了,这些问题第三方供应商已经会帮我解决这些问题的。

6. 能适应微服务架构和扩展性能力强

Serverless 的背后是 诸如 AWS Lambda 这样的 FaaS(Function as a Services)。

对于传统应用来说,要应对更多的请求的方式,就是部署更多的实例。然而,这个时候往往已经来不及了。而对于 FaaS 来说,我们并不需要这么做,FaaS 会自动的扩展。它可以在需要时尽可能多地启动实例副本,而不会发生冗长的部署和配置延迟。

以亚马逊的AWS Lambda为案例,Lambda能让我们不用思考任何服务器,也就是说,不用我们处理服务器上的部署,服务器的容量和服务器的扩展和失败容错,还有服务器上选择什么OS操作系统,语言的更新,日志等等问题。你的应用程序只需要和多个第三方的API或服务打交道,也可以自我创建一个无服务器的
API。

缺点有如下:

1. 不适合长时间运行应用

serverless 在请求到来的时候才运行,当应用不运行的时候会进入 "休眠状态",下次当请求来临时,应用将会需要一个启动时间,可以叫 冷启动,如果我们的应用需要一直长期不间断的运行,处理大量的请求,那么可能就不适合使用serverless来架构了,如果这种情况下,我们需要使用像EC2这样的云服务器会是一个更好的选择。

EC2相当于我们自己买了一辆车,在Lambda 相当于我们租了一辆车。如果我们长期租车的话,那么肯定比买车更贵,但是租车可以减少一部分车维护成本。

2. 完全会依赖于第三方服务

如果我们所有和应用相关的服务放在第三方服务上的话,就可能会涉及到安全性问题,因此我们可以将不重要的API或服务放在serverless上。
当然如果我们自己有服务设施的话,那肯定使用自己的设施服务的,当我们自己使用serverless架构的时候,那么我们就已经和供应商绑定了。
如果这个时候我们将服务迁到别的云服务商上就没有那么容易了。

3. 缺乏调式和开发工具,排查问题困难。

4. 无法用于高并发运用。

为每个请求启动一个进程开销太高,流量瞬间爆发容易超时。比如淘宝的双十一支付宝高峰期,每秒处理交易笔数8万多笔,也就意味着我们的系统内每秒有8万多个进程创建又被销毁。那么这样就会造成系统开销很大。解释和第一点一样的原理。

四:使用serverless的应用场景有哪些?

Serverless 适合构建比较简单的应用,比如上传一张图片,对一段音频/视频进行编码或解码,对请求返回一小段数据等。

Serverless架构主要有以下特点:

1. 实现了细粒度的计算资源分配。
2. 不需要预分配资源。
3. 具备真正意义上的高度扩容和弹性。
4. 按需使用,按需计费。

因此以下应用将可能使用serverless架构:

1. 静态网站的管理。
2. 替代WordPress(Serverless Blog Project)
3. 个人媒体服务器(less!)
4. 物联网Iot或家庭自动框架或项目 (使用 AWS IoT)

Guess you like

Origin www.cnblogs.com/tugenhua0707/p/10991363.html