edz
edz

Reputation: 41

Java distributed tasks

I am building system which should be consisted of 3 servers and same Java (Spring mvc) service would be running on all 3 of them. Service will be able to do 3 categories of tasks, i.e. A, B and C.

What I want is to make each service on servers perform only one category while communicating with other server. If one server dies, remaining servers should negotiate and only one of them should take category.

Example:

  1. Server 1 - Service does A

    Server 2 - Service does B

    Server 3 - Service does C

  2. Server 2 Dies

    Server 1 and Server 3 negotiate

    Server 1 - Service does A and B

    Server 3 - Service does C

If server 2 returns to normal state it should take category from Server 1 (A or B)

Is there any pattern, architecture, technology, link that could help me solve this?

Upvotes: 4

Views: 166

Answers (1)

Ravindra babu
Ravindra babu

Reputation: 38950

Zookeeper was especially meant for handling these types of scenarios in distributed environment. One master will be elected out of N number of servers by acquiring a lock. Once master dies, it causes re-election and new master will serve client requests.

Other alternative,which is error prone is implementing a shared global distributed lock by yourself and handle corner cases. The server who acquires the lock will serve the client requests.

From zookeeper documentation page:

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications

enter image description here

You can find more details in zookeeper Overview page.

Upvotes: 1

Related Questions