Naturally the biggest factors in the lifespan of a roof are the quality of the materials and workmanship when the roof is put on. Metal and tile roofs can last twice as long as asphalt shingle roofs, but they also cost more to install.
Workmanship is a factor because there are so many opportunities to do the job badly or skimp on materials. If you're thinking of having a new roof put on, consult the Angie's List tips on hiring a roofer. If you're buying a house, make sure you have the roof inspected and find out from the seller what year the roof was put on.
For the homeowner, the primary roof maintenance responsibilities are:
Keep the gutters clean to prevent unnecessary water damage to the lower deckboard, and the fascia and soffit boards along the gutter line.
Remove debris from the roof such as tree branches and leaves that may collect along roof valleys.
Watch for ice dams that may develop in winter when snow on the roof is partially melted.
Have the roof professionally inspected every two or three years and have small repairs made as needed -- such as resealing weak spots that may begin to develop along the flashing.