The advantages and disadvantages of microservices are as follows. Then it discusses the correct posture for using microservices. Finally, a simple example shows how to implement microservices using Spring Boot.

In this article, we’ll discuss the pros and cons of microservices so you can make better decisions. After that, we’ll look at microservices architecture through an example. Hardware advances have kept pace with the complexity of applications. But it has not kept up with the changing pace of Internet traffic. So architecture and Web interfaces need to change, and we have a lot of technology to solve this problem, and now back-end singleton programs are almost nonexistent. We’ll discuss the pros and cons of microservices here.

Advantages:

  • You can use the latest technology stacks in a variety of languages.

  • A Bulkhead can be used, so that if one system fails, other systems can serve it efficiently.

  • Dynamic extensibility

  • The combined application will not have a long release cycle.

  • Applications will be a separate set of systems and the deployment process will be smoother.

  • Contribute to the efficient use of human and technical resources.

Disadvantages:

  • This is a very high non-initial cost for small applications.

  • Integration and testing efforts may increase.

  • Sometimes developers complain about repetitive work.

  • Adding service apis can be complex. Memory consumption can be high

To quote Martin Fowler:

One of the legitimate arguments we heard was that you shouldn’t start with a microservice architecture. Instead, the monolithic application is kept modular, and when the monolithic application fails, it is split into microservices

If you’re already using microservices, the advantages are clear. If the application becomes large and complex, then move to microservices as the application becomes more modular. Because micro service is very demanding in terms of technology, workload and architecture design level. We will create a project to demonstrate. Microservices are an architectural style whose implementation is supported by a number of frameworks, i.e. Dropwizard, Vertx, Spring Boot, Restlet, Spark + Unirest (REST client. Spark does not provide REST client). Here we will use Spring boot. This is the most popular framework for microservices, as we know it is supported by Spring.

In this project, we will use the Eureka server, which is simply a service registry implementation. In this case, each microservice is registered, and the client looks up the Eureka server to find the relevant microservice. We tried to mimic the real world scenario here, where Eureka servers and different microservices are deployed separately.

Example Initialize the Eureka service

For our demonstration purposes, we will only use Eureka as our service registry server. To do this, you simply need to use the correct dependencies and specify Eureka properties in your application YAML or in the properties file.

Eureka POM

application.yaml

The following are the main configurations for your application

Once we start the application, the Eureka server will display the details of all registered and available services.

There are no registered services, so you will see a warning. Micro services client We will define two simple projects: employee services and employer services. These two services will be registered with the Eureka server. At the heart of these projects will be its application properties, which define the names and other parameters they will register with the server. Staff service

Employer service

Once we start the process, they will register with Eureka.

Please note that the warning has disappeared. Use published microservices

Clients are registered under different names. These names will be used to find services on other clients. In our example, the Employee-service returns static data. This data is obtained and displayed in the EMPLOYER SERVICE. Staff service

We only have 2 predefined data sets and we will only return from this set. Employer service

Note how employer services access employee services. It does not use any hosts or ports. Based on the service name, it tries to find and use the service.

The output

conclusion

Here we see the implementation of microservice minimization based on Spring Boot. Here services are very isolated from server configuration and deployment. You can download the complete code from GitHub Repository [1]

The writer is Rahul, translated by Fangyuan. Please indicate the source, original technology and architecture practice article, welcome to submit through the public menu “contact us”.

Links in the article:

[1] https://github.com/pavansolapure/opencodez-samples/tree/master/microservices

Related reading:

Motan RPC: new support for cross-language and service governance

Yes, we migrated from PHP to Go in order to better support microservices

Modularity or Microservices – Why do most team microservices fall into the trap

New choice for Java microservices framework: Spring 5

From monolithic applications to microservices: Implications for an API Gateway upgrade

Activity preview:

From June 1 to 2, GIAC Global Internet Architecture Conference will be held in Shenzhen. GIAC is a technology architecture conference for architects, technical leaders, and high-end technology practitioners from the high Availability Architecture Technology community. This year’s GIAC has been attended by experts from Tencent, Alibaba, Baidu, Toutiao, IFLYtek, Sina Weibo, Xiaomi, Meitu, Oracle, Lianjia, Vip.com, JD, Ele. me, Meituan-Dianping, Luji Thinking, Ofo, Megsight, LinkedIn, Pivotal and other companies.

Some of the highlights of this GIAC conference are as follows:

Participated in GIAC and took stock of the latest technologies in 2018. Click “Read the article” to learn more about the conference