A word for one who is sacrificed or suffers so others need not
Although the word martyr somewhat applies, it includes a nobility not necessarily present.
An idiom describing this, in a voluntary situation, would be drawing the short straw, thereby acquiring some unpleasant or dangerous duty. An idiom for an involuntary situation would be getting thrown under the bus.
Context
Friend: I knew someone would eventually need to refactor this code. I didn't think it would be me.
Me: You're our... uh, what's the word?
patsy:
- a person who is easily cheated, victimized, etc
- a scapegoat
cannon fodder:
men regarded as expendable because they are part of a huge army
pawn:
a person, group, etc, manipulated by another