--- url: "http://microservices.io/patterns/cn/deployment/serverless-deployment.html" titulek: "Serverless deployment" h1: "Pattern: Serverless deployment" popis: "" jazyk: "" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 21:12:14" znaku: 11200 slov: 1161 kodovani: "iso-8859-2" sha256: "2bc7368bf89a1a6d54713fb9ea53988875897cd8e4cf68e900e3457398533835" --- #### [Chris Richardson 的微服务架构网站](/index.html) **本站由[Kong](https://konghq.com/)提供支持** #### 微服务架构咨询和培训服务 本站点由 Chris Richardson 编写和维护,他是经典技术著作《POJOS IN ACTION》一书的作者,也是 cloudfoundry.com 最初的创始人。Chris çš„ç ”çŠśé˘†ĺŸŸĺŒ…ć‹Ź Spring、Scala、微服务架构设计、领域驱动设计、NoSQL 数据库、分布式数据管理、事件驱动的应用编程等。Chris 是一位连续创业者,[eventuate.io](http://eventuate.io) 是他的最新创业项目,一个微服务应用和数据服务平台。 Chris 定期为企业提供微服务设计培训和实战项目的架构咨询服务。近年来 Chris 多次访问中国,为包括华为、SAPă€ćƒ ć™Žă€ä¸œéŁŽćą˝č˝Śç­‰ĺ¤§ĺž‹äźä¸šćäž›ĺžŽćœĺŠĄćžśćž„ç›¸ĺ…łçš„ćŠ€ćœŻĺ’¨čŻ˘ćœĺŠĄă€‚ĺŚ‚ć‚¨ĺ¸Œćœ›ä¸Ž Chris 深入交流,建立合作,请点击下方按钮跟他取得联系。 [预约课程](http://www.chrisrichardson.net/contactus.html) #### ĺžŽćœĺŠĄĺş”ç”¨çš„ç¤şäž‹äťŁç  为了避免纸上谈兵,Chris ćäž›äş†ä¸€ĺĽ—ä¸Žčż™äş›ć¨Ąĺźç›¸ĺ…łçš„ç¤şäž‹äťŁç ă€‚čż™çť„äťŁç ä˝żç”¨[eventuate](http://eventuate.io)框架,实现了微服务架构下分布式数据的存取。请点击下方按钮访问。 [čŽżé—ŽäťŁç ](http://eventuate.io/exampleapps.html) --- ### 模式库 ć ¸ĺżƒć¨Ąĺź - [单体架构](/patterns/cn/monolithic.html) - [微服务架构](/patterns/cn/microservices.html) 服务拆分 - [ć šćŽä¸šĺŠĄčƒ˝ĺŠ›ć‹†ĺˆ†](/patterns/cn/decomposition/decompose-by-business-capability.html) new - [ć šćŽé˘†ĺŸŸçš„ĺ­ĺŸŸć‹†ĺˆ†](/patterns/cn/decomposition/decompose-by-subdomain.html) new 部署模式 - [单主机上部署服务的多个实例](/patterns/cn/deployment/multiple-services-per-host.html) - [单主机上部署服务的单个实例](/patterns/cn/deployment/single-service-per-host.html) - [服务实例与虚拟机一一对应](/patterns/cn/deployment/service-per-vm.html) - [服务实例与容器一一对应](/patterns/cn/deployment/service-per-container.html) - [ć— ćœĺŠĄĺ™¨éƒ¨ç˝˛](/patterns/cn/deployment/serverless-deployment.html) - [服务部署平台](/patterns/cn/deployment/service-deployment-platform.html) new 需要关注的边界问题 - [微服务的基底](/patterns/cn/microservice-chassis.html) - [配置信息外部化](/patterns/cn/externalized-configuration.html) new 通讯模式 - [远程过程调用](/patterns/cn/communication-style/rpi.html) - [月息](/patterns/cn/communication-style/messaging.html) - [领域独用协议](/patterns/cn/communication-style/domain-specific.html) new - [API 网关](/patterns/cn/apigateway.html) - [服务前端的后端](/patterns/cn/apigateway.html) - [客户端服务发现](/patterns/cn/client-side-discovery.html) - [服务器端服务发现](/patterns/cn/server-side-discovery.html) - [服务注册表](/patterns/cn/service-registry.html) - [自注册](/patterns/cn/self-registration.html) - [第三方注册](/patterns/cn/3rd-party-registration.html) - [断路器](/patterns/cn/reliability/circuit-breaker.html) new 数据管理 - [每服务数据库](/patterns/cn/data/database-per-service.html) - [共享数据库](/patterns/cn/data/shared-database.html) - [事件驱动架构](/patterns/cn/data/event-driven-architecture.html) - [事件溯源](/patterns/cn/data/event-sourcing.html) - [CQRS](/patterns/cn/data/cqrs.html) - [事务日志跟踪](/patterns/cn/data/transaction-log-tailing.html) - [数据库触发器](/patterns/cn/data/database-triggers.html) - [应用程序事件](/patterns/cn/data/transactional-outbox.html) 安全模式 - [访问令牌](/patterns/cn/security/access-token.html) new 可测试性 - [服务组件测试](/patterns/cn/testing/service-component-test.html) new - [服务集成协议测试](/patterns/cn/testing/service-integration-contract-test.html) new 可观测性 - [应用日志](/patterns/cn/observability/application-logging.html) new - [ĺş”ç”¨ćŒ‡ć ‡](/patterns/cn/observability/application-metrics.html) new - [审计日志](/patterns/cn/observability/audit-logging.html) new - [分布式追踪](/patterns/cn/observability/distributed-tracing.html) new - [异常追踪](/patterns/cn/observability/exception-tracking.html) new - [健康检查](/patterns/cn/observability/health-check-api.html) new UI 模式 - [ćœĺŠĄĺ™¨çŤŻéĄľé˘ç˘Žç‰‡ĺŒ–ĺ…ƒç´ ćž„ĺťş](/patterns/cn/ui/server-side-page-fragment-composition.html) new - [厢戡獯 UI 构建](/patterns/cn/ui/client-side-ui-composition.html) new --- [订阅微服务邮件列表](http://visitor.r20.constantcontact.com/d.jsp?llr=ula8akwab&p=oi&m=1123470377332&sit=l6ktajjkb&f=15d9bba9-b33d-491f-b874-73a41bba8a76) --- 全新的微服务应用支撑平台,成功解决微服务架构下分布式数据管理的难题。 [了解更多](http://eventuate.io/) ĺŠ ĺ…Ľ [微服务架构的 Google 讨论组](https://groups.google.com/forum/#!forum/microservices)(需要翻墙) # Pattern: Serverless deployment ## Context You have applied the [Microservice architecture pattern](/patterns/microservices.html) and architected your system as a set of services. Each service is deployed as a set of service instances for throughput and availability. ## Problem How are services packaged and deployed? ## Forces - Services are written using a variety of languages, frameworks, and framework versions - Each service consists of multiple service instances for throughput and availability - Service must be independently deployable and scalable - Service instances need to be isolated from one another - You need to be able to quickly build and deploy a service - You need to be able to constrain the resources (CPU and memory) consumed by a service - You need to monitor the behavior of each service instance - You want deployment to reliable - You must deploy the application as cost-effectively as possible ## Solution Use a deployment infrastructure that hides any concept of servers (i.e. reserved or preallocated resources)- physical or virtual hosts, or containers. The infrastructure takes your service’s code and runs it. You are charged for each request based on the resources consumed. To deploy your service using this approach, you package the code (e.g. as a ZIP file), upload it to the deployment infrastructure and describe the desired performance characteristics. The deployment infrastructure is a utility operated by a public cloud provider. It typically uses either containers or virtual machines to isolate the services. However, these details are hidden from you. Neither you nor anyone else in your organization is responsible for managing any low-level infrastructure such as operating systems, virtual machines, etc. ## Examples There are a few different serverless deployment environments: - [AWS Lambda](https://aws.amazon.com/lambda/) - [Google Cloud Functions](https://cloud.google.com/functions/docs) - [Azure Functions](https://azure.microsoft.com/en-us/services/functions/) They offer similar functionality but AWS Lambda has the richest feature set. An AWS Lambda function is a stateless component that is invoked to handle events. To create an AWS Lambda function you package your the NodeJS, Java or Python code for your service in a ZIP file, and upload it to AWS Lambda. You also specify the name of function that handles events as well as resource limits. When an event occurs, AWS Lambda finds an idle instance of your function, launching one if none are available and invokes the handler function. AWS Lambda runs enough instances of your function to handle the load. Under the covers, it uses containers to isolate each instance of a lambda function. As you might expect, AWS Lambda runs the containers on EC2 instances. There are four ways to invoke a lambda function. One option is to configure your lambda function to be invoked in response to an event generated by an AWS service such as S3, DynamoDB or Kinesis. Examples of events include the following: - an object being created in a S3 bucket - an item is created, updated or deleted in a DynamoDB table - a message is available to read from a Kinesis stream - an email being received via the Simple email service. Another way to invoke a lambda function is to configure the AWS Lambda Gateway to route HTTP requests to your lambda. AWS Gateway transforms an HTTP request into an event object, invokes the lambda function, and generates a HTTP response from the lambda function’s result. You can also explicitly invoke your lambda function using the AWS Lambda Web Service API. Your application that invokes the lambda function supplies a JSON object, which is passed to the lambda function. The web service call returns the value returned by the lambda. The fourth way to invoke a lambda function is periodically using a cron-like mechanism. You can, for example, tell AWS to invoke you lambda function every five minutes. The cost of each invocation is a function of the duration of the invocation, which is measured in 100 millisecond increments, and the memory consumed. ## Resulting context The benefits of using serverless deployment include: - It eliminates the need to spend time on the undifferentiated heavy lifting of managing low-level infrastructure. Instead, you can focus on your code. - The serverless deployment infrastructure is extremely elastic. It automatically scales your services to handle the load. - You pay for each request rather than provisioning what might be under utilized virtual machines or containers. The drawbacks of serverless deployment include: - Significant limitation and constraints - A serverless deployment environment typically has far more constraints that a VM-based or Container-based infrastructure. For example, AWS Lambda only supports a few languages. It is only suitable for deploying stateless applications that run in response to a request. You cannot deploy a long running stateful application such as a database or message broker. - Limited “input sources” - lambdas can only respond to requests from a limited set of input sources. AWS Lambda is not intended to run services that, for example, subscribe to a message broker such as RabbitMQ. - Applications must startup quickly - serverless deployment is not a good fit your service takes a long time to start - Risk of high latency - the time it takes for the infrastructure to provision an instance of your function and for the function to initialize might result in significant latency. Moreover, a serverless deployment infrastructure can only react to increases in load. You cannot proactively pre-provision capacity. As a result, your application might initially exhibit high latency when there are sudden, massive spikes in load. The deployment infrastructure will internally deploy your application using one of the other patterns. It will most likely use [Service Service per Host pattern](single-service-per-host.html). - The [Multiple Service Instances per Host pattern](multiple-services-per-host.html) is an alternative deployment solution - The [Single Service per Host pattern](single-service-per-host.html) is an alternative deployment solution --- Tweet [关注本站推特账号 @crichardson](https://twitter.com/crichardson) Š 2017 Chris Richardson 版权所有 • 保留一切权利 • 本站由 [Kong](https://konghq.com/) 提供支持.