In general, democracy works because it doesn’t work.
One reason why democracy tends to produce decent outcomes is that educated, elite political insiders tend to control the political parties and the bureaucracy. To a significant extent, these elites prevent the people from simply getting what they want. What we see this year, with the rise of Donald Trump, is what happens when the Republican establishment breaks down, and is forced to run a populist candidate rather than a candidate the savvy insiders prefer.