Generally, the most reliable way to differentiate between a frontend and backend request is to check the request's URL and see if the /Sitefinity parameter is present. This parameter indicates that the request is a backend one. Sample code would be:
//you are working with backend request
//you are working with frontend request
There might be exceptions, depending on the Sitefinity version used. For example, service calls to the /sf/system and the /restapi routes. Place the necessary checks where applicable.