I a perfect world with heterogeneous workers and jobs, the matches are those that maximize efficiency. But when information about the quality of either is private and cannot be revealed credibly, the economy quickly looses efficiency. The solution is then to make hiring and firing easy, so that good matches can be found by trial and error. Employers also try to gather information about their potential employees, and their socio-demographic characteristics are certainly among them. While this looks like discrimination, it is OK if it is only statistical discrimination. But one can improve on this.
Christian Dustmann, Albrecht Glitz, and Uta Schönberg study job referrals from co-workers. They find that typically shunned minority workers are more likely to be hired the more other minority workers are already present, a clear sign of job referral. In addition, these workers earn on average higher wages and are more likely to stay in such firms. In some sense, this shows that job search networks can be better than open competition under some circumstances. One could even stretch the argument to claim that favoritism could be beneficial.