Q:

What to do when you reach a conclusion and find out later on that someone else already did?

Say you've thought hard about a specific issue in your research and have elaborated a possible answer, interpretation, etc., to tackle it. (I'm not thinking about huge research subjects, but rather small ideas that articulate a demonstration.) You then discover later on, while reading a new paper, that someone has thought about the exact same thing. How do you present your idea on the issue?
On the one hand, you can't pretend that you haven't read what the other paper says about it, both for reasons of intellectual honesty and because the other author (or someone who read his paper) might think that you stole his idea. Citing the other paper is thus somewhat of an obligation.
On the other hand, it doesn't feel right to dismiss your demonstration and just cite the other paper, since, after all, you figured out a solution on your own. Conversely, it seems somewhat pointless (and maybe arrogant), to write explicitly that you reached the given conclusion and only then found the other article.
What to do in such circumstances?

A:

Do not despair: your work likely still has value!
In my experience, it's almost never the case that work addressing the same problem has exactly the same solution or exactly the same approach to gathering evidence.  Existence of a previous publication will thus typically make your results smaller and more incremental, but not invalid or duplicative.  Some examples of what your work may provide:

A second, independent confirmation of a hypothesis
Confirmation of a closely related but different hypothesis
A different approach that has advantages in some situations and disadvantages in others

There are even good journals like PLOS ONE that explicitly invite replications and "non-notable" incremental work.  Thus, if you've got a set of results in hand and you discover somebody else has done much the same, you should still write up your work---just be straight and honest about the smaller size of contribution based on the prior work.
If you're still at the "ideation" stage where you're just thinking up possible work to do, however, then it seems more appropriate to move on and work on something else instead---maybe building on their results.

A:

I'd argue that this is pretty common in research. As a consequence, the right thing to do is just cite the paper.
If, however, your derivation/interpretation/explanation is slightly different, you should both cite the paper and present your own work. 
It may feel unfair to you, that you don't get credit for coming up with the same solution, but don't worry. If you came up with the same (presumably) correct solution, it shows that you are a good way. You have the right thoughts about good topics. That's good for you.

A:

This happens quite a lot if you are working in a field with a lot of current research interest. Things that you know are also known by others. People working parallel tracks can often come to the same insights at about the same time. 
If there is nothing novel in your work compared to the other, you just do what you would normally do and explore extensions and deeper results. You can't be denied the satisfaction of having discovered something, even if you don't get public acclaim for it. 
Write the next paper. 
But, if you think it worthwhile, you can also contact the other author, mentioning that you discovered the same thing independently and exploring whether it is worth working collaboratively. Often this can be a good way to expand your research "neighborhood." 

