Afaik this is not an error from Lemmy but from nginx, which is not able to relay the request to Lemmy and therefore returns a 502 bad gateway response. Imo this just means the servers are over capacity, so most likely a scaling/infrastructure issue.
I had a quick read of the code and it looks pretty solid to me. Not the most “enterprise” code imaginable, but definitely no code smell or quick hacking job.
My server is a DiskStation, so I use HyperBackup to do an encrypted backup of the important data to their Synology C2 service every night.