Microservices
In software engineering, a microservice architecture is an architectural 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 a monolithic architecture. [1]
Definition
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]
Usage
It is common for microservices architectures to be adopted for
In February 2020, the Cloud Microservices Market Research Report predicted that the global microservice architecture market size will increase at a CAGR of 21.37% from 2019 to 2026 and reach $3.1 billion by 2026.[8]
History
In 1999, software developer Peter Rodgers had been working on the Dexter research project at
Also in 2005, Alistair Cockburn wrote about hexagonal 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.
Microservice granularity
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. [11][12]
Mapping Microservices to Bounded Contexts
A bounded context, a fundamental concept in Domain-Driven Design (DDD), defines a specific area within which a domain model is consistent and valid, ensuring clarity and separation of concerns. [13] 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]
Benefits
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 and legacy 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 for software modernization of legacy applications is done using an incremental approach.[21]
- Distributed development: it parallelizes refactoring.[23] Microservice-based architectures facilitate continuous integration, continuous delivery and deployment.[24]
Criticism and concerns
The microservices approach is subject to criticism for a number of issues:
- Services form information barriers.[25]
- Inter-service calls over a network have a higher cost in terms of network latency and message processing time than in-process calls within a monolithic service process.[26]
- Testing and deployment can be complicated.[27]
- 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.
Complexities
The architecture introduces additional complexity and new problems to deal with, such as
Antipatterns
- 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. [37]
- 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. The Circuit 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. [37]
Challenges
Microservices are susceptible to the fallacies of distributed computing, a series of misconceptions that can lead to significant issues in software development and deployment. [11]
Code Sharing Challenges
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. [37]
Best practices
According to O'Reilly, each microservice should have its own architectural characteristics (a.k.a non functional requirements), and architects should not define uniform characteristics for the entire distributed system.[11]
Technologies
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 (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.[38]
The Eclipse Foundation has published a specification for developing microservices, Eclipse MicroProfile.[39][40]
Service mesh
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 as Kubernetes, Nomad, Docker Swarm, or DC/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.
See also
- Conway's law
- Cross-cutting concern
- Data mesh, a domain-oriented data architecture
- DevOps
- Fallacies of distributed computing
- GraphQL
- gRPC
- Interface description language (IDL)
- Representational state transfer(REST)
- Service-oriented architecture (SOA)
- Microfrontend
- Unix philosophy
- Self-contained system (software)
- Serverless computing
- Web-oriented architecture (WOA)
References
- ISBN 978-0321127426.
- ISBN 978-1491950357.
- ISBN 978-0134602417.
- ^ Nadareishvili, I., Mitra, R., McLarty, M., Amundsen, M., Microservice Architecture: Aligning Principles, Practices, and Culture, O'Reilly 2016
- ^ Martin Fowler (28 August 2014). "Microservice Prerequisites". Archived from the original on Oct 3, 2023.
- ISBN 9781617294549.
- S2CID 204744007.
- ^ Research, Verified Market. "Cloud Microservices Market 2020 Trends, Market Share, Industry Size, Opportunities, Analysis and Forecast by 2026 – Instant Tech Market News". Retrieved 2020-02-18.
- ^ Russell, Perry; Rodgers, Peter; Sellman, Royston (2004). "Architecture and Design of an XML Application Platform". HP Technical Reports. p. 62. Retrieved 20 August 2015.
- ^ Rodgers, Peter (Feb 15, 2005). "Service-Oriented Development on NetKernel- Patterns, Processes & Products to Reduce System Complexity". CloudComputingExpo. SYS-CON Media. Archived from the original on 20 May 2018. Retrieved 19 August 2015.
- ^ ISBN 978-1492043454.
- ISBN 978-1491986363.
- ISBN 978-1492043454.
- ISBN 978-1492034025.
- ^ a b Chen, Lianping (2018). Microservices: Architecting for Continuous Delivery and DevOps. The IEEE International Conference on Software Architecture (ICSA 2018). IEEE.
- .
- ^
Dragoni, Nicola; Lanese, Ivan; Larsen, Stephan Thordal; Mazzara, Manuel; Mustafin, Ruslan; Safina, Larisa (2017). "Microservices: How to Make Your Application Scale" (PDF). Perspectives of System Informatics. Lecture Notes in Computer Science. Vol. 10742. pp. 95–104. S2CID 1643730.
- ^
Newman, Sam (2015). Building Microservices. O'Reilly. ISBN 978-1491950357.
- ^
Wolff, Eberhard (2016). Microservices: Flexible Software Architecture. Addison Wesley. ISBN 978-0134602417.
- ^ Knoche, Holger; Hasselbring, Wilhelm (2019). "Drivers and Barriers for Microservice Adoption – A Survey among Professionals in Germany". Enterprise Modelling and Information Systems Architectures. 14: 1:1–35–1:1–35. .
- ^ S2CID 28134110.
- ^ Richardson, Chris. "Microservice architecture pattern". microservices.io. Retrieved 2017-03-19.
- .
- S2CID 18802650.
- ^ Stenberg, Jan (11 August 2014). "Experiences from Failing with Microservices".
- ^ a b Martin Fowler. "Microservices". Archived from the original on 14 February 2018.
- ^ Calandra, Mariano (7 April 2021). "Why unit testing is not enough when it comes to microservices".
- ^ Lanza, Michele; Ducasse, Stéphane (2002). "Understanding Software Evolution using a Combination of Software Visualization and Software Metrics" (PDF). In Proceedings of LMO 2002 (Langages et Modèles à Objets): 135–149. Archived from the original (PDF) on Feb 27, 2021.
- ISBN 978-1-61729454-9.
- ^ Devoxx (Aug 30, 2017). "10 Tips for failing badly at Microservices by David Schmitz". YouTube. Archived from the original on Apr 22, 2021.
- ^ ISBN 978-0136524038.
- S2CID 30256045.
- S2CID 4560021.
- ^ "Developing Microservices for PaaS with Spring and Cloud Foundry".
- ^ Fowler, Martin. "Microservice Trade-Offs".
- application programming interfaces(APIs), idiosyncratic foreign function interfaces, complex ill-understood model definitions, or ad 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".
- ^ a b c Richards, Mark. Microservices AntiPatterns and Pitfalls. O'Reilly.
- ISBN 978-1717075901.
- ^ Swart, Stephanie (14 December 2016). "Eclipse MicroProfile". projects.eclipse.org.
- ^ "MicroProfile". MicroProfile. Retrieved 2021-04-11.
Further reading
- "Special theme issue on microservices". IEEE Software . 35 (3). May–June 2018.
- I. Nadareishvili et al., Microservices Architecture – Aligning Principles, Practices and Culture, O'Reilly, 2016, ISBN 978-1-491-95979-4
- S. Newman, Building Microservices – Designing Fine-Grained Systems, O'Reilly, 2015 ISBN 978-1491950357
- Wijesuriya, Viraj Brian (2016-08-29) Microservice Architecture, Lecture Notes - University of Colombo School of Computing, Sri Lanka
- Christudas Binildas (June 27, 2019). Practical Microservices Architectural Patterns: Event-Based Java Microservices with Spring Boot and Spring Cloud. Apress. ISBN 978-1484245002.