We investigate the trade-off between the risk-sharing gains enjoyed by more interconnected firms and the costs resulting from an increased risk exposure. We find that when the shock distribution displays "fat" tails, extreme segmentation into small components is optimal, while minimal segmentation and high density of connections are optimal when the distribution exhibits "thin" tails. For less regular distributions, intermediate degrees of segmentation and sparser connections are optimal. Also, if firms are heterogeneous, optimality requires perfect assortativity in a component. In general, however, a conflict arises between efficiency and pairwise stability, due to a "size externality" not internalized by firms.