Search code examples
databaseamazon-web-servicesamazon-ec2rdselastic-load-balancer

Redirecting admin url traffic to a particular load balancer


Current Setup: I've two load balancer each containing EC2 instances from different regions. Primary region has Read-write DB & secondary has read-only replica of primary DB.

There are also 2 record sets in Route 53 which are configured with load balancer such that whenever a user hits my website, the traffic is distributed among these two load balancer in 70:30

Why I'm opting for read-only? so that i just have to update one DB and the changes are synced across the slaves.

Problem: When I update my website with admin url, there is a 30% chance that I am connected to the read-only DB, hence I'll get server error as the DB gets locked.

What I'm looking for: Is it possible to route my traffic to the read-write DB whenever someone accesses admin url, eg:www.example.com/admin should always hit my primary server, so that the any write operation is done in my read-write DB only.

I'm using Apache server with mysql DB.

Thank you.


Solution

  • You can configure a listener to your Application Load Balancer. I don't want to rewrite everything in the documentation, but I think this answers your problem:

    Benefits

    Using an Application Load Balancer instead of a Classic Load Balancer has the following benefits:

    Support for path-based routing. You can configure rules for your listener that forward requests based on the URL in the request. This enables you to structure your application as smaller services, and route requests to the correct service based on the content of the URL.

    Here is the full documentation