Suppose multiple students have asked me for letters of recommendation to the same graduate department in the US. Am I expected to explicitly compare the students to one another? Am I supposed to do this in both letters (assuming they haven't been submitted yet)? Do I need to explicitly state a preference for one over the other, or can I just get away with listing relative strengths and weaknesses (for instance, "X is stronger academically, but Y has more research experience and is a stronger programmer")?
Since each individual student is asking for a letter of recommendation it would be appropriate to approach each letter as an individual task and not implicitly cross-reference between the letters by making comparisons. Direct comparisons between the specific students should not be made. It is after all the person or committee admitting the students to the program that will make decisions who may fit the best and their criteria may not be the same as yours. It is, however, reasonable to make implicit comparisons such as ranking each in relative terms to, say, all students you have encountered or some other frame of reference. This way each student is compared to a group and not each other. This is what one commonly does anyway.
I can imagine that you may get a request for more details by the person/committee if there is a difficulty in separating students. You could if you are willing, add a comment to the fact that you are willing to answer any questions that may arise during the process regarding the student in question.
While writing recommendation letters, you can write about each applicant's strengths. You do not need to compare them to each other, but you can say whether you consider them in to 10%, 20% etc (some schools explicitly ask for this information).
More than one student can be in the top 10%, for example. If you have a good formula to calculate this, you should just follow that. It will make your letters easy and consistent.
While I agree the students are competing they can still both get in! Especially if we are only talking two students applying to a cohort. Schools will remember students from particular institutions, and more quality students is a good thing as it suggests they were better prepped for grad school.
On the flipside, I fail to see how providing potentially disparaging remarks (even if indirectly in saying I would choose A over B) provides help to the student getting the positive hand. That is, if you say
A is a better student than B I don't see how this helps A against any of the other competition applying to the program besides over the B individual. Your creating a false dichotomy in doing so.
IMO the letters should really be orthogonal to one another (that is A's actions should have no bearing on B's letter) and you should focus on the individual in the recommendation.