Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring + Load balancing/Clustering

I am working on a webapp project and we are considering deploying it on multiple servers.

What solution do you advise for clustering/load-balancing with Spring?

What are the issues to take into account?

For example: How do singletons behave in a cluster of machines? What about session replication? Are there any other issues to take into account?

like image 390
balteo Avatar asked Aug 02 '12 09:08

balteo


People also ask

How clustering is used in load balancing?

The load balancing process makes use of the concept of a cluster switch. What this means is that it distributes parallel tasks to computing units in a system. Proper load balancing ensures that a system is stable and can receive large amounts of traffic.

What is load balancing in spring?

Load balancing is the process of distributing traffic among different instances of the same application. To create a fault-tolerant system, it's common to run multiple instances of each application. Thus, whenever one service needs to communicate with another, it needs to pick a particular instance to send its request.

Is Netflix ribbon deprecated?

Spring Cloud Netflix Ribbon has been deprecated and is not included in the 2020.0. 0 release train. Spring Cloud LoadBalancer is the suggested alternative.


1 Answers

Here is the list of possible issues (not necessarily Spring-related):

  • stateful beans - if your beans have state, like collections accumulating something or counters, you need to think whether this state should be replicated or not. E.g. should this counter be local to one JVM or global in the whole cluster? In the latter case consider terracotta and hazelcast

  • filesystem - as long as all instances use the same database, everything is fine. But if one node writes to disk, other instance can't read it. Solutions? Either use database for all storage or distributed file system

  • HTTP sessions - either use sticky session or replicate sessions. If you go for replication, keep sessions as small as possible.

  • asynchronous jobs - if you have a job running every hour, should it run on every machine, or just on a dedicated one (or maybe on random)?

like image 172
Tomasz Nurkiewicz Avatar answered Sep 19 '22 23:09

Tomasz Nurkiewicz