联系
Knight's Tale » 架构

架构:微服务

2015-06-30 17:28

Microservices

http://martinfowler.com/articles/microservices.html

We do not claim that the microservice style is novel or innovative, its roots go back at least to the design principles of Unix. But we do think that not enough people consider a microservice architecture and that many software developments would be better off if they used it.

Characteristics of a Microservice Architecture

Componentization via Services

模块即服务

Microservice architectures will use libraries, but their primary way of componentizing their own software is by breaking down into services. We define libraries as components that are linked into a program and called using in-memory function calls, while services are out-of-process components who communicate with a mechanism such as a web service request, or remote procedure call. (This is a different concept to that of a service object in many OO programs [3].)

微服务使用库,库定义成是内存里的调用,而微服务则定义成是web请求或远程调用。

One main reason for using services as components (rather than libraries) is that services are independently deployable.

独立可部署

Another consequence of using services as components is a more explicit component interface.

接口调用

Using services like this does have downsides. Remote calls are more expensive than in-process calls, and thus remote APIs need to be coarser-grained, which is often more awkward to use. If you need to change the allocation of responsibilities between components, such movements of behavior are harder to do when you're crossing process boundaries.

缺点是远程调用比本地要重很多

Organized around Business Capabilities

按业务逻辑来进行分配

Products not Projects

分成产品 而不是项目

A common inspiration for this is Amazon's notion of "you build, you run it" where a development team takes full responsibility for the software in production.

Smart endpoints and dumb pipes

The two protocols used most commonly are HTTP request-response with resource API's and lightweight messaging[6].

使用http请求或者是消息

The second approach in common use is messaging over a lightweight message bus. The infrastructure chosen is typically dumb (dumb as in acts as a message router only) - simple implementations such as RabbitMQ or ZeroMQ don't do much more than provide a reliable asynchronous fabric - the smarts still live in the end points that are producing and consuming messages; in the services.

一般使用消息来做轻量级的消息总线,做异步,关键是统一协议,例如 RMQ的 AMQP协议

Decentralized Governance

分散管理

Splitting the monolith's components out into services we have a choice when building each of them. You want to use Node.js to standup a simple reports page? Go for it. C++ for a particularly gnarly near-real-time component? Fine. You want to swap in a different flavour of database that better suits the read behaviour of one component? We have the technology to rebuild him.

各个模块可以采用各种实现来做

For the microservice community, overheads are particularly unattractive. That isn't to say that the community doesn't value service contracts. Quite the opposite, since there tend to be many more of them. It's just that they are looking at different ways of managing those contracts. Patterns like Tolerant Reader and Consumer-Driven Contracts are often applied to microservices.

可以使用 容忍读策略 和 消费者契约 来解决上下游通信的问题。

Decentralized Data Management

Using transactions like this helps with consistency, but imposes significant temporal coupling, which is problematic across multiple services. Distributed transactions are notoriously difficult to implement and and as a consequence microservice architectures emphasize transactionless coordination between services, with explicit recognition that consistency may only be eventual consistency and problems are dealt with by compensating operations.

使用最终一致性,并用补偿策略来解决问题。

可以使用消息来解决此问题。

Infrastructure Automation

Continuous Delivery 、Continuous Integration.

持续交付和持续集成

Design for failure

Synchronous calls considered harmful

同步调用是非常有害的。

their platform API redesign has built asynchronicity into the API fabric.

Evolutionary Design

引用

  • ServiceOrientedAmbiguity http://martinfowler.com/bliki/ServiceOrientedAmbiguity.html 大概是讲SOA的概念太广泛,想讲的东西太多
  • 容忍读策略 http://www.liaoqiqi.com/post/241
  • 消费者契约 http://www.liaoqiqi.com/post/242
本文链接地址:架构:微服务