Java – Approach to auto-scaling with Amazon AWS

amazon ec2amazon-web-servicesautoscalingjavarabbitmq

I want to know about the possible options for auto-scaling my web app architecture. What I have in architect is web-app (Tomcat), middleware (RabbitMQ), database(MongoDB), worker(standalone Java app). Right now I am attempting scaling based on the CPU Utilization. I can auto scale my web-app and worker as expected, but I am facing problems scaling rabbitmq because I do not know how to pass load to the newly instantinated rabbtimq server.

For instance, I have 2 Tomcat servers running. Whenever the CPU utilization of my RabbitMQ instance is greater than 80%, AWS will add a new RabbitMQ server. But my Tomcat server(s) do not know that a new instance of RabbitMQ is added, so they keep referring to the original RabbitMQ server only and not the newly created one.

What could I do? Should I auto-scale whole architecture when Rabbit CPU utilization goes up? Or should I give up the idea of auto-scaling RabbitMQ entirely and create the required instances at the initial stage of deployment? Are there other options?

Best Answer

The problem is that your Tomcat servers (and most likely your workers) don't know about the RabbitMQ server. You need to do 1 of 2 things in this scenario: (a) Tell them about the new server, or (b) Make it so that they don't care

For (a) above, you could notify each Tomcat server and worker when your new RabbitMQ server start, or put the info in some list that your other components references.

However, in this scenario, assuming you have a queue on RabbitMQ #1, what happens to that queue if you start RabbitMQ #2? You'll actually have 2 queues in this case, not a single queue spanning 2 servers. Does your application handle this?

For (b) above, you can take a look at RabbitMQ Clustering . My understanding is that with RabbitMQ clustering, you can have nodes come and go, and the clients shouldn't care.

Related Topic