If rejected for a position, maintain pride in your accomplishments, analyze the situation, regroup and persevere. No matter how good you are, how talented or how exceptional, you will not get every job you go after. Accept this fact and it will reduce your frustrations. A number of factors go into any hiring decision. Managers may want to add someone else with a different background to round out the team.
Chemistry can also be a factor.
You're just going to hit it off better with some people than with others. Think about it. If you learn that the person who got the job had qualifications that you're lacking, then get busy and get qualified for the next opening. Things haven't changed much. When you join a company, you're the new kid, and, considering that demographics are still skewed toward white people, you may stand out even more.