The gut nourishes rich bacterial communities that affect profoundly the functions of the immune system. The relationship between gut microbiota and the immune system is one of reciprocity. The microbiota contributes to nutrient processing and the development, maturation, and function of the immune system. Conversely, the immune system, particularly the adaptive immune system, plays a key role in shaping the repertoire of gut microbiota. The fitness of host immune system is reflected in the gut microbiota, and deficiencies in either innate or adaptive immunity impact on diversity and structures of bacterial communities in the gut. Here, we discuss the mechanisms that underlie this reciprocity and emphasize how the adaptive immune system via immunoglobulins (i.e. IgA) contributes to diversification and balance of gut microbiota required for immune homeostasis.