Howdy!
I'd recommend a server with at least 1gb of ram (which you might still have, but I'm guessing you may have a 512mb ram server as this issue is fairly common on servers with only 512mb of ram).
In any case, you can add "swap", which is a partition of the disk drive that the operating system can use when RAM is fully used. When swap is used, the server WILL slow down, but it can also prevent quick tasks like a deployment to work successfully without failing.
Some people would rather let the server fail and be alerted, but for this use case, I'd recommend enabling some swap.
Here's how: Log into your server and run the following:
# Create the Swap file, 1GB in size
sudo fallocate -l 1G /swapfile
# Set the correct Swap permissions
sudo chmod 600 /swapfile
# Setup Swap space
sudo mkswap /swapfile
# Enable Swap space
sudo swapon /swapfile
# Make the Swap file permanent
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
# Add some swap settings:
# vm.swappiness=10: Means that there wont be a Swap file until memory hits 90% useage
# vm.vfs_cache_pressure=50: read http://rudd-o.com/linux-and-free-software/tales-from-responsivenessland-why-linux-feels-slow-and-how-to-fix-that
printf "vm.swappiness=10\nvm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.conf && sysctl -p