What is Microservices and is there a connection with MVC - spring-boot

I'm familiar with spring boot framework and I developed an Application which helps to handle online Assignments.I used few service classes to handle different tasks of the application and its structure can be seen here.
And I have seen several complex applications built as independent packages based on the task it do in the application.
(1)
My First question is can my Application be called as a MicroServices Application?? Because I have
used independent services for the application development.
(2)
And my second question is Can a application developed in MicroServices Architecture has MVC Architecture at the same time.But I have seen in several tutorials they are 2 different architectures.But a Moicroservices Application also has Models ,Views and Controllers at the same time.
So can those 2 be used at the same time??
Thank you!!

You should do some deeper research yourself about the concept and theory of microservices. Studying other applications without the basic knowledge can be misleading.
(1) Just because you are using multiple classes called services does not mean, you are building microservices application. Microservice application examples can be - student management rest api, question and answer management rest api, UI for administration, UI for public usage etc. All of them can be separate spring boot apps, or any other technology capable of handling the requirements (node.js, python, php, Asp.net ...) You should be able to deploy, test and use them as separate standalone apps.
(2)I think a microservice app does not need views, it can be a rest/soap app, log aggregation app, health check app, messaging service app etc. But different types can use different architecture, one of which can be MVC.
By definition of M. Fowler microservices are
..an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.
As you see the definition is ambiguous. I think you are building a monolith application with a good separation of responsibilities into classes called XyServices - a possible candidates to migrate to microservices.

Microservices according to Chris Richardson
( recognized thought leader in microservices) is Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are
Highly maintainable and testable
Loosely coupled
Independently deployable
Organized around business capabilities
Owned by a small team
The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack.
It is way of delivery and based on 12 factors
https://12factor.net/.
We use domain driven design as one of the way.
MVC is way of designing as service where we have model view and controller.
In Microservices architecture we can use MVC in one way where each component will be distributed .
Please go through the Microservice Patterns. It is very good book to understand the Microservices architecture
1.Answer to your question yes your application can be Microservices if it followed the 12 factors as mentioned in the website .
Yes Microservices can be on the pattern of mvc but they will be distributed and like we have Microservices for backend in similar fashion we have micro frontend for UI .

Related

Can I have an Express server and Java Spring boot for Backend at the same time?

I am using Java spring boot for an REST API, using Stripe to handle Payment. To handle the payments, I am planning to use an Express server. Is this Okay? Will I face any issues in deployment?
I am planning to start working on it soon.
This is really an architectural choice that you can take. It can be justified as being part of a micro-services architecture. This is not uncommon, to have different services being developed with different languages and infrastructures, especially when you have different teams with different skillsets working on isolated features/services. There are a couple of things to be careful about though:
Maintainability
Interoperability
Infrastructure
Security
etc.
I hope this gives you enough to think about to make your decision.

The eurika service is it necessray in implementing a microservice?

I want to create a microservice with spring boot but in fact I am not underestanding the architecture microservice well ! I create a controller, a service, a repository, a model and I have related it with a mongo database thanks to the file application.properties ! And I can access to it thanks to the path "http://localhost:8080".
My question is : This project that I have developped with spring boot is it a microservice ? Or it need the service Eurika to become a microservice ?
Interesting question - to understand the answer you need to think first "Why microservices" or "What are the benefits of microservices".
When you will google this you will get tons of benefits of microservices architecture (of course there are some drawbacks as well).
But focusing on benefits one of the most common benefits you will see is microservices architecture is scalable.
Now the answer to your questions lies in this benefit 'Scalable'.
In very simple words, scalability of microservices means horizontal scalability of the microservices. That essentially means you need to run multiple instances of your microservices so that you can cater more and more load/traffic on your system.
Now the moment you run multiple instances there has to be some support component in your architecture that helps you in service discovery.
And Eureka is one of the ways you do service discovery in the microservices services architecture.
Now the short answer to your question - No! Eureka is not necessary microservices architecture but service discovery is one of the foundation pattern in the microservices architecture. (and Eureka is one of the tool/ways of achieving the same)

What patterns could I implement in microservice development?

I'm going to begin a new project of microservice and want know about patterns that I might wan't to implement on my new microservice for that I could scale, don't have problems with load balance, have an good service with resilience.
I looking to know about patterns that might microservices should implement
Also could you provide some indications for Java microservices application?
For solve some problems that was said: [1]
Architecture: You could build small microservices as it can be, so that the scale be right focused on need to be.
You could set a Discovery service for registering the applications instances, with that making easier to the client access the right application when are lots of instances of the same service (Netflix Eureka / Spring Cloud).
You could set a Configuration outside the code source of the code, so that all the instances can be configured without human intervention right on the running code (Spring Cloud Config).
Set a way the check the health of the microservice with ease.
I circuit breaker for clear the anomalies microservices instances (Spring Cloud / Netflix Hystrix).
and following as say the Twelve-Factor App.
With lots of another things that you need to that care when building a microservice, suggesting the reading the book, if you'll use Java for building microservices Spring Microservices in Action By John Carnell , if you i'll implement in another programming language this other could guide you, Microservices in Action by Morgan Bruce and Paulo Pereira.
[1] (https://www.amazon.com.br/Spring-Microservices-Action-John-Carnell/dp/1617293989

Micro service architecture : Data Access services

In a micro service architecture, Is it good to have separate DAO services for all the Business services or should I have all the layers intact in the service. In my case, I am building a small Banking application where in I have below services
cbs-accountsummary
cbs-payments
cbs-accounts
cbs-loan
cbs-deposits
So should I really require below services as well
cbs-accountsummary-dao
cbs-payments-dao
cbs-accounts-dao
cbs-loan-dao
cbs-deposits-dao
Or is it fine to have DAO as part of business services. I am really wondering how it goes in real life applications.
In micro-services architecture you split your Domain to micro-services and each micro-service will have its own: api, business logic and data access.
Your example
In your case for example the micro-service "cbs-payments" will have its own API exposed, as well as a business layer(the domain logic of the payments domain) and data access layer. The micro-service will be responsible for the whole scope of the request from api to data persistence. This could include api's, business logic, cache, database and other things.
Lets say if you have a Create payment api call. You would call your micro-service REST api like POST api/payments which would process the request, apply some business rules(validation and others) and save it to the micro-service specific database. All that code would be in your micro-service.
The confusion
Maybe your where working with systems where the the architectural split was not done based on the domain but on some other criteria.
Usually micro-services are split based on some Domain boundaries like in your example. Each of these micro-services are isolated. Regardless of business logic, data access logic or any other logic it is still part of that micro-service.
Usually people use DDD(Domain Driven Design) with micro-services. It is also a common approach to use Repository and Unit Of Work design patterns. You could create Generic Repository/Unit of Work classes which help in database interaction. If you are using micro-service architecture you can extract these generic implementation to some library and use them in each micro-service(extend them if needed). Still you would use that code in your micro-service code.
As already said, I would not go for separate DAO-Services. A Microservice should control all aspects for the bounded context it is responsible for, this includes persistence.
Imagine, if there would be seperate DAO-Services, what would prevent a client from modifying, via said services, the data of the Microservice itself? The Microservice applies business logic onto its domain objects and persists them or not (in case of business rule violation). You never want this to be circumvented. See "cohesive behavior" of Sam Newmans book Building Microservices.

Example open source microservices applications

I'm looking for open source applications that demonstrate the microservices pattern. In particular, I'd like to find one or more applications that can be spun up on real cloud environment up (but with fake data and requests) to demonstrate real-world deployment mechanics.
Unfortunately, I haven't found any good options yet. I'll note that Discourse is a modern 3-tier application, using Rails API, Ember.js, Postgres, and Redis, but it still is much closer to a monolith than an example of microservices. The closest I've found so far is https://github.com/kbastani/spring-cloud-microservice-example but that is more of a framework than an actual application that delivers data.
Not your typical CRUD app but Deis (a PaaS) uses REST APIs mostly to communicate between services. Peatio has a bunch of services that communicate asynchronously through a message queue.
Microsoft provides a demo webshop application based on .NET Core showing how to apply the microservices pattern:
https://github.com/dotnet-architecture/eShopOnContainers
There is also an ebook available: https://aka.ms/microservicesebook
this lagom application example is a microservices application written in Lagom . It is a akka based framework (DDD for design).
Application is complete and working. See if that serve your purpose.

Resources