der Ersatz
replacement
A person or thing that takes the place of another; a substitute or stand-in.
Da der Kaffee aus war, trank sie Tee als Ersatz.
Since the coffee was gone, she drank tea as a replacement.

replacement / compensation
Loading your saved state.
replacement
A person or thing that takes the place of another; a substitute or stand-in.
Da der Kaffee aus war, trank sie Tee als Ersatz.
Since the coffee was gone, she drank tea as a replacement.

The noun 'der Ersatz' (the replacement/compensation) is directly derived from the verb 'ersetzen' (to replace). 'Ersetzen' means to put something in the place of something else. 'Der Ersatz' is therefore the person or thing that takes on this function.
Wir müssen den kaputten Stuhl ersetzen.
We have to replace the broken chair.
You can recognize the meaning from the context. If it is about standing in for a person or thing, 'Ersatz' (replacement) is a substitute. If it is about damage or loss, 'Ersatz' (compensation) is compensation, often in the form of money.
Der verletzte Spieler braucht einen Ersatz.
The injured player needs a replacement.
When 'Ersatz' (replacement) is a substitute, it is very often used with the preposition 'für' (for) and the accusative. This expresses what or who is being replaced.
Gibt es einen Ersatz für den ausgefallenen Flug?
Is there a replacement for the canceled flight?
In the sense of compensation, 'Ersatz' (compensation) is often combined with the verbs 'leisten' (to provide/pay), 'fordern' (to demand), or 'verlangen' (to demand/request). These combinations are typical of formal or legal contexts.
Der Verursacher des Unfalls muss Ersatz leisten.
The person who caused the accident must provide compensation.
representative / substitute
'Vertreter' and 'Ersatz' can both mean a person who steps in for someone else. 'Vertreter' is used especially when a person temporarily takes over a task, function, or role, for example at work, at school, or in an organization. 'Ersatz' is more general and can be a person or also a thing that takes the place of something else. It often sounds more practical and less official. Learners confuse the words because a 'Vertreter' can be a kind of 'Ersatz'. When it is about a professional or official role, 'Vertreter' is more precise; when something or someone is simply used instead of the original, 'Ersatz' fits.

Im Restaurant gibt es keinen Reis mehr, deshalb bekommen wir Kartoffeln als Ersatz.
There is no rice left in the restaurant, so we are getting potatoes as a replacement.
Für die kranke Lehrerin kam heute ein Vertreter in die Klasse.
A substitute came to the class today for the sick teacher.