Search code examples
phpapacheload-balancingsquid

Multi-Step Image Submission To Load Balanced Server Problem


We have two apache/php web servers load balanced with squid page caching proxy. The squid caching is not active on image submission pages. We have a form where users can submit images.

It's a two step process. They first upload the images. The second step they can enter details about the images and images are then moved over to correct folders once they submit the image details.

Problem is when there is high traffic the second step might be served from a different server then the one with the uploaded images. So the second step might not find the uploaded images and upload fails to complete.

We have thousands of image files on these servers so the syncing between them is slow. Is there anyway that we can force a specific page to always to be served from a specific server? Basically to bypass the load balancing feature.


Solution

  • There are a few solutions to this.

    1. Switch to nginx as a reverse proxy and you can stick clients to the host
    2. Make the upload directory a NFS share mounted on both hosts
    3. Upload the file into a mysql table (probarbly best to use a hash table) so both servers can access it.

    Personally I would go with option 1 as you still get round robin load balancing, but each connection is stuck to the host that it was initially connected to.

    Option 2 has the benefit of still equally balancing requests, but the downside is the NFS share is a single point of failure.

    Option 3 can cause issues if there is not enough ram on the DB server if you use a hash table.