Natural communities harbor many species. Ecologists debate to what extent different species occupy different niches, and whether other mechanisms help to avoid competition For instance, if a species is a good disperser, it may maintain itself among stronger competitors by timely dispersing to new patches. Nematodes are the most abundant invertebrates in marine sediments, and are very species-rich. Many species feed on the same resource class; for instance, we find many bacterivorous nematode species together. Here, we investigate whether species specialize for different parts of a resource class by using cutting-edge metagenetic tools. If they do, this niche divergence may explain their coexistence. We test this at different levels of taxonomic relatedness: by comparing species belonging to different families, different genera within a family, different species within a genus, and different individuals within a species. We expect that resource divergence will be stronger and competition weaker among more distantly related species. If so, then closely related species will probably rely more heavily on dispersal to avoid competition. Thus, we investigate whether the levels of resource divergence and of relatedness affect dispersal. If dispersal helps to avoid competition, a patchy habitat will allow more coexistence than a homogeneous habitat. Hence, we compare coexistence among competitors in patchy and dynamic vs homogeneous habitats containing different food availability.