单体架构存在很多问题,微服务的出现就是为了解决单体架构面临的困难。就目前来看,微服务本身并没有一个严格的定义,Martin Fowler是这样定义微服务的。
In short, the microservice architectural style [1] is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.
原文地址:https://martinfowler.com/articles/microservices.html
翻译:微服务架构风格是一种将一个单一应用程序开发为一组小型服务的方法,每个服务运行在自己的进程中,服务问通信采用轻量级通信机制(通常用HTTP资源APT)。这些服务围绕业务能力构建并且可通过全自动部署机制独立部署。这些服务共用一个最小型的集中式的管理,服务可用不同的语言开发,使用不同的数据存储技术。
以电影售票系统为例,使用微服务来架构该应用,架构图如下: 将整个应用分解为多个微服务,各个微服务独立运行在自己的进程中,并分别有自己的数据库,微服务之间使用REST或者其他协议通信。
综合来看,单体应用架构的缺点,恰恰是微服务的优点,而这些优点使得微服务看起来简直完美。然而完美的东西并不存在,下面来看看微服务面临的有哪些挑战。