We study how social relations affect public service delivery and test whether group identity is the mechanism underpinning this effect. In collaboration with the NGO BRAC we randomly select one of two candidates for the position of delivery agent for an agricultural extension program. The design creates exogenous variation in social connections to the delivery agent among groups of ex-ante identical farmers. Combined with naturally occurring variation in the political and religious affiliation of the candidates we show that: (i) delivery agents favor farmers they are socially connected to and discriminate those connected to the other candidate; (ii) both favoritism and discrimination only arise when the two candidates identify with different political or religious groups. This biases targeting as the delivery agent gives priority to rich farmers connected to her at the expense of poor farmers connected to her rival. However, because altruism towards potential beneficiaries motivates the delivery agent to exert more effort and differences in identity create heighten both altruism towards one's friends and spite towards the friends of the other, the number of reached beneficiaries might be larger in divided communities.