Optimal grouping of components in a distributed system