Modern microbial mats are relictual communities mostly found in extreme environments worldwide. Despite their significance as representatives of the ancestral Earth and their important roles in biogeochemical cycling, research on microbial mats has largely been localized, focusing on site-specific descriptions and environmental change experiments. Here, we present a global comparative analysis of non-lithifying microbial mats, integrating environmental measurements with metagenomic data from 62 samples across eight sites, including two new samples from the recently discovered Archaean Domes from Cuatro Ciénegas, Mexico. Our results revealed a notable influence of environmental filtering on both taxonomic and functional compositions of microbial mats. Functional redundancy appears to confer resilience to mats, with essential metabolic pathways conserved across diverse and highly contrasting habitats. We identified six highly correlated clusters of taxa performing similar ecological functions, suggesting niche partitioning and functional specialization as key mechanisms shaping community structure. Our findings provide insights into the ecological principles governing microbial mats, and lay the foundation for future research elucidating the intricate interplay between environmental factors and microbial community dynamics.