Its impossible to have a flawless justice system. There will always make mistakes, which is why, in civilized societys, permanent punishments, i.e. execution and dismmeberment are not practiced.
However, in the US the flaws are not of the unavoidable kind, as they occur pretty clearly along economic and racial lines. Our justice system is incredibly biased in favor of those with money(court appointed attorneys are far from equal to high priced private lawyers, there have been numerous documented cases in which they've been found to fail at things like remembering to file appeals in time to being high on drugs while in court), and in many places very biased in favor of those who are white(look at the statistics for how likely a prosecutor is to seek the death penalty in cases where a black person has killed a white person and vice versa.)