Load Balanced Servers - Syncing Uploads

Hi all,

I am using Trellis: 0.9.9

I’ve search these forums for the answer to my question, but whilst many touch upon a similar setup, I am reaching out to see if there’s an optimal way to achieve what I want using the Roots stack.

I have a WordPress site that will be load balanced, with likely two web servers and one remote database that’ll serve them. Nothing too crazy going on there, it all works fine.

The obvious concern is how to handle any plugin generated files that may appear in the /uploads/ directory, alongside whatever media is generated using the WP Dashboard. I will likely have frequent posts in the backend, with multiple media attached, so ideally I don’t want those files present on one of the servers, and not the other.

I understand that I could utilize a plugin to offload the media aspect to S3, or indeed create my own solution to do that, and while it’s a great option, I’m wondering if there’s something perhaps more native that can account for anything that hits the uploads folder.

This user has a somewhat similar setup to what I want, although I’m not too well versed in how I might ensure a valid cache between both web servers.

Anyway - I see NFS is mentioned, which will allow any files that are uploaded to one particular server instance to be instantly available to the others that have the NFS mounted, correct? This would work, I’d imagine, but is there a better way in true Trellis style

I notice the following in Trellis Deploy Roles:

  - path: web/app/uploads
    src: uploads

…but I can’t make 100% sense of it, or how it might apply to me.
Does Trellis account for this need of a shared upload folders across servers given that the uploads folder exists outside of the main site files?

1 Like

That sets a shared uploads folder on the remote server so every release serves it’s uploads from that folder. There might be a way to use a external server for that?

Thanks for that. So seemingly the uploads are pulled out of the normal release so nothing is overwritten in each time there is a new one?

I wonder if I can set that ‘path’ to the path of a NFS mounted drive (that contains all the uploads)? But I assume I would need to redefine where uploads should go, for anyone pushing media from any of the WordPress Dashboards…

Sort of, it’s nothing more than a symlink in every new release to the shared folder

1 Like

So it looks like the following setup for me: 2 load balanced servers, 1 remote database, 1 NFS server to provide the /uploads/ to both workers. Perhaps a caching layer on the same server as the remote DB, if my research has proven fruitful.

If anyone has any better ideas of how to go about it, happy to hear.

Hi @Doocey, I don’t want to go off-topic, but how do you have managed to make Trellis compatible with a load balancer configuration? Is there some specific step by step guide/documentation to accomplish this? Thank you! :smiley:

No specific guide per say, but Trellis is pretty versatile.
I’m simply deploying to two servers under one command line deploy (two servers with identical code) which Trellis accounts for in the environment’s host file. I’m also defining a shared remote database in the specific environment’s vault.yml file.

As for the actual load balancing, I’m simply being provided the servers themselves, which I push to. The load balancing is being handled by someone else on our team, but it’s fairly straight forward in that it will delegate traffic via Round Robin technique.

I haven’t implemented NFS just yet to share the /uploads/ directory between the two web servers, but I’m hoping to sort it soon. I could offload all media uploads to S3 and serve via Cloudfront for an efficient setup, but I wanna further examine whether any PHP generated files/non-media files that might land in the uploads folder from plugins etc can be shared between the web servers easily, perhaps without the need for NFS.

My hosting is Rackspace, but I do know that the Roots.io team have tutorial guide how to use DigitalOcean’s block storage which is certainly along the same lines of the setup I’m eyeing.

1 Like

@Doocey Thank you so much for the explanation! :smile:

we use aws elastic beanstalk environment for load balancing. honestly you save yourself all the pain by using s3 offload (or similar solutions).

I’ve heard good things about AWS EB, but I’m not sure I have the leeway to switch over to that setup in my current position. Seems like it would pretty much serve all of my concerns, mind…

This topic was automatically closed after 42 days. New replies are no longer allowed.