文档结构  
翻译进度:44%     翻译赏金:0 元 (?)    ¥ 我要打赏

约翰弗里泽尔,一位红帽的手机平台架构师,进行了一场有关微服务的演讲,其中包含了一些有关微服务的很棒的建议。最重要的是,他提供了一些有关何时,哪里以及为什么你应该(或者为什么你不应该)部署微服务的建议。

什么是微服务

微服务是将一种应用分解成一系列微小、轻量级的服务,这些服务通过HTTP进行通讯。建立一项单独的微服务是容易的,建立微服务架构是相当难的。微服务基本上是分布式系统的设计与开发。如果你要开始进行一项新的微服务架构,你可能会面临一些挑战。

第 1 段(可获 1.33 积分)

微服务的八个挑战

构建微服务

  • 如何识别服务之间的依赖?一个服务的改变导致几个服务的重新构建。
  • 必须仔细跟踪单个服务的多个版本,决定哪些服务的哪些版本组成一个发布版。

测试

  • 根据定义,对微服务进行单元测试非常容易。
  • 集成测试需要列出哪些是实际需要测试的,哪些是周边的?
  • 端到端的测试需要对正确的版本覆盖到整个微服务架构。但是微服务的特点又是所有版本都是独立的,这就很难决定你究竟需要测试其他微服务的什么版本。
第 2 段(可获 1.31 积分)

版本控制

  • 每个服务都有唯一、独立的版本。
  • 微服务的集合会有一个版本。
  • 随着时间推移,维护版本矩阵变得尤其复杂。
  • 如何发布并保持后期的兼容性?你有维护老代码并添加新功能么?这会导致代码膨胀,并且违背了微服务的本质。其他的选择是发布不断变化的版本,这样你在同一时刻必须发布多个独立的版本。

部署

  • 由于手动部署系统太复杂,发布微服务需要强大的自动化功能。
  • Blue/Green deployment对微服务来说是理想的部署方法。系统太复杂,不能尝试回退改变。
第 3 段(可获 1.59 积分)

日志记录

  • 微服务需要集中记录,因为没有地方能判断到底是怎么回事。登录成百上千的服务来查询日志是非常无用的。
  • 你还需要一些全球请求跟踪类型,给每个请求分配一个请求ID,这样你可以判断事物的流程。

监控

  • 微服务应该随着中央面板一起部署。监控多个微服务是一项非常艰巨的工作,你需要一些东西汇总服务数据。
  • 监控方案还需要包含分布式请求跟踪。微服务架构需要一项机制通过服务以及衡量绩效来可视化请求标识。一个慢微服务可以减缓应用程序停止。
第 4 段(可获 1.5 积分)

Debugging

  • Root cause analysis – how to determine where the problem exists with microservices? It is virtually impossible to tell where the failure is without the monitoring solution. Only then can you begin to isolate the actual problem.
  • Remote debugging is not feasible across many microservices at once. You need to be able to iterate the microservice versions very quickly, sometimes guessing to solve your problem.

Connectivity

  • Microservice architectures should include a service discovery registry. You don’t want to hardcode URLs into your microservices, especially with moving between CI/CD environments. How do they contact each other? How do they contact the right version of each other?
  • Network – there are network hops between each service, these add latency and possibly data loss between each service. Your architecture needs to accommodate failures gracefully. Build in short TTLs, fail quickly to bubble up the failures rather than a slow crawl to death. Failing quickly lets you retry quickly.
第 5 段(可获 1.95 积分)

When should you consider moving to microservices?

Traditional monolithic architectures have their own unique and well-understood challenges. If you are starting to see these block development efforts, microservices might be your answer.

Size

  • The monolith application code base size has grown too large for local development. Can you even load all the code in your IDE at once?

Stack

  • Your monolith will be a single technology stack rather than the right stack for the right purpose.
  • The initial large jump from one stack to another is very difficult, subsequent jumps are much easier to make.
第 6 段(可获 1.19 积分)

Failure

  • If anything fails in a monolith, everything fails… it is all one system.
  • Much larger surface area to attack and to be exposed to external conditions

Scaling

  • Only really can scale a monolith vertically, you have to increase everything at the same time. This leads to excessive cost and resource consumption.
  • A few large VMs are usually much more expensive than many small VMs or containers

Developer Productivity

  • Developers cannot work independently, rather in fewer, and larger teams.
  • In a single code-base, CI takes much longer occurs much less frequently. You typically have to wait for nightly or weekly builds to see if anything breaks.
第 7 段(可获 1.33 积分)

If you do decide to move to microservices, you might realize these benefits:

  • Agility and flexibility.
  • Smaller code-base, easier to wrap head around.
  • More, smaller teams rather than one larger team.
  • Easier to scale microservices, only scale the ones that are hot.
  • Right stack for the right job, you are no longer bound to one stack.

If you are going to run microservices, understand why and what benefits you will receive. Start out from day one with automation. Trying to add it later will ultimately make your effort fail, you need to invest in the automation before starting to build.

第 8 段(可获 1.25 积分)

Finally, remember Conway’s law – moving to microservices will likely require an “Agile Transformation”. Your organization should mirror the microservice architecture.

For a framework for building enterprise Java microservices visit WildFly Swarm and download the cheat sheet.

第 9 段(可获 0.46 积分)

文章评论