Microservices Explained

In software engineering, a microservice architecture is an architectural pattern that arranges an application as a collection of loosely coupled, fine-grained services, communicating through lightweight protocols. One of its goals is to enable teams to develop and deploy their services independently. This is achieved by reducing several dependencies in the codebase, allowing developers to evolve their services with limited restrictions, and hiding additional complexity from users.[1] Consequently, organizations can develop software with rapid growth and scalability, as well as use off-the-shelf services more easily. Communication requirements are reduced. These benefits come with the cost of maintaining decoupling, so a microservice architecture may be suitable only if the application is too complex to manage as a monolith.[2] Interfaces need to be designed carefully and treated as public API. One technique used is having multiple interfaces on the same service or multiple versions of the same service to avoid disrupting existing users of the code.

A microservice is analogous to bounded context in domain-driven design.[3]

Introduction

There is no single definition for microservices. A consensus has evolved over time in the industry. Some of the defining characteristics that are frequently cited include:

A microservice is not a layer within a monolithic application (for example, the web controller or the backend-for-frontend).[8] Rather, it is a self-contained piece of business functionality with clear interfaces, and may, through its own internal components, implement a layered architecture. From a strategic perspective, microservice architecture essentially follows the Unix philosophy of "Do one thing and do it well".[9] Martin Fowler describes a microservices-based architecture as having the following properties:[4]

It is common for microservices architectures to be adopted for cloud-native applications, serverless computing, and applications using lightweight container deployment. According to Fowler, because of the large number (when compared to monolithic application implementations) of services, decentralized continuous delivery and DevOps with holistic service monitoring are necessary to effectively develop, maintain, and operate such applications.[13] 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.[14] With microservices, only the microservice supporting the function with resource constraints needs to be scaled out, thus providing resource and cost optimization benefits.[15]

History

There are numerous claims as to the origin of the term microservices. As early as 2005, Peter Rodgers introduced the term "Micro-Web-Services" during a presentation at the Web Services Edge conference. Against conventional thinking and at the height of the SOAP service-oriented architecture (SOA) hype curve he argued for "REST-services" and on slide #4 of the conference presentation, he discusses "Software components are Micro-Web-Services". He goes on to say "Micro-Services are composed using Unix-like pipelines (the Web meets Unix = true loose-coupling). Services can call services (+multiple language run-times). Complex service assemblies are abstracted behind simple URI interfaces. Any service, at any granularity, can be exposed." He described how a well-designed microservices platform "applies the underlying architectural principles of the Web and REST services together with Unix-like scheduling and pipelines to provide radical flexibility and improved simplicity in service-oriented architectures.[16]

Rodgers' work originated in 1999 with the Dexter research project at Hewlett Packard Labs, whose aim was to make code less brittle and to make large-scale, complex software systems robust to change.[17] Ultimately this path of research led to the development of resource-oriented computing (ROC), a generalized computation abstraction in which REST is a special subset.

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.

In 2007, Juval Löwy in his writing[18] and speaking[19] [20] called for building systems in which every class was a service. Löwy realized this required the use of a technology that can support such granular use of services, and he extended Windows Communication Foundation (WCF) to do just that,[21] [22] taking every class and treating it as a service while maintaining the conventional programming model of classes.

In May 2011, a workshop of software architects held near Venice used the term 'microservice' to describe a common architectural style that many participants had been recently exploring.[23] By May 2012, the same group had decided that 'microservices' was the most appropriate name. James Lewis presented some of those ideas as a case study in March 2012 at 33rd Degree in Kraków in Microservices - Java, the Unix Way,[24] as did Fred George[25] about the same time. Adrian Cockcroft, former director for the Cloud Systems at Netflix,[26] described this approach as "fine-grained SOA", pioneered the style at web-scale, as did many of the others mentioned in this article - Joe Walnes, Dan North, Evan Bottcher, and Graham Tackley.[27]

Microservices is a specialization of an implementation approach for service-oriented architectures used to build flexible, independently deployable software systems.[28] The microservices approach is the first realisation of SOA that followed the introduction of DevOps and is becoming more popular for building continuously deployed systems.[29]

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.[30]

Service granularity

A key step in defining a microservice architecture is figuring out how big an individual microservice has to be. There is no consensus or litmus test for this, as the right answer depends on the business and organizational context.[31] For instance, Amazon uses a service-oriented architecture where service often maps 1:1 with a team of 3 to 10 engineers.[32]

To find the right level of service granularity, architects have to continuously iterate their component designs with programmers. Architects need to take into account user requirements, responsibilities, and architectural characteristics (aka non-functional requirements).

In the context of software architecture, services dedicated to a single task, such as calling a specific backend system or performing a particular calculation, are known as atomic services. Services that call atomic services to consolidate an output are referred to as composite services.

It is considered bad practice to make the service too small, as then the runtime overhead and the operational complexity can overwhelm the benefits of the approach. When services become too fine-grained, alternative approaches should be considered, such as packaging the function as a library or integrating it into other microservices.

If domain-driven design is being employed in modeling the domain for which the system is being built, then a microservice could be as small as an aggregate or as large as a bounded Context.[33]

In the granularity of microservices discussion, there is a spectrum. On one end are the Anaemic Services, which do not have a large number of responsibilities, and on the other end are the Modular Monolith, which are large modules of a system.

Benefits

The benefit of decomposing an application into different smaller services are numerous:

Criticism and concerns

The microservices approach is subject to criticism for a number of issues:

Complexities

The architecture introduces additional complexity and new problems to deal with, such as latency, message format design,[51] backup/availability/consistency (BAC),[52] load balancing and fault tolerance.[53] All of these problems have to be addressed at scale. The complexity of a monolithic application does not disappear if it is re-implemented as a set of microservices. Some of the complexity gets translated into operational complexity.[54] Other places where the complexity manifests itself are increased network traffic and resulting in slower performance. Also, an application made up of any number of microservices has a larger number of interface points to access its respective ecosystem, which increases the architectural complexity.[55] Various organizing principles (such as hypermedia as the engine of application state (HATEOAS), interface and data model documentation captured via Swagger, etc.) have been applied to reduce the impact of such additional complexity.

Best practices

According O'Reilly, each microservice should have its own architectural characteristics (a.k.a non functional requirements), and architects should not to define uniform characteristics for the entire distributed system.

Latency is often measured through "99th percentile" because median and average latencies can be misleading as they can miss outliers. [56] [57]

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.[58]

The Eclipse Foundation has published a specification for developing microservices, Eclipse MicroProfile.[59] [60]

Service mesh

See also: 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.

In a service mesh, the service instances and their sidecar proxies are said to make up the data plane, which includes not only data management but also request processing and response. The service mesh also includes a control plane for managing the interaction between services, mediated by their sidecar proxies.

A comparison of platforms

Implementing a microservice architecture is very difficult. There are many concerns (see table below) that any microservice architecture needs to address. Netflix developed a microservice framework to support their internal applications, and then open-sourced many portions of that framework. Many of these tools have been popularized via the Spring Framework – they have been re-implemented as Spring-based tools under the umbrella of the Spring Cloud project. The table below shows a comparison of an implementing feature from the Kubernetes ecosystem with an equivalent from the Spring Cloud world. One noteworthy aspect of the Spring Cloud ecosystem is that they are all Java-based technologies, whereas Kubernetes is a polyglot runtime platform.

Microservices concernSpring Cloud & Netflix OSSKubernetes
Configuration management:[61] configuration for a microservice application needs to be externalized from the code and be retrievable via a simple service call.Spring Config Server, Netflix Archaius both support a Git-repository—based location for configuration. Archaius supports data typing of configuration.Kubernetes ConfigMaps exposes the configuration stored in etcd via services. Kubernetes Secrets supports the service-based secure deployment and usage of sensitive configuration information (such as passwords, certificates, etc.).
Service discovery

maintain a list of service instances that are available for work within a microservice domain.

Spring Cloud Eureka allows clients to register to it, maintains a heartbeat with registered clients, and maps service names to hostnames for clients that lookup services by service name.Kubernetes Services provide deployment-time registration of instances of services that are internally available within the cluster. Ingress is a mechanism whereby a service can be exposed to clients outside the cluster.
Load balancing: The key to scaling a distributed system is being able to run more than one instance of a component. Load has to be then distributed across those instances via a load balancer.Spring Cloud Ribbon provides the ability for service clients to load balance across instances of the service.Kubernetes Service provides the ability for the service to be load-balanced across service instances. This is not the equivalent of what Ribbon provides.
API gateway: The granularity of APIs provided by microservices is often different than what a service client needs. API Gateways implement facades and provide additional services like proxying, and protocol translation, and other management functions.Spring Cloud Zuul provides configuration-based API facadesKubernetes Service and Ingress resources, Istio, Ambassador are solutions that provide both north–south (traffic into and out of data center) as well as east–west (traffic across data centers or clouds or regions) API gateway functions. Zuul can also be implemented along with Kubernetes, providing configuration at individual service level.
Security concerns: Many security concerns are pushed to the API gateway implementation. With distributed microservice applications, it makes sense to not reinvent the security wheel and allow for policy definition and implementation in components that are shared by all services.Spring Cloud Security addresses many security concerns through Spring Cloud ZuulThe Kubernetes ecosystem provides service meshes like Istio, which are capable of providing security through their API gateway mechanisms.
Centralized logging: It is important to have a centralized log gathering and analysis infrastructure to manage a plethora of services – many of which are operating in a distributed fashion.ELK Stack (Elasticsearch, Logstash, Kibana)EFK Stack (Elasticsearch, Fluentd, Kibana)
Centralized metrics: A centralized area where the health and performance of the individual services and overall system can be monitored is essential to proper operations.Spring Spectator & AtlasHeapster, Prometheus, & Grafana
Distributed tracing: Per-process logging and metric monitoring have their place, but neither can reconstruct the complex paths that transactions take as they propagate across a distributed system. Distributed tracing is an essential tool for a microservices platform.Spring Cloud SleuthHawkular, Jaeger
Resilience and fault tolerance: Distributed systems must be capable of auto-routing around failures, and be capable of routing requests to the service instance that will provide an optimum response.Spring Hystrix, Turbine, & RibbonHealth check, service meshes (example: Istio)
Autoscaling and self-healing: Distributed systems respond to higher load by scaling horizontally: the platform must detect and auto-respond to such conditions. Furthermore, the system needs to detect failures and attempt auto-restarts without operator input.-Health check, self-healing, and auto-scaling
Packaging, deployment, and scheduling: Large-scale systems require robust package management, and deployment systems to manage rolling or blue-green deployments, and rollbacks if necessary. A scheduler helps determine which particular execution node a new set of services can be deployed to based on current conditions.Spring Boot, Apache Maven. The Spring Cloud system does not have a true scheduler.Docker, Rkt, Kubernetes Scheduler & Deployment, Helm
Job management: scheduled computations disconnected from any individual user requests.Spring BatchKubernetes Jobs and Scheduled Jobs
Singleton application: limit a specific service to run as the only instance of that service within the entire system.Spring Cloud ClusterKubernetes Pods

See also

Further reading

Notes and References

  1. Web site: Microservice architectures: more than the sum of their parts? . 2022-03-29 . IONOS Digitalguide . 2 March 2020 . en.
  2. Book: Fowler, Martin . Patterns of Enterprise Application Architecture . Addison-Wesley Professional . 2002 . 978-0321127426.
  3. Book: Fundamentals of Software Architecture: An Engineering Approach . O'Reilly Media . 2020 . 978-1492043454.
  4. Web site: Microservices. Martin Fowler. https://web.archive.org/web/20180214171522/https://martinfowler.com/articles/microservices.html. 14 February 2018. live.
  5. Book: Newman, Sam. Building Microservices. O'Reilly Media. 978-1491950357. 2015-02-20.
  6. Book: Microservices: Flexible Software Architectures. 978-0134602417. Wolff. Eberhard. 2016-10-12. Addison-Wesley .
  7. Nadareishvili, I., Mitra, R., McLarty, M., Amundsen, M., Microservice Architecture: Aligning Principles, Practices, and Culture, O'Reilly 2016
  8. Web site: Backends For Frontends Pattern . Microsoft Azure Cloud Design Patterns . Microsoft.
  9. Book: B00VJ3NP4A. Microservices: Patterns and Applications. Lucas Krause.
  10. Web site: Software Architecture: The Hard Parts . 2023-01-20 . Thoughtworks . en . N . Ford . M . Richards . P . Sadalage . Z . Dehghani .
  11. "CI/CD for microservices architectures", Azure Architecture Center, Microsoft. Retrieved 9 January 2018.
  12. Josuttis, N. (2007). SOA in Practice. Sebastopol, CA, US: O'Reilly. .
  13. Web site: Microservice Prerequisites. Martin Fowler. Martin Fowler (software engineer) . 28 August 2014 . live . https://web.archive.org/web/20231003075551/https://martinfowler.com/bliki/MicroservicePrerequisites.html . Oct 3, 2023 .
  14. Book: Richardson . Chris . Microservice Patterns . November 2018 . Manning Publications . 1.4.1 Scale cube and microservices . 9781617294549.
  15. Mendonca. Nabor C.. Jamshidi. Pooyan. Garlan. David. Pahl. Claus. 2019-10-16. Developing Self-Adaptive Microservice Systems: Challenges and Directions. IEEE Software. 38. 2. 70–79. 10.1109/MS.2019.2955937. 1910.07660. 204744007 .
  16. Web site: Rodgers. Peter. Service-Oriented Development on NetKernel- Patterns, Processes & Products to Reduce System Complexity. CloudComputingExpo. SYS-CON Media . Feb 15, 2005 . 19 August 2015. https://web.archive.org/web/20180520124343/http://www.cloudcomputingexpo.com/node/80883. 20 May 2018. dead.
  17. Web site: Russell. Perry. Rodgers. Peter. Sellman. Royston. Architecture and Design of an XML Application Platform. HP Technical Reports. 20 August 2015. 62. 2004.
  18. Book: Löwy, Juval . Programming WCF Services, 1st ed. . O’Reilly Media . 2007 . 978-0-596-52699-3 . 543–553.
  19. Juval Löwy "Every Class a WCF Service". (Channel9, ARCast.TV, October 2007).
  20. Juval Löwy "Every Class As a Service" (Microsoft TechEd Conference, May 2009), SOA206. Archived from the original on 2010.
  21. Book: Löwy, Juval . Programming WCF Services, 1st ed. . O’Reilly Media . 2007 . 978-0-596-52699-3 . 48–51.
  22. Book: Löwy, Juval . Programming WCF Services, 3rd ed. . O’Reilly Media . 2010 . 978-0-596-80548-7 . 74–75.
  23. Book: Dragoni. Nicola. Giallorenzo. Saverio. Lafuente. Alberto Lluch. Mazzara. Manuel. Montesi. Fabrizio. Mustafin. Ruslan. Safina. Larisa. Present and Ulterior Software Engineering. Microservices: Yesterday, Today, and Tomorrow. 2017. 195–216. 10.1007/978-3-319-67425-4_12. 1606.04036. 978-3-319-67424-7. 14612986.
  24. Web site: Micro services - Java, the Unix Way. James Lewis.
  25. Web site: MicroService Architecture: A Personal Journey of Discovery. Fred George. 2013-03-20.
  26. News: Farrow . Rik . 2012. Netflix heads into the clouds .
  27. Web site: James Lewis and Martin Fowler. Microservices.
  28. 2017. Microservices in Practice, Part 1: Reality Check and Service Design. IEEE Software. 34. 1. 91–98. 10.1109/MS.2017.24. Pautasso. Cesare. 5635705.
  29. Web site: Continuous Deployment: Strategies. javacodegeeks.com. 10 December 2014. 28 December 2016.
  30. Web site: Cloud Microservices Market 2020 Trends, Market Share, Industry Size, Opportunities, Analysis and Forecast by 2026 – Instant Tech Market News. Research. Verified Market. en-US. 2020-02-18.
  31. O. Zimmermann, Domain-Specific Service Decomposition with Microservice API Patterns, Microservices 2019, https://www.conf-micro.services/2019/slides//keynotes/Zimmerman.pdf
  32. Web site: Amazon SOA mandate. 13 October 2011.
  33. Book: Vaughn, Vernon . 2016 . Domain-Driven Design Distilled. Addison-Wesley Professional. 978-0-13-443442-1.
  34. Microservices: Architecting for Continuous Delivery and DevOps. Lianping . Chen . 2018 . The IEEE International Conference on Software Architecture (ICSA 2018). http://icsa-conferences.org/2018/ . IEEE.
  35. Yousif. Mazin. 2016. Microservices. IEEE Cloud Computing. 3. 5. 4–5. 10.1109/MCC.2016.101.
  36. Book: Dragoni. Nicola. Lanese. Ivan. Larsen. Stephan Thordal. Mazzara. Manuel. Mustafin. Ruslan. Safina. Larisa. Perspectives of System Informatics . Microservices: How to Make Your Application Scale . 2017. Lecture Notes in Computer Science. 10742. https://hal.inria.fr/hal-01636132/file/microservices-make-application.pdf. 95–104. 10.1007/978-3-319-74313-4_8. 2017arXiv170207149D. 1702.07149. 978-3-319-74312-7. 1643730.
  37. Book: Newman, Sam . 2015 . Building Microservices . O'Reilly. 978-1491950357.
  38. Book: Wolff, Eberhard . 2016 . Microservices: Flexible Software Architecture . Addison Wesley. 978-0134602417.
  39. 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. 10.18417/emisa.14.1.
  40. Taibi. Davide. Lenarduzzi. Valentina. Pahl. Claus. Janes. Andrea. 2017. Microservices in agile software development: a workshop-based study into issues, advantages, and disadvantages. Proceedings of the XP2017 Scientific Workshops. 10.1145/3120459.3120483. 28134110.
  41. Web site: Microservice architecture pattern. Richardson. Chris. microservices.io. 2017-03-19.
  42. Towards an Evidence-Based Understanding of Emergence of Architecture through Continuous Refactoring in Agile Software Development. Lianping . Chen . Muhammad. Ali Babar. 2014. Proceedings Working IEEE/IFIP Conference on Software Architecture 2014 WICSA 2014. The 11th Working IEEE/IFIP Conference on Software Architecture(WICSA 2014). https://web.archive.org/web/20140730053454/http://wicsa2014.org/. IEEE. 10.1109/WICSA.2014.45.
  43. Balalaie. Armin. Heydarnoori. Abbas. Jamshidi. Pooyan. May 2016. Microservices Architecture Enables DevOps: Migration to a Cloud-Native Architecture. IEEE Software. 33. 3. 42–52. 10.1109/ms.2016.64. 0740-7459. 10044/1/40557. 18802650.
  44. Web site: Experiences from Failing with Microservices. Jan . Stenberg. 11 August 2014.
  45. Web site: Why unit testing is not enough when it comes to microservices. Calandra. Mariano. 7 April 2021.
  46. Web site: How small should your microservice be? . Tilkov . Stefan . 17 November 2014 . Innoq . 4 January 2017.
  47. Lanza . Michele . Ducasse . Stéphane. 2002 . Understanding Software Evolution using a Combination of Software Visualization and Software Metrics. In Proceedings of LMO 2002 (Langages et Modèles à Objets). 135–149 . dead . https://web.archive.org/web/20210227104157/https://rmod.inria.fr/archives/papers/Lanz02aEvolutionMatrix.pdf . Feb 27, 2021 .
  48. Book: Richardson . Chris . Microservice Patterns . November 2018 . Manning Publications . Chapter 4. Managing transactions with sagas. 978-1-61729454-9.
  49. Web site: 10 Tips for failing badly at Microservices by David Schmitz . Devoxx . Aug 30, 2017 . . dead . https://web.archive.org/web/20210422161909/https://www.youtube.com/watch?v=X0tjziAQfNQ . Apr 22, 2021 .
  50. Book: Löwy, Juval. Righting Software 1st ed.. Addison-Wesley Professional. 2019. 978-0136524038. 73–75.
  51. 2017. Microservices in Practice, Part 2: Service Integration and Sustainability . IEEE Software . 34. 2. 97–104. 10.1109/MS.2017.56 . Pautasso. Cesare. 30256045 .
  52. 2018. Consistent Disaster Recovery for Microservices: the BAC Theorem. IEEE Cloud Computing. 5. 1. 49–59. 10.1109/MCC.2018.011791714. Pautasso. Cesare. 4560021.
  53. Web site: Developing Microservices for PaaS with Spring and Cloud Foundry.
  54. Web site: Martin Fowler (software engineer). Martin . Fowler . Microservice Trade-Offs.
  55. News: BRASS Building Resource Adaptive Software Systems . DARPA . U.S. Government . 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 documented 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".
  56. Book: Understanding Distributed Systems: What every developer should know about large distributed applications . 2021 . 978-1838430207 . Vitillo . Roberto . Roberto Vitillo .
  57. Web site: What's the P99 Latency? . Bhargav . Nikhil . 2024-03-18 . baeldung.com . 2024-06-08 . The mean and median often mask outliers.
  58. Book: Microservices - A Practical Guide. 978-1717075901. Wolff. Eberhard. 2018-04-15. CreateSpace Independent Publishing Platform .
  59. Web site: Eclipse MicroProfile. Stephanie. Swart. 14 December 2016. projects.eclipse.org.
  60. Web site: MicroProfile. 2021-04-11. MicroProfile. en-US.
  61. Towards Optimal Configuration of Microservices . Somashekar. Gagan. Gandhi. Anshul. 2021-04-26. Association for Computing Machinery . Proceedings of the 1st Workshop on Machine Learning and Systems . 7–14 . Online, United Kingdom . 10.1145/3437984.3458828 . EuroMLSys '21.