Halachah, that's what makes it justice. If you act halachicly you do justice, because that's what God called justice. If you act against the Halachah you're driven by your feelings.
Indeed, reciprocity and retaliation are innate biological behaviors observed even with animals, so both revenge and justice come from the same biological urge. But the only difference between the two is whether it is sanctioned by the Torah or not. If it is, for example paying for damages (eye for an eye), it is considered justice, it is permitted and even a Mitzvah to do, if it is not - it is revenge (or driven by revenge) and it is prohibited.
Here's a simple example: someone is calling you names and you know that no Rabbi allowed to call names back. So if you retaliate, you're taking revenge. But if the next day you consult your rabbi and he permits you to respond, you suddenly do justice. As I said, just because it was sanctioned by the Torah authority.
So in your case, ask a rabbi, as his ruling will determine what your behavior is.
It could be generalized, of course to other native behaviors - murdering is bad but stoning heretics is Mitzvah, stealing is bad, but looting in war is good, adultery is bad but for heavenly purposes it's OK, breaking Shabbos is bad but for saving lives it's good, etc. Basically, we can not know apriori if certain behavior is good or bad until it is ruled Halachicly.