Open In App

Why Use Spring Cloud for Microservices Development?

Last Updated : 10 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Microservices are small, loosely coupled distributed services. Microservices architecture evolved as a solution to the scalability, independently deployable, and innovation challenges with Monolithic Architecture. It provides us to take a big application and break it into efficiently manageable small components with some specified responsibilities. It is considered the building block of modern applications.

There are many reasons to use Spring Framework for example if you want faster development, less configuration, auto-configuration, embedded server, production-ready application, and many more. But apart from that most importantly we have ready-made support for microservices and this ready-made support is available through Spring Cloud. So now let’s discuss some of the known challenges while building microservices and how Spring Cloud is helping us to overcome those challenges.

Microservices Development Challenges

Writing microservices is simple but maintaining them is not that simple. We will show you some of the challenges that we face while developing Microservices.

Challenge No: 1

Imagine you have this application called Employee-Customer-Management app where you have different modules like Address Module, Course Module, Employee Module, Customer Module, etc. And this is just a monolith application.

 

Right now your company wants to adopt the microservices architecture. So you split this application into multiple services and out of this one application which contains many modules right now you’re going to be converting all these modules to different services and different applications. Consider creating different Spring Boot applications like this.

 

Now you have separate applications like address service for the address module, course service for the course module, and so on. And you know in your spring boot you can configure all these applications and we can configure our applications using the application.properties file or application.yaml file. Now imagine in all these applications we have this property in all the properties file

company.name = geeksforgeeks

This is a common property that exists in the application.properties file in all our projects. Now suppose one day our requirement changes according to the client. The client says you are developing the app for us so we are telling you that go ahead and change the value of the company from “geeksforgeeks” to “gfg”. 

company.name = gfg

So you can do it if you have 5-10 microservices. But imagine you have 1000 microservices. So how you will be doing it? Do you want to go to every application open the application.properties file and will change the value of company.name right over. There it will be a difficult challenge. How we’ll be solving this issue?

Challenge No: 2

Now let’s discuss another issue/challenge. Imagine you are writing microservices. Your company has adopted the microservices architecture you have Address Service, Employee Service, Course Service, Student Service, etc, etc. You have many spring boot applications and all the spring boot application has been deployed into many different servers and you might have thousands of applications. Right now all these applications let’s say Course Service wants to connect to the Address Service, Student Service wants to connect to the Course Service, and wants to get some course-related data then how these servers will communicate with each other? We will simply make a REST call and all these servers will communicate with each other using the REST API. But the real challenging part is when a server wants to connect to another server then before this server connects to this server it needs to know the IP address, and it needs to know the port number where this particular application is running in the server. 

 

This is not going to be a simple job to manage the thing where you have thousands and thousands of applications. How you will manage the server IP? How you’ll maintain their port number because every server, when you want some data from another server, it needs to connect to them and in order to connect to them it needs to know the IP and the server address of that and it will be a really critical job to handle all the IP and the server ports where you have thousands of servers where you have split your one application into thousands of different modules and deployed into different servers. Don’t you think managing the IP and the server URL will be critical? In the case of a Monolithic Application, there we have only one server so we used to remember the server IP and the port but now your monolithic has been split into thousands of applications how’ll be handling that?

Challenge No: 3

Now imagine we have a Course Service that has been deployed into a server. Suppose there is a special occasion coming for example Diwali, or Christmas. And we are running some offers like 50% off on this course. Please check it out. Now lots of people coming into our server and are trying to hit a lot of requests to the server. Right now our server is not able to handle all those concurrent requests or all those requests which are coming from our clients or maybe different people will have a different computer and they will keep hitting our server and our server will not handle the load.

 

And in microservices what we can do is we will have three different copies of our Course Service and we will deploy them into three different servers, and right now when requests are coming from the client what we will do we’ll just distribute the request between multiple servers to balance the load.

 

We will not throttle one server by hitting lots and lots of requests to this.

 

Rather we want this request to go into a different server and for that, we will introduce a Load Balancer, and our job is going to know whenever multiple requests are getting we’ll make sure it will be first reached the Load Balancer and the Load Balancer will circulate this request to different or among different server and will distribute them in a load balanced way so that one server will not be throttled with many requests.

 

But now the challenge is how to write a Load Balancer. It’s a tough job to do. So don’t worry, Load Balancer comes free with Spring Cloud.

Challenge No: 4

Now, let’s discuss another challenge. Imagine you have the same Course Service that has been deployed to a server and right now there is a client but this is not a good client, this is a hacker. 

 

He knows the end point of your microservice and imagine he’s hitting many requests to your server, and eventually if the hacker has a script and he has written that script to hit many requests to the server eventually the server will be down. Because it cannot handle that many requests. So how can you tackle this? In a particular scenario if somebody knowingly puts a lot of requests to your server where he doesn’t have to do anything with your application but he just wants your server to go down so that your business will hamper. Your application will not reach the targeted audience or your application will not reach your clients and your clients will have trouble because your server is down and knowingly somebody is putting a lot of requests to the server how you’ll be limiting all these things?

Challenge No: 5

Now, let’s discuss the last challenge. Imagine you have a server where you have deployed your Student Service, and you have another server where you have deployed your Course Service.

 

Now suppose one server i.e. Student Service wants to get some course data. So he’s making a REST call and hitting this endpoint called ‘/courses‘. Imagine whenever the Student Service wants some data from the Course Service but what if the server is down and as we are hitting right now from one server to another server there will be an absolute probability that this server will be down, this server is busy, or this server is slow and it is not able to take our request and process it. There is n number of reasons why the server will not function well. It will function well which should be our priority but think about the negative scenario. What about the server where you have deployed your application is slow or down or it is not able to take or process your request then in that case this request will result in an error and because of that error the Student Service also will not function well and this Server might have a lot of problems because of the request it is making to another server is failing. So how to tackle all these kinds of scenarios?

Spring Cloud as Solution

And for all these challenges please welcome Spring Cloud. Spring Cloud is a project under which we have a lot of sub-projects which is going to give you absolute treasure. Using those sub-projects you can solve all these problems. 

  • For Challenge No 1 we have Spring Cloud Config Server
  • For Challenge No 2 we have Service registration and discovery using Eureka
  • For Challenge No 3 we have Spring Cloud LoadBalancer
  • For Challenge No 4 we have resilience4j-ratelimiter
  • For Challenge No 5 we have Circuit Breakers Pattern

And all these things have given free by Spring Boot using the Spring Cloud project and Spring Cloud has all these sub-projects using which you can build highly efficient microservices free of cost, without having tons of exposure to microservices creation you can create microservices on the go.

What is Spring Cloud?

Spring Cloud is a collection of projects like Load Balancer, when the load increases you need a load balancer so you can use one of the projects from Spring Cloud called Spring Cloud LoadBalancer to implement the load balancing and you don’t have to write the logic, Spring Cloud will get you that particular thing freely available. You just need to add one dependency and the load balancing automatically starts happening and Spring Cloud will get you that particular feature. So like load balancing, service discovery, Spring Cloud Gateway, security, tracing, tracking, and logging, everything will be given by Spring Cloud. So spring Cloud basically provides some of the common tools and techniques and projects to quickly develop some common patterns of the microservices.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads