Is there any way to create some script in server to restart services automatically when any one of the service got stopped [means when we receive 5xx errors] ?
Unfortunately we're not familiar with such a service.
Note that if that happens at a time when the server load is pretty high (due to high amount of requests), restarting may not be the solution as it will end up in the same situation after the service has been restarted.
In any case moving the database to a separate instance will solve (1).
After that you will be able to apply the following configuratoin:
(we recently changed the default configuration depending on the instance size)
That, in addition to moving assets to a CDN, should help decrease the amount of times errors (2) and (4) appear, and likely (3 - internal server error) as well.
Finally, before applying these changes, it would be useful to measure the impact. In order to do that, it would be great to know the frequency of the failures before, and after applying these.
I hope it helps!