Add delay to publish post

I think that by adding a delay you’re not really fixing the issue, you’re simply hiding it, until you grow and add more media and servers, so lsyncd will take longer, and you’ll have to increase your delay every time.

Also what about updating existing posts? People might add media items and update, or add more items to a gallery, you’ll have to add delays on every save action, sounds very hacky, fragile and bad UX.

I can think of three approaches to fix the problem. First, you can proxy requests to wp-content/uploads to your “master” server if the requested file was not found on the target server. I think you can do this with try_files in nginx:

try_files $uri @proxy;
location @proxy {
    proxy_pass http://master:80;
}

This should work well with your current setup, and @proxy will kick in when replication with lsyncd hasn’t finished yet.

The second approach would be to use a distributed filesystem, such as GlusterFS or Ceph. You can use them in an NFS-like fashion, i.e. mounted, readable and writable on several nodes at once, so you no longer have to have a “master” web server — every one of them would be able to write to the filesystem.

Note, however, that doing lots of file IO on a mounted remote filesystem can very easily become a performance bottleneck (#31066 comes to mind) so make sure you have some kind of disk io caching and very low latency (same rack or same datacenter at least) between your web servers and the filesystem cluster.

Third option would be object storage, preferably with HTTP access, like Amazon S3. It’ll require more heavy-lifting since now you’ll have to move all your uploaded files to a remote destination (don’t be fooled by s3fs, it’s a can of worms) and you won’t be able to easily do things locally, such as regenerate thumbnails, read EXIF data off of a local file, etc.

Now, to answer your original question. Instead of adding a delay I suggest you look into scheduling a post to be published, say 5 minutes from when the users hit the Publish button. For that I’d look into the transition_post_status action, watch for the draft => publish transition and change it to future with wp_insert_post().

Hope that helps!