Why do some of the kindest, most selfless people struggle in life while others who lie, cheat and hurt people seem to have everything going for them?

I've always heard that good deeds bring good things while bad deeds eventually catch up to people. But in reality, I've seen genuinely good people suffer endlessly while those who manipulate or harm others seem to live perfect lives. It makes me wonder--does life really balance out in the end, or is it all just random?