The Variable Geometry Vanes in most modern jet engines help prevent this "flow reversal"...they modulate their position based on engine demand to provide the smoothest front to back airflow..i guess you could kind of relate it to a sort of "check valve"....sorta
To put it simply..without going into the countless variables that could determine / change the most "desirable altitude" the main goals are to find the...
1.) most efficient fuel flow in respect to altitude..obv specific engine performance dependent
2.) highest true airspeed with respect (as said above) to MEAs and of course the hemispherical rules of what altitudes to fly with directions
3.) most advantageous tailwind
and then any other factors that make sense. You're not going to climb to FL350 from JFK to BOS to get an 80 knot tailwind..just not practical on such a short leg