concept microservice in category microservice

This is an excerpt from Manning's book Bootstrapping Microservices with Docker, Kubernetes and Terraform.
Microservices are an architectural pattern that is playing a pivotal role in contemporary software development. A distributed application composed of microservices solves these problems and more, but typically it is more difficult, more complex and more time-consuming to architect than a traditional monolithic application. If these terms are new: microservices, distributed application and monolithic application please hold tight, they will be explained soon.
Conventional wisdom says that microservices are too difficult. We are told to start monolith-first and later restructure to microservices when necessary to scale. But I argue that this attitude doesn’t make the job of building an application any easier! Your application is always going to tend toward complexity and eventually, you will need to scale your application. So when you do decide you need to convert to microservices, now you have the extremely difficult job of safely converting your monolith to microservices when staff and customers already depend on it.
Now is also the perfect time to be building microservices. The confluence of various factors - easily accessible and cheap cloud infrastructure, increasingly good tools and increasing opportunities for automation - has driven an industry-wide move toward smaller and smaller services, aka microservices.
npm install --save-dev nodemon

This is an excerpt from Manning's book Microservices in .NET Core, Second Edition.
Figure 1.3. Running more than one microservice within a process leads to high coupling between the two: They cannot be deployed individually and one might cause downtime in the other.
![]()
Listing 3.1. Dockerfile for the Shopping Cart
language="sql" linenumbering="unnumbered">FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build #1 WORKDIR /src COPY ["ShoppingCart/ShoppingCart.csproj", "ShoppingCart/"] RUN dotnet restore "ShoppingCart/ShoppingCart.csproj" #2 COPY . . WORKDIR "/src/ShoppingCart" RUN dotnet build "ShoppingCart.csproj" -c Release -o /app/build #3 FROM build AS publish RUN dotnet publish "ShoppingCart.csproj" -c Release -o /app/publish #4 FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS final #5 WORKDIR /app EXPOSE 80 #6 COPY --from=publish /app/publish . #7 ENTRYPOINT ["dotnet", "ShoppingCart.dll"] #8

This is an excerpt from Manning's book Microservices Security in Action.
We find microservices to be a key enabler for fail fast, fail often. Microservices architecture has gone beyond technology and architectural principles to become a culture. Netflix, Amazon, Lyft, Uber, and eBay are the front-runners in building that culture. Neither the architecture nor the technology behind microservices--but the discipline practiced in an organizational culture--lets your team build stable products, deploy them in a production environment with less hassle, and introduce frequent changes with no negative impact on the overall system.
In a typical microservices deployment, microservices are not exposed directly to client applications. In most cases, microservices are behind a set of APIs that is exposed to the outside world via an API gateway. The API gateway is the entry point to the microservices deployment, which screens all incoming messages for security and other QoS features.
Figure 3.1 depicts a microservices deployment that resembles Netflix’s, in which all the microservices are fronted by the Zuul API gateway. Zuul provides dynamic routing, monitoring, resiliency, security, and more. It acts as the front door to Netflix’s server infrastructure, handling traffic from Netflix users around the world. In figure 3.1, Zuul is used to expose the Order Processing microservice via an API. We do not expose Inventory and Delivery microservices from the API gateway, because external applications don’t need access to those.
Figure 3.2 The interactions among the client application, microservice, and authorization server. The Order Processing microservice handles more functionality than it ideally should.
![]()
Executing all these steps becomes a problem because the microservice loses its atomic characteristics by performing more operations than it’s supposed to. It would be ideal for the microservice to perform only the fifth task from the preceding list, which is the one that deals with the business logic for which we designed the microservice. The coupling of security and business logic introduces unwanted complexity and maintenance overhead to the microservice. For example, making changes in the security protocol would require changes in the microservice code, and scaling up the microservice would result in more connections to the authorization server.

This is an excerpt from Manning's book Testing Microservices with Mountebank.
Netflix experienced this slowdown once the organization grew to about 100 engineers, with multiple teams competing in the same codebase. Like Amazon, the company solved the problem by breaking the monolithic application into services, and it made a conscious effort to make each service do only one thing. This architectural approach—what we now call microservices—supported development teams working independently of each other, allowing the company to scale its development organization.
Although scaling development efforts is the primary force leading us toward microservices, it has a welcome side effect: it’s much easier to release a small service than it is to release a large application. If you can release services independently, you can release features to the market much more quickly. By removing the need for release coordination between teams, microservices provide an architectural solution for what would normally have to be solved manually. Customers are the beneficiaries. Both Amazon and Netflix are known for the ability to rapidly innovate in the marketplace but to do so required rethinking how they organized to deliver software and how they tested software.

This is an excerpt from Manning's book Microservices in Action.
A microservice owns its data store, if it has one. This reduces coupling between services because other services can only access data they don’t own through the interface that a service provides. Microservices themselves, not the messaging mechanism that connects them nor another piece of software, are responsible for choreography and collaboration — the sequencing of messages and actions to perform some useful activity. Figure 1.1 The flow of communication through microservices in an application that allows users to sell positions in financial shares
![]()
In addition to these three characteristics, you can identify two more fundamental attributes of microservices:

This is an excerpt from Manning's book Enterprise Java Microservices.
Throughout the book, we’ve focused on developing microservices for Enterprise Java with Thorntail. This appendix provides details on developing microservices with Spring Boot. Included are snippets from Spring Boot in Action by Craig Walls (Manning, 2015). If you’re particularly focused on Spring Boot microservices, taking a look at this book for further details would be worthwhile (see www.manning.com/books/spring-boot-in-action).
In previous chapters, you’ve seen how to access separate microservices directly by referring to the URL where a microservice is running. In this chapter, you’ll take calling microservices a step further by decoupling your client from the microservice it’s consuming, making it easier to scale.
Unless you’re developing a microservice for your own use, it’s virtually guaranteed that you’ll need the ability to scale the number of instances of your microservice in production. Without the ability to scale, your application will always have problems coping with the load placed upon it by users.
To support scaling of microservices, it’s not possible for them to be stateful—at least not in the same way that stateful session beans were in Java EE. As the often used saying goes, we want our microservices to be more like cattle and less like pets. Better to have many that can come or go without impact (cattle), instead of a few from which one disappearing can cause major issues (pets). You can still use user data from a previous request in your microservice, but it has to have been stored somewhere for you to retrieve it.
The shift to more stateless services has already begun in Enterprise Java over the last five years, but the push toward microservices has made it even more prominent than before. For developers and architects, it’s no simple feat to switch from thinking in terms of state to stateless. The change requires additional thought up front, and during development, to prevent state from creeping into a microservice.
If there’s a service you already have that’s stateful, and there’s simply no way to break it down into stateless microservices, or the challenge in doing so poses a risk that’s too great, then microservices might not be the best approach. Stick with a more traditional Java EE application server to handle the stateful service and scaling of that service across a small cluster.

This is an excerpt from Manning's book Testing Java Microservices: Using Arquillian, Hoverfly, AssertJ, JUnit, Selenium, and Mockito.
This book isn’t intended to be a tutorial on the varied microservice architectures that are available today; we’ll assume you have some understanding of the subject. Rather, we’re going to help you overcome the challenges involved in testing the common features that all microservice applications share. In order to do that, in this chapter we’ll establish some common ground about what a microservice is, so that you can relate to where we’re coming from when we discuss these topics in later chapters.
Before we delve into the nature of microservices, let’s answer the “why” question. Until recently, it’s been commonplace to develop monolithic applications, and that’s still perfectly acceptable for any application that doesn’t require scaling. The problem with scaling any kind of monolithic application is straightforward, as shown in figure 1.1. Microservices aren’t here to tell you that everything else is bad; rather, they offer an architecture that is far more resilient than a monolith to changes in the future.
Microservices enable you to isolate and scale smaller pieces of your application, rather than the entire application. Imagine that you’ve extracted some core business logic in your application to services A and B. Let’s say service A provides access to an inventory of items, and B provides simple statistics. You notice that on average, service A is called one million times per hour and service B is called only once per day. Scaling a monolithic application would mean adding a new node with the application that includes both services A and B.
Wouldn’t it be better if you only needed to scale service A? This is where the potential of microservices becomes apparent: in the new architecture, shown in figure 1.2, services A and B become microservices A and B. You can still scale the application, but this additional flexibility is the point: you can now choose to scale where the load is greatest. Even better, you can dedicate one team of developers to maintaining microservice A and another to microservice B. You don’t need to touch the application to add features or fix bugs in either A or B, and they can also be rolled out completely independently of each other.
A microservice is a part of a monolithic application that has been dissected into a smaller logical element. Microservices benefit your application by allowing targeted scaling and focused development. Microservices offer a logical way to meet scalability requirements by providing the ability to scale not only where performance is required, but also when. You can break monolithic applications into smaller elements that can be used as microservices. Microservices allow several teams to focus on individual, nonconflicting tasks that make up the bigger picture.

This is an excerpt from Manning's book The Tao of Microservices.
Transport independence is the ability to move messages from one microservice to another without requiring microservices to know about each other or how to send messages. If one microservice needs to know about another microservice and its message protocol in order to send it a message, this is a fatal flaw. It breaks the no privilege axiom, because the receiver is privileged from the perspective of the sender. You’re no longer able to compose other microservices over the receiver without also changing the sender.
There are degrees of transport independence. Just as all programming languages are executed ultimately as machine code, all message-transport layers must ultimately resolve senders and receivers to exact network locations. The important factor is how much information is exposed to the internal business logic of the microservice to allow it to send a message. Different message transports (shown in figure 1.6) have different levels of coupling.
For example, requiring a microservice to look up another service using a service registry is asking for trouble, because doing so creates a dangerous coupling. But service discovery need not be so blatant. You can hide services behind load balancers. The load balancers must know where the services are located, so you haven’t solved the problem; but you’ve made services easier to write, because they only need to find the load balancer, and they’ve become more transport independent. Another approach is to use message queues. Your service must still know the correct topics for messages, and topics are a weak form of network address. The extreme degree, where microservices know nothing of each other, is the goal, because that gives you the full benefits of the architecture.
To understand the implications and trade-offs of moving to a new architecture, you need to understand how it differs from the old way of doing things, and how the new way will solve old problems. What are the essential differences between monolithic and microservice architectures? What are the new ways of thinking? And how do microservices solve the problems of enterprise software development?
A microservice is a unit of software development. The microservice architecture provides a mental model that simplifies the world at a useful level. The proposition of this book is that microservices are the closest thing yet to ideal software components. They’re perfectly sized artifacts for fine-grained deployment into production. They’re easily measured to ensure correct operation. The microservice attitude is the belief that these three aspects of the architecture deliver a fast, practical, efficient way to create business value with software. Let’s dig into the details to see how this works in practice.

This is an excerpt from Manning's book Spring Microservices in Action.
As a developer writing a microservice, sooner or later you’re going to have to decide whether your service is going to be deployed to one of the following:
Constrained— Microservices have a single set of responsibilities and are narrow in scope. Microservices embrace the UNIX philosophy that an application is nothing more than a collection of services where each service does one thing and does that one thing really well. Loosely coupled— A microservice-based application is a collection of small services that only interact with one another through a non–implementation specific interface using a non-proprietary invocation protocol (for example, HTTP and REST). As long as the interface for the service doesn’t change, the owners of the microservice have more freedom to make modifications to the service than in a traditional application architecture. Abstracted— Microservices completely own their data structures and data sources. Data owned by a microservice can only be modified by that service. Access control to the database holding the microservice’s data can be locked down to only allow the service access to it.
The service is managing data across a large number of tables—A microservice is the system of record for the data it manages. If you find yourself persisting data to multiple tables or reaching out to tables outside of the immediate database, this is a clue the service is too big. I like to use the guideline that a microservice should own no more than three to five tables. Any more, and your service is likely to have too much responsibility.

This is an excerpt from Manning's book Microservices in .NET Core: with examples in Nancy.
A microservice is a service with one, and only one, very narrowly focused capability that a remote API exposes to the rest of the system. For example, think of a system for managing a warehouse. If you broke down its capabilities, you might come up with the following list:
A microservice owns the data store where it stores the data it needs. This is another consequence of a microservice’s scope being a complete capability. Most business capabilities require some data storage. For instance, a Product Catalog microservice needs some information about each product to be stored. To keep Product Catalog loosely coupled with other microservices, the data store containing the product information is completely owned by the microservice. The Product Catalog microservice decides how and when the product information is stored. As illustrated in figure 1.4, other microservices, such as Shopping Cart, can only access product information through the interface to Product Catalog and never directly from the Product Catalog data store.
The fact that each microservice owns its own data store makes it possible to use different database technologies for different microservices depending on the needs of each microservice. The Product Catalog microservice, for example, might use SQL Server to store product information; the Shopping Cart microservice might store each user’s shopping cart in Redis; and the Recommendations microservice might use an Elasticsearch index to provide recommendations. The database technology chosen for a microservice is part of the implementation and is hidden from the view of other microservices.
This approach allows each microservice to use whichever database is best suited for the job, which can also lead to benefits in terms of development time, performance, and scalability. The obvious downside is the need to administer, maintain, and work with more than one database, if that’s how you choose to architect your system. Databases tend to be complicated pieces of technology, and learning to use and run one reliably in production isn’t free. When choosing a database for a microservice, you need to consider this trade-off. But one benefit of a microservice owning its own data store is that you can swap out one database for another later.
Before jumping head first into building a system of microservices, you should consider whether the system you’re implementing is sufficiently complex to justify the associated overhead.
Do microservices perform?
One question that always seems to pop up in discussions of whether to use microservices is whether a system built with microservices will be as performant as a system that’s not. The argument against is that if the system is built from many collaborating microservices, every user request will involve several microservices, and the collaboration between these microservices will involve remote calls between them. What happens when a user request comes in? Do you chain together a long series of remote calls going from one microservice to the next? Considering that remote calls are orders of magnitude slower than calls inside a process, this sounds slow.
The problem with this argument is the idea that you’d be making roughly the same calls between different parts of the system as you would if everything were in one process. First, the interaction between microservices should be much less fine-grained than calls within a process tend to be. Second, as we’ll discuss in chapters 4 and 5, you’ll prefer event-based asynchronous collaboration over making synchronous remote calls, and you’ll store copies of the same data in several microservices to make sure it’s available where it’s needed. All in all, these techniques drastically reduce the need to make remote calls while a user is waiting. Moreover, the fine-grained nature of microservices enables you to scale out the specific parts of the system that get congested.
There isn’t a simple yes or no answer as to whether microservices perform well. What I can say is that a well-designed microservice system can easily meet the performance requirements of many, if not most, systems.