"Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards ten years later." I've found this particularly true. As long as you're working on something interesting and difficult, you're probably not wasting your time, even if you can't see yet where it leads. It will be an ingredient in something.
I think the key ingredient is inspiration. I find it not always clear where to look for it. On Hacker News? When traveling? What makes one think "This is something I want to work on." and makes one stick with it long enough? It seems like there's a certain ingredient to personalities that some people have more of while some have less.