I'm almost certain writing was invented first. It was likely used for people to keep track of things. But everybody had their own unique symbols. So if person A wrote something, person B and Person C could not read it. Over generations, things probably got a little more standardized so that everybody in a community or a village could read eachother's writing. But somebody from a village 20 miles away couldn't read it.
As things developed eventually people needed more standardization so that anybody with an education who speaks the language can understand what everybody else is writing. And so over more generations of time, the alphabet sort of just evolved into being.
I'm sure not every community did this. But a lack of standardized writing put them at a great disadvantage to those that did. Those who could communicate and keep records efficiently eventually conquered those who could not, and the victors then spread their language/culture/alphabet/etc. to the newly conquered lands. This process went on until the alphabet spread around the world. (although different regions have different styles of alphabets. Western alphabets vs Eastern alphabets for example).
Today with the internet and airplanes and everything, things will continue to become more standardized. In a few hundred years the whole world will probably have one culture, one alphabet, and one language. And there will probably only be one race, because all races will mix and meld into one.