504 Gateway Errors occur rarely when talking to the Microsoft endpoint.
The reason is unclear but people suspect some sort of rate limiting on high loads.
So far we have only seen this when updating the user images.
Fix: retry up to 2 or 3 times on 504 errors (when updating user images).