One contribution of 13 to a theme issue 'Evolutionary ecology of arthropod antimicrobial peptides'. Drosophila melanogaster lives, breeds and feeds on fermenting fruit, an environment that supports a high density, and often a diversity, of microorganisms. This association with such dense microbe-rich environments has been proposed as a reason that D. melanogaster evolved a diverse and potent antimicrobial peptide (AMP) response to microorganisms, especially to combat potential pathogens that might occupy this niche. Yet, like most animals, D. melanogaster also lives in close association with the beneficial microbes that comprise its microbiota, or microbiome, and recent studies have shown that antimicrobial peptides (AMPs) of the epithelial immune response play an important role in dictating these interactions and controlling the host response to gut microbiota. Moreover, D. melanogaster also eats microbes for food, consuming fermentative microbes of decaying plant material and their by-products as both larvae and adults. The processes of nutrient acquisition and host defence are remarkably similar and use shared functions for microbe detection and response, an observation that has led to the proposal that the digestive and immune systems have a common evolutionary origin. In this manner, D. melanogaster provides a powerful model to understand how, and whether, hosts differentiate between the microbes they encounter across this spectrum of associations.This article is part of the themed issue 'Evolutionary ecology of arthropod antimicrobial peptides'.