To simplify only a tad, rank today is mainly associated with three things, some of them historical remnants: your salary, whether you are in the military for life or just passing by, and whether you are of privileged birth or commoner. The latter two used to be intertwined, but nowadays it's the former two that are related: you are a commissioned officer if you deem the higher but still meager salary good enough for living, but an enlisted fellow if you are there to grab enough money from the lower salary to move on with your life.
On a secondary level, rank may indicate how long you have spent at your job, or how good you are at it. Those two things need not correlate at all.
By the 24th century, one would think that the noblemen vs. peasants thing would finally be forgotten for good, and the social or financial status of the recruit would not affect his or her or its career future much. One would also assume that salaries as career motivators would be massively diminished by the welfare-state nature of the UFP.
This would basically leave us with the "secondary level", and bring rank closer to what to me appears the ideal: an indicator of one's commitment to career, still in terms of service years but even more so in terms of skills and ambitions. There would be little drive to get a higher rank for the higher salary it offers - for all we know, Starfleet has a flat pay rate for all ranks, or has some futuristic arrangement that supercedes pay and does not favor fast promotions. And there might not be any sort of an "up or out" policy, so one could reach advanced age and career years and still remain a junior Lieutenant like Picard in "Tapestry".
As such, rank could be established to perfectly match one's position in the command chain, so that all Lieutenants would be perfect choices for bossing around Ensigns, and all Captains would be good bosses for Commanders. Fields of speciality would still confuse the picture somewhat, though - so it would be an excellent idea to have narrow-fielded specialists wear blue so that one realizes that "their" Commanders aren't necessarily any good commanding "our" Lieutenants.
Whether there would be a rationale for the red and yellow uniforms is debatable, then, but one might argue on basis of the rationale for blue. That is, the TNG yellows or TOS reds would represent middle ground in terms of expertise. They would be generalists enough to be good bosses for all blueshirts, capable of utilizing the special skills of those people without possessing such skills themselves. But the TNG reds or TOS yellows would take this one step further, by being very well trained in command while possessing few actual practical skills. In a crisis situation, one would immediately look for guidance from a TNG redshirt, practical skills from a TNG yellowshirt, and expertise from a blueshirt.
Trying to interpret the three colors as indicating shipboard divisions, skillsets or types of training is a bit futile: three is far too few for that, and even the dozen colors of the TOS movies would be a bit narrow a range. But interpreting the colors as "levels of generalization" or "levels of command qualifications" works just fine in most cases. There are very few instances where a TNG yellowshirt would boss over a TNG redshirt, unless clearly outranking him or her and possessing special expertise pertinent to the situation (usually engineering or security expertise). There are a few instances where a low-ranking TNG redshirt rightfully wrestles command from a slightly higher-ranking TNG yellowshirt, and a lot of instances where blueshirts are bossed around. The cases where a blueshirt gets a say outside his or her area of expertise are extremely rare, unless one counts Spock whose status as a "secret goldshirt" was quite explicit anyway. So that system basically works, whether or not it is intended by the writer of the episode in question, or indeed by any writer.
Timo Saloniemi