Yes, there is an age by which people generally realize their sexual orientation, and that is most often in adolescence. For some people, it is a bit earlier in childhood, and for some it is a bit later in early adulthood. Any of these ages is perfectly acceptable and one should not worry about which age it occurs in.
Some people have homosexual relationships in part because they are very traumatized by their previous heterosexual relationships. They falsely conclude that everyone of the opposite sex is just as awful as their 'ex. So they choose to partner with someone of the same sex. This can happen at any age.
Some people realize early in their life what their orientation is. However, for some people they may realize as adults, perhaps even in middle age and beyond. This is especially the case for those who are not heterosexual, as their culture may discourage non-heterosexual orientations, such that people may suppress or avoid non-heterosexual situations and thus may not realize what they are really attracted to.