How online communities develop and evolve

Has anyone written a book or a paper about how online communities evolve over time? Despite best intentions, there always seems to be some undesirable traits or qualities that appear given enough time. For example, StackOverflow has all the ingredients for a great community managed ‘developers helping developers’ Q&A site, and yet among new developers it’s considered a toxic and unwelcoming community. Why is this, and why does this happen?