Collection of loosely coupled services used to build computer applications
In software engineering, amicroservice architecture is anarchitectural pattern that organizes an application into a collection of loosely coupled, fine-grained services that communicate through lightweight protocols. This pattern is characterized by the ability to develop and deploy services independently, improving modularity, scalability, and adaptability. However, it introduces additional complexity, particularly in managing distributed systems and inter-service communication, making the initial implementation more challenging compared to amonolithic architecture.[1]
There is no single, universally agreed-upon definition of microservices. However, they are generally characterized by a focus on modularity, with each service designed around a specific business capability. These services are loosely coupled, independently deployable, and often developed and scaled separately, enabling greater flexibility and agility in managing complex systems. Microservices architecture is closely associated with principles such as domain-driven design, decentralization of data and governance, and the flexibility to use different technologies for individual services to best meet their requirements.[2][3][4]
It is common for microservices architectures to be adopted forcloud-native applications,serverless computing, and applications using lightweightcontainer deployment. According toFowler, because of the large number (when compared to monolithic application implementations) of services, decentralized continuous delivery andDevOps with holistic service monitoring are necessary to effectively develop, maintain, and operate such applications.[5] A consequence of (and rationale for) following this approach is that the individual microservices can be individually scaled. In the monolithic approach, an application supporting three functions would have to be scaled in its entirety even if only one of these functions had a resource constraint.[6] With microservices, only the microservice supporting the function with resource constraints needs to be scaled out, thus providing resource and cost optimization benefits.[7]
Cell-based architecture is adistributed computing design in which computational resources are organized into self-contained units called cells. Each cell operates independently, handling a subset of requests while maintaining scalability, fault isolation, and availability.[2][8][9]
A cell typically consists of multiple microservices and functions as an autonomous unit. In some implementations, entire sets of microservices are replicated across multiple cells, enabling requests to be rerouted to another operational cell if one experiences a failure. This approach is intended to improve system-wide resilience by limiting the impact of localized failures.[2][8][9]
Some implementations incorporatecircuit breakers within and between cells. Within a cell, circuit breakers may be used to mitigate cascading failures among microservices, while inter-cell circuit breakers can isolate failing cells and redirect traffic to those that remain operational.[2][8][9]
Cell-based architecture has been adopted in certain large-scale distributed systems where fault isolation and redundancy are design priorities. Its implementation varies based on system requirements, infrastructure constraints, and specific operational goals.[2][8][9]
In 1999, software developer Peter Rodgers had been working on the Dexter research project atHewlett Packard Labs, whose aim was to make code less brittle and to make large-scale, complex software systemsrobust to change.[10] Ultimately this path of research led to the development ofresource-oriented computing (ROC), a generalized computation abstraction in which REST is a special subset. In 2005, during a presentation at the Web Services Edge conference, Rodgers argued for "REST-services" and stated that "Software components are Micro-Web-Services... Micro-Services are composed usingUnix-like pipelines (the Web meets Unix = trueloose-coupling). Services can call services (+multiple language run-times). Complex service assemblies are abstracted behind simpleURI interfaces. Any service, at any granularity, can be exposed." He described how a well-designed microservices platform "applies the underlying architectural principles of theWeb and REST services together with Unix-like scheduling and pipelines to provide radical flexibility and improved simplicity in service-oriented architectures.[11]
Also in 2005,Alistair Cockburn wrote abouthexagonal architecture which is a software design pattern that is used along with the microservices. This pattern makes the design of the microservice possible since it isolates in layers the business logic from the auxiliary services needed in order to deploy and run the microservice completely independent from others.
Determining the appropriate level of (micro)service granularity in a microservices architecture often requires iterative collaboration between architects and developers. This process involves evaluating user requirements, service responsibilities, and architectural characteristics, such as non-functional requirements. Neal Ford highlights the role of integrator and disintegrator factors in this context. Integrator factors, such as shared transactions or tightly coupled processes, favor combining services, while disintegrator factors, such as fault tolerance or independent scalability, encourage splitting services to meet operational and architectural goals. Additionally, fitness functions, as proposed by Neal Ford, can be used to validate architectural decisions and service granularity by continuously measuring system qualities or behaviors that are critical to stakeholders, ensuring alignment with overall architectural objectives.[12]
In microservices architectures, service granularity influences testing, deployment, performance, and reliability. Very fine-grained microservices are typically easier to test and deploy independently, but they often experience lower performance and reduced overall reliability due to increased interservice communication and more complex service choreography.[13] Coarse-grained services exhibit contrasting characteristics. They generally provide higher robustness and reliability by minimizing communication overhead and coordination complexity, but they are more challenging to test and deploy because modifications affect a broader functional scope.[13] The appropriate level of service granularity is determined by business drivers. Architectural decisions commonly begin with identifying these drivers and then aligning architectural characteristics such as performance, scalability, reliability, or deployment flexibility to support them.[13]
A bounded context, a fundamental concept indomain-driven design (DDD), defines a specific area within which a domain model is consistent and valid, ensuring clarity and separation of concerns.[12] In microservices architecture, a bounded context often maps to a microservice, but this relationship can vary depending on the design approach. A one-to-one relationship, where each bounded context is implemented as a single microservice, is typically ideal as it maintains clear boundaries, reduces coupling, and enables independent deployment and scaling. However, other mappings may also be appropriate: a one-to-many relationship can arise when a bounded context is divided into multiple microservices to address varying scalability or other operational needs, while a many-to-one relationship may consolidate multiple bounded contexts into a single microservice for simplicity or to minimize operational overhead. The choice of relationship should balance the principles of DDD with the system's business goals, technical constraints, and operational requirements.[14]
The benefit of decomposing an application into different smaller services are numerous:
Modularity: This makes the application easier to understand, develop, test, and become more resilient to architecture erosion.[15] This benefit is often argued in comparison to the complexity of monolithic architectures.[16]
Scalability: Since microservices are implemented and deployed independently of each other, i.e. they run within independent processes, they can be monitored and scaled independently.[17]
Integration of heterogeneous andlegacy systems: microservices are considered a viable means for modernizing existing monolithic software application.[18][19] There are experience reports of several companies who have successfully replaced parts of their existing software with microservices or are in the process of doing so.[20] The process forsoftware modernization of legacy applications is done using an incremental approach.[21]
Distributed development: it parallelizesdevelopment by enabling small autonomous teams to develop,deploy and scale their respective services independently.[22] It also allows the architecture of an individual service to emerge through continuousrefactoring.[23] Microservice-based architectures facilitatecontinuous integration,continuous delivery and deployment.[24]
Inter-service calls over a network have a higher cost in terms of network latency and message processing time than in-processcalls within amonolithic service process.[26]
Moving responsibilities between services is more difficult.[15] It may involve communication between different teams, rewriting the functionality in another language or fitting it into a different infrastructure.[26] However, microservices can be deployed independently from the rest of the application, while teams working on monoliths need to synchronize to deploy together.[21]
Viewing the size of services as the primary structuring mechanism can lead to too many services when the alternative of internal modularization may lead to a simpler design. This requires understanding the overall architecture of the applications and interdependencies between components.[28]
Two-phased commits are regarded as an anti-pattern in microservices-based architectures, resulting in a tighter coupling of all the participants within the transaction. However, the lack of this technology causes awkward dances which have to be implemented by all the transaction participants in order to maintain data consistency.[29]
Development and support of many services are more challenging if they are built with different tools and technologies - this is especially a problem if engineers move between projects frequently.[30]
The protocol typically used with microservices (HTTP) was designed for public-facing services, and as such is unsuitable for working internal microservices that often must be impeccably reliable.[31]
While not specific to microservices, the decomposition methodology often uses functional decomposition, which does not handle changes in the requirements while still adding the complexity of services.[31]
The very concept of microservice is misleading since there are only services. There is no sound definition of when a service starts or stops being a microservice.[31]
Data aggregation. In order to have a full view of a working system, it is required to extract data sets from the microservices repositories and aggregate them into a single schema. For example, to be able to create operational reports that are not possible using a single microservice repository.
The architecture introduces additional complexity and new problems to deal with, such aslatency,message format design,[32]backup/availability/consistency (BAC),[33]load balancing andfault tolerance.[34] All of these problems have to be addressed at scale. The complexity of amonolithic application does not disappear if it is re-implemented as a set of microservices. Some of the complexity gets translated into operational complexity.[35] Other places where the complexity manifests itself are increased network traffic and slower performance. Also, an application made up of any number of microservices has a larger number of interface points to access its respectiveecosystem, which increases the architectural complexity.[36] Various organizing principles (such ashypermedia as the engine of application state (HATEOAS), interface and data model documentation captured viaSwagger, etc.) have been applied to reduce the impact of such additional complexity.
The "data-driven migration antipattern", coined by Mark Richards, highlights the challenges of prioritizing data migration during the transition from a monolithic to a microservices architecture. To address this antipattern, an iterative approach can be helpful where application code is migrated first, with new microservices temporarily relying on the existing monolithic database. Over time, as the system is better understood, data can be decoupled and restructured, enabling individual microservices to operate with their own databases. This strategy can simplify the migration process and reduce data migration errors.[13]
The "timeout antipattern", coined by Mark Richards, describes the challenges of setting timeout values in distributed systems. Short timeouts may fail legitimate requests prematurely, leading to complex workarounds, while long timeouts can result in slow error responses and poor user experiences. Thecircuit breaker pattern can address these issues by monitoring service health through mechanisms such as heartbeats, "synthetic transactions", or real-time usage monitoring. This approach can enable faster failure detection and can improve the overall user experience in distributed architectures.[13]
Reporting on microservices data presents challenges, as retrieving data for a reporting service can either break thebounded contexts of microservices, reduce the timeliness of the data, or both. This applies regardless of whether data is pulled directly from databases, retrieved via HTTP, or collected in batches. Mark Richards refers to this as the "reach-in reporting antipattern".[13] A possible alternative to this approach is for databases to asynchronously push the necessary data to the reporting service instead of the reporting service pulling it. While this method requires a separate contract between microservices and the reporting service and can be complex to implement, it helps preserve bounded contexts while maintaining a high level of data timeliness.[13]
Microservices are susceptible to thefallacies of distributed computing – a series of misconceptions that can lead to significant issues in software development and deployment.[12]
Ideally, microservices follow a"share-nothing" architecture. However, in practice, microservices architectures often encounter situations where code must be shared across services. Common approaches to addressing this challenge include utilizing separate shared libraries for reusable components (e.g., a security library), replicating stable modules with minimal changes across services, or, in certain cases, consolidating multiple microservices into a single service to reduce complexity. Each approach has its advantages and trade-offs, depending on the specific context and requirements.[13]
Richards & Ford inFundamentals of software architecture (2020) propose each microservice should have its own architectural characteristics (a.k.a.non functional requirements), and architects should not define uniform characteristics for the entiredistributed system.[12]
To avoid having to coordinate deployments across different microservices, Sam Newman suggests keeping the interfaces of microservices stable and makingbackwards-compatible changes as interfaces evolve. On the topic of testing, Newman inBuilding Microservices (2015) proposes consumer-driven contract testing as a better alternative to traditional end-to-end testing in the context of microservices. He also suggests the use oflog aggregation and metrics aggregation as well as distributed tracing tools to ensure theobservability of systems composed of microservices.[2]
Computer microservices can be implemented in different programming languages and might use different infrastructures. Therefore, the most important technology choices are the way microservices communicate with each other (synchronous, asynchronous, UI integration) and the protocols used for the communication (e.g. RESTful HTTP, messaging,GraphQL). In a traditional system, most technology choices like the programming language impact the whole system. Therefore, the approach to choosing technologies is quite different.[37]
TheEclipse Foundation has published a specification for developing microservices, Eclipse MicroProfile.[38][39]
In a service mesh, each service instance is paired with an instance of a reverse proxy server, called a service proxy, sidecar proxy, or sidecar. The service instance and sidecar proxy share a container, and the containers are managed by a container orchestration tool such asKubernetes,Docker Swarm, orDC/OS. The service proxies are responsible for communication with other service instances and can support capabilities such as service (instance) discovery, load balancing, authentication and authorization, secure communications, and others.
^abcdRichardson, Chris (2019).Microservices patterns: with examples in Java. Shelter Island, NY: Manning Publications.ISBN978-1-61729-454-9.
^abcdChristudas, Binildas (2019).Practical Microservices Architectural Patterns: Event-Based Java Microservices with Spring Boot and Spring Cloud. Berkeley, CA: Apress L. P.ISBN978-1-4842-4501-9.
^abcLöwy, Juval (2019).Righting Software 1st ed. Addison-Wesley Professional. pp. 73–75.ISBN978-0136524038.
^Pautasso, Cesare (2017). "Microservices in Practice, Part 2: Service Integration and Sustainability".IEEE Software.34 (2):97–104.doi:10.1109/MS.2017.56.S2CID30256045.
^Pautasso, Cesare (2018). "Consistent Disaster Recovery for Microservices: the BAC Theorem".IEEE Cloud Computing.5 (1):49–59.doi:10.1109/MCC.2018.011791714.S2CID4560021.
^"BRASS Building Resource Adaptive Software Systems". U.S. Government. DARPA. April 7, 2015. "Access to system components and the interfaces between clients and their applications, however, are mediated via a number of often unrelated mechanisms, including informally documentedapplication programming interfaces (APIs), idiosyncratic foreign function interfaces, complex ill-understood model definitions, orad hoc data formats. These mechanisms usually provide only partial and incomplete understanding of the semantics of the components themselves. In the presence of such complexity, it is not surprising that applications typically bake-in many assumptions about the expected behavior of the ecosystem they interact with".
Christudas Binildas (June 27, 2019). Practical Microservices Architectural Patterns: Event-Based Java Microservices with Spring Boot and Spring Cloud. Apress.ISBN978-1484245002.