Essential characteristics of the microservice architecture: independently deployable
The home page of microservices.io lists several essential characteristics of the services that comprise a microservice architecture. This is the first in a series of blog posts that describes each of those characteristics starting with independently deployable.
The simplistic definition of independently deployable
The simplistic definition of ‘independently deployable’ is a service is packaged as a deployable or executable unit. Examples of a deployable or executable unit include: executable JAR file, WAR file, operating system executable, a Docker container image, or a Zip file that defines an AWS Lambda function. Conversely, a regular JAR file that needs to be packaged with other JARs is not a deployable or executable unit. While this meets the literal definition of ‘independently deployable’ is woefully inadequate. Let’s look at a better definition.
Independently deployable = production-ready after being tested in isolation
A much more meaningful definition of independently deployable is a service that is packaged as a deployable or executable unit and is production-ready after it has been tested in isolation. Such a service has its own source code repository and deployment pipeline. The deployment pipeline tests the service in isolation by using test doubles for its collaborators along with consumer-driven contract testing. What emerges from the deployment pipeline that is a service that can and should be deployed into production.
If you need to test your service with other services in order to verify that it’s production ready then it is not independently deployable. Moreover, you might want to consider putting those services in a single repository. It ensures that the output of your single deployment pipeline is actually production ready. It will also eliminate the complexity of developing across multiple repositories.
An important benefit of an independently deployable service is that it accelerates the deployment pipeline. It eliminates the need to slow, brittle, and complex end-to-end tests of multiple services. It also eliminates the need for teams to coordinate their and potentially obstruct one another.
Rethinking user acceptance tests
One obstacle to deploying services independently are system-level user acceptance tests. Acceptance tests are usually written from the perspective of a user and often span multiple services. A straightforward implementation of such tests would require testing multiple services together. In order for services to independently deployable, you must replace system-level user acceptance tests with service-level user acceptance tests.
An independently deployable service requires a well-defined specification
More generally, in order for a service to be testable in isolation it needs to have (a) a well-defined specification and (b) a test suite that verifies that its behavior conforms to that specification. If you cannot precisely specify a service’s behavior, you should probably reconsider whether it makes sense as a service.
Services must also collaborate through stable APIs in order avoid regularly changing in lockstep. That’s one aspect of another defining characteristic of the microservice architecture - loosely coupled - which I’ll describe in a later post.