concept microservice in category java

This is an excerpt from Manning's book The Java Module System.
Isn’t a module system overkill in times when everybody writes microservices?
In general, it’s fair to say that the module system’s benefits have a larger effect, the bigger the project is. So when everybody is talking about microservices, isn’t a module system for large applications the proverbial lipstick on a pig? The answer depends on how many projects will end up being structured as microservices, and that is, of course, a huge discussion in itself.
Some believe microservices are the future and sooner or later all projects will start out that way—it’s all microservices! If you’re in that camp, you may still implement your services in Java 9+, and the module system will affect you, but, of course, much less than it affects monolithic projects. We’ll discuss that in the next section.
Others have a more cautious opinion. Like all architecture styles, microservices have both advantages and disadvantages, and a trade-off must be made between them with the project’s requirements in mind. Microservices shine particularly brightly in rather complex projects that have to sustain high loads, where their ability to scale is almost unrivaled.
This scalability is paid for with operational complexity, though, because running a multitude of services requires much more knowledge and infrastructure than putting a handful of instances of the same service behind a load balancer. Another drawback is that getting service boundaries wrong, which is more likely the less the team knows about the domain, is more expensive to fix in microservices than in a monolith.
The critical observation is that the price for the complexity (Martin Fowler calls it the microservices premium) must always be paid, but the benefits are only reaped once a project is large enough. This factor has convinced many developers and architects that most projects should start as a monolith and move toward splitting off services, maybe eventually ending in microservices, once circumstances require it.
You shouldn’t start a new project with microservices, even if you’re sure your application will be big enough to make it worthwhile. […] The logical way is to design a monolith carefully, paying attention to modularity within the software, both at the API boundaries and how the data is stored. Do this well, and it’s a relatively simple matter to make the shift to microservices.
By now, the emphasized phrases should be familiar: careful design, modularity, boundaries—these are all properties that the module system promotes (see section 1.5). In a microservice architecture, service dependencies should be clear (cue reliable configuration) and ideally decoupled (service loader API); furthermore, all requests must go through public APIs (strong encapsulation). Carefully using the module system can lay the groundwork for a successful migration to microservices if and when the time for that comes. Figure 15.6 shows the importance of this careful design.
Figure 15.6 Given two hypothetical migrations of a monolithic application to microservices, would you rather start with a sizable square of mud (left) or a properly modularized code base (right)?
![]()

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.