Yes, judges have a lot of leeway, and that's how you get things like brock turner's "good kid" sentence while a black teenager gets years for a minor drug offense.
The US legal system also thrives on plea deals. Prosecutors charge people with WAYY more than is fair, so the risk of going to court is too high (years in jail) and defendants are bullied into plea deals that suck.
If you'd like to learn more about how messed up this system is, season 3 of the podcast Serial is a pretty good starting place.