Introduction

One of the major goals of microbiome research is to achieve a mechanistic understanding of the structure, function, and dynamics of microbial communities [1, 2]. The recent rapid proliferation of metagenomics and other -omics data has promoted correlation-based, large-scale statistical analyses of these ecosystems [3]. One common property revealed by these studies is that communities can often exist in multiple or alternative stable states, distinguished from each other by differences in the abundance profiles of surviving species. Examples of this include the human gut microbiome [4, 5], bioreactors [6], and soil communities [7]. Moreover, external perturbations—such as the temporary introduction (or removal) of nutrients (or microbes)—can trigger transitions between these stable states. This is often the basis for the effect of prebiotics and probiotics on the gut microbiome [8, 9] and disturbances in bioreactors or other engineered environments [10]. However, our ability to predict stable states as well as direct and control their transitions remains limited. Developing a deeper conceptual understanding of community structure, we believe, is an important step towards such an endeavor.

Ever since pioneering theoretical work by MacArthur and Tilman [11, 12], resource competition has been a promising approach to modeling stable states in microbial communities. Following ref. [11], contemporary models of microbial communities typically assume that microbes simultaneously co-utilize several substitutable nutrients as sources of carbon and energy [13,14,15,16,17,18]. However, as first described by Monod [19], many microbes tend to utilize these nutrients in a specific sequential order. When exposed to a mixed medium containing multiple nutrients, microbes begin to grow by first utilizing their most preferred one. Upon the exhaustion of this nutrient, and after a period of stasis known as the lag phase, they undergo a diauxic shift and resume growth using the next available nutrient down in their hierarchy [19]. This continues until all consumable nutrients in the medium that the microbe could grow on are exhausted.

Recent work by Martens and collaborators [20,21,22] has established that many species in Bacteroides (the most prevalent genus in the human gut microbiome [23, 24]) exhibit this kind of preferential nutrient utilization—with respect to polysaccharides present in a typical diet [25]. Interestingly, even species such as B. ovatus and B. thetaiotaomicron—which are closely related evolutionarily—display rather different polysaccharide preference hierarchies [22]. Similar results have also been demonstrated for Bifidobacterium species [26]. In addition, many of these species are simultaneously present in the gut at high abundances. This is in spite of their similar nutrient utilization capabilities [21, 27] that should have promoted competition and mutual exclusion [28]. This apparent “habitat filtering”—where potential metabolic competitors are frequently detected together at high abundances—remains a puzzling observation.

Describing community dynamics where microbes utilize nutrients one at a time can be approached either via mechanistic or conceptual models. To develop mechanistic models, however, the main obstacle is that they rely on the knowledge of a large number of quantitative parameters, e.g., growth curves of individual microbes, kinetic rates of adsorption, and release of small molecules, etc. The vast majority of these parameters are hard to measure and are currently unknown. This further necessitates the need for conceptual models with a much more coarse-grained description of interactions between microbes and nutrients. In particular, the first question that such models need to deal with concerns “matching”: how do complex communities divide resources among their constituent microbes?

In this study we present a new conceptual modeling approach that provides mechanistic insights into several phenomena in microbial communities, specifically: the existence of multiple stable states and inter-state transitions, as well as restructuring and resilience of these states. Our model is inspired by a decades-old economics work: the stable marriage or stable allocation problem, developed by Gale and Shapley in the 1960s [29] and awarded the Nobel prize in economics in 2012. We also apply this approach to predict patterns in polysaccharide utilization preferences of seven Bacteroides species residing in the human gut. We believe that our model can help bridge the gap between statistical analyses based on metagenomic data and a detailed predictive description of community dynamics.

Results

A model of microbial community dynamics inspired by the stable marriage problem

The traditional formulation of the stable marriage problem (SMP) is the following: N men and N women have to be matched pairwise in N “marriages”. Every person has associated with them a preference list of all members of the opposite sex, ranked from their most preferred marriage partner (rank 1) to their least preferred one (rank N). A matching is “stable” if it has no “blocking pairs”, i.e., it has no man–woman pair (who are not currently married to each other) who would both prefer each other to their current marriage partners. One can show that stability with respect to blocking pairs is sufficient to ensure stability with respect to a coalition of any size [30]. Gale and Shapley proved [29] that there is always at least one such stable matching, and introduced a “men-proposing” algorithm to find it. According to this algorithm every man first proposes to his top choice partner. If a woman receives more than one proposal, she temporarily accepts the most suited partner according to her preference list and rejects the others. Men rejected during the first round propose to their second choice and so on. If a woman later on receives a proposal that is better than her current partner, she accepts it and releases her previous choice. One can prove that the state achieved at the end of this men-proposing procedure is stable [30]. In general there are many different stable states for a given set of preference lists (on average (N/e)logN for random lists but occasionally exponentially many more). When the set of men and women have unequal sizes, the number of pairs in any matching is given by the size of the smaller set. Furthermore, in all stable states, the partners left without spouses are always the same [30]. Another version of the problem is one with unacceptable partners (partial lists). In this case, one can show that the number of pairs in a stable matching is generally smaller than the number of men and women. As in the previous case, the same set of partners are left without spouses in every stable state [30]. The SMP still remains a field of active mathematical research. In particular, some of the recent work addresses various aspects and extensions of the original problem, such as the notion of “universal beauty” and correlations in preference lists [31], scaling behaviors [32], partial information [33], three-dimensional preferences and agents [34], and versions with ties in preference lists [35].

In our application of this problem to microbial communities, a set of “marriages” constitutes a one-to-one pairing between microbial species and substitutable nutrients. Consider a set of microbes capable of utilizing the same set of fully substitutable nutrients (e.g., carbon/energy sources). A more general case when each microbe could utilize only a subset of all available nutrients (incomplete ranked lists) is discussed later on in our study. The central assumption in our model is that every microbe consumes these nutrients in a diauxic (or more generally polyauxic) fashion, i.e., one nutrient after another in a specific sequential order. This order is encoded in microbe’s transcriptional regulatory network combined with diverse post-transcriptional mechanisms of catabolite repression [36, 37]. Detailed kinetic modeling of catabolite repression in even one organism (E. coli) is rather complicated and involves up to 63 state variables connected up to 473 kinetic parameters, most of which are not known experimentally [38]. The advantage of the SMP-based approach is that it depends only on the ranked microbial preferences toward nutrients, thus bypassing the need for precise measurements of such kinetic parameters. These ranked preferences ranging from 1 (the most preferred nutrient, such as glucose for E. coli) to N (the least preferred one) are illustrated in Fig. 1a and may be different even between closely related microbial species [22].

Fig. 1
figure 1

Ranked interaction tables encode microbes’ nutrient preferences and competitive abilities. Two ranked tables with each microbe’s preferences towards nutrients (a) and their competitive abilities with respect to each particular nutrient (b) fully define our model. We illustrate them using two microbial species, M1 and M2, represented correspondingly by dark and light circles, and three nutrients, N1, N2, and N3. Both species can use all three nutrients. a Microbial nutrient preferences: the dark species prefers nutrient N1 the most (rank 1 in the table above), N2 next (rank 2), and N3 the least (rank 3), while the yellow species prefers nutrients in the order: N3 > N1 > N2. b Microbial competitive abilities: the dark species (rank 1) can displace the light species (rank 2) in a competition for utilizing the nutrient N2, but will be displaced by the light species when competing for nutrients N1 and N3

If two or more microbes attempt to simultaneously consume the same nutrient, we refer to this event as competition, whose outcome is determined by the relative competitive abilities of the respective microbes. In our model, the competitive ability of a microbe on a given nutrient is in direct proportion to the rate at which it uptakes this nutrient from the medium. Thus the microbe with the largest uptake rate would drive that nutrient to the lowest extracellular concentration, thereby preventing other microbes from growing on it [12]. The SMP approach requires only the knowledge of a ranked table of microbial competitive abilities ranging from 1 (the most competitive microbe for a particular nutrient) to M (the least competitive out of M microbes) (see Fig. 1b for an illustration). Competitive abilities of microbes may in general be different for different nutrients.

The final outcome of a competition of microbes for nutrients is a stable state in which no microbe can switch to a more preferred nutrient and simultaneously win the competition with another microbe that is currently utilizing it. The microbial ecosystem will persist in this stable state until it is externally perturbed (e.g., by removal or addition of either microbes or nutrients). Note that our definition of a stable state corresponds exactly to that in the original formulation of the stable marriage problem.

Inspired by the classical diauxic (or polyauxic) growth experiments [19] we assume that microbes are constantly scouting the environment for more preferred nutrients. However, the diauxic shift down to the next nutrient requires the currently consumed (more preferred) nutrient to either be completely exhausted or at least to fall below a certain concentration threshold. In what follows, we ignore the kinetics of this switching behavior including the lag phase. The natural microbial ecosystems relevant to our model may have rather complex dynamical behaviors including long transients, oscillations, and even chaos [39,40,41,42]. However, these lie beyond the scope of the SMP-based approach. Microbial preferences towards nutrients typically follow the order of maximal growth rates reached when they are present in a high concentration [43]. Using this as a general rule of thumb, we assume that a microbial species’ stable-state abundance systematically decreases as it shifts down its nutrient preference list. The exact procedure by which we assign abundances to species in a stable state is described in Methods: Studying complementarity through different ranked interaction tables.

Community restructuring following external perturbations

We first consider a simple case in which two microbial species (M1: grey and M2: light in Fig. 2) utilize two nutrients (N1 and N2). The preferences of microbes for these nutrients are complementary to each other: M1 prefers N1 to N2, while M2 prefers N2 to N1. The competitive abilities of microbes are opposite to their preferences. As shown in Fig. 2 M2 wins over M1 in a competition for N1, while M1 wins over M2 in a competition for N2. There are two possible states of this ecosystem characterized by nutrients: the state A (Fig. 2), where M1 is consuming N1 while M2 is consuming N2, and the state B, where M1 is consuming N2, while M2 is consuming N1. One can easily check that both states are stable in the SMP sense. That is to say, no microbe could switch to a nutrient it prefers more than the one it currently utilizes and simultaneously win the battle with another microbe which is its current consumer. The state A is the one obtained by the “microbe-proposing” algorithm. It naturally emerges whenever the current set of microbes is introduced to the system when all nutrients are supplied at a high influx. In this case, microbes following the sequence of diauxic shifts end up in this state and remain there until perturbed by addition of other microbes or nutrients, or (possibly transient) removal of the existing ones. The stable states in our model satisfy the criteria for alternative states of an ecosystem proposed in ref. [44].

Fig. 2
figure 2

Community restructuring following external perturbations. Two ranked tables of microbes’ nutrient utilization preferences and competitive abilities are shown on top of each panel. Colored circles represent different microbial species M1, M2, M3. The size of each circle corresponds to the rank of a nutrients microbe currently utilizes—bigger sizes correspond to better ranks and thus larger populations. Different nutrients are labeled N1, N2, N3. Oblique dashed lines indicate transient states for microbial competition. a The introduction of a new probiotic microbe, dark species (M3), causes grey (M1) and light (M2) species to enter into a competition with the invader. The dynamics of the stable marriage model results in a community restructuring to the state B, such that the grey (M1) and light (M2) species shift their currently utilized nutrients to their second choices. The invading dark species (M3) fails to establish itself and disappears from the system. b A transient addition of a prebiotic nutrient, N3, restructures the community from state B back to state A, in which each microbe once again uses its most preferred nutrient

In what follows we investigate the stability of stable states in the example illustrated in Fig. 2, with respect to two types of perturbation: the introduction of a probiotic (another microbe M3 shown in dark in Fig. 2a) and a prebiotic (a transient nutrient N3 in Fig. 2b).

In the case of the probiotic, the community starts at the state A—a natural endpoint of diauxic shifts. A new microbe M3 (probiotic) is introduced to the community and initially displaces M2 in the competition for its preferred nutrient, N2. As a result, M2 switches over to its next preferred nutrient (N1) and outcompetes M1, which was consuming it. M1 now also switches to its second preferred nutrient N2 and competitively displaces the “invader” M3. M3 switches to its second nutrient N1 but loses the competition with M2 and ultimately disappears from the system. Thus, in spite of its temporary success, the microbe M3 fails to establish itself in the community. Note, however, that the result of its transient residence was a restructuring of the community from one stable state (A) to another (B). While the initial state A was “microbe-optimal” (i.e., both microbes consumed their most preferred nutrients in any of the stable states), the transient competitive interactions due to a new microbe pushed the community to a less microbe-optimal stable state, B.

In the other illustrative case the community starts in the stable state B, driven there, e.g., by consumption of a probiotic microbe (Fig. 2a). A new nutrient N3 (prebiotic) is transiently added to the diet. The microbe M2 prefers N3 to its currently consumed nutrient (N1) and switches to consume it. The N1 is now available without competition, so microbe M1 switches to use it as it stands higher than its currently consumed nutrient (N2) in M1’s preference hierarchy. After some time the prebiotic N3 is removed from the diet. The microbe M1 now switches to N2 (its second preferred choice after N3). Thus the community undergoes a restructuring again, this time from microbe-pessimal state B to microbe-optimal A.

These examples illustrate the following general rule: the introduction of microbes and nutrients pushes the community structure in two opposite directions. Specifically, invading microbes increase competition for nutrients and generally result in a community restructuring towards a stable state that is less growth-optimal for microbes. Even short-lived introduction of extra nutrients, on the other hand, relieves this competition and restores the community towards stable states in which microbes use more preferred nutrients.

Multiple stable states and the network of transitions between them

In general, the number of stable states increases with the number of microbes and nutrients in the community. In Fig. 3 we show an example of a community where seven microbial species compete for seven distinct nutrients, all of which they can utilize. For the particular set of microbial nutrient preferences and competitive abilities shown as ranked tables in Fig. 3a, there are a total of five stable states labeled S1 through S5.

Fig. 3
figure 3

Multiple stable states and the network of transitions between them. Two ranked tables of microbes’ nutrient utilization preferences and competitive abilities are shown on the left. a The list of all stable states (labeled S1 through S5) in the model. In each stable state, every microbe (colored circles with tails; sizes indicative of how preferred the consumed nutrient in a state is) exclusively consumes one nutrient (labeled N1 through N7). b The “microbe-optimality” of stable states S1 S5 (lower is better for microbes) quantified by the rank of the consumed nutrient averaged over all microbes. Microbe-optimality can be improved by transiently removing microbes and deteriorated by transiently removing nutrients. c, d The stable states are connected via “restructuring networks”. The community in the model gradually restructures from S1 towards S5 by transient nutrient removal (for details, see the Results section) and from S5 back towards S1 by transient microbe removal. In this restructuring network, a pair of stable states is connected by a directed link, if the community can transition between these states via transient removal of just one nutrient (removed nutrient and directionality are shown in c) or of a single microbe (removed microbe and directionality are shown in d). e Average number of stable states for communities with different numbers of microbes (M, x-axis) and nutrients (N, y-axis) and randomized interaction tables. (Inset, top) For (M, N) = (50, 50), we show the distribution of the number of steady states (in orange) for 1000 random interaction tables. The distribution has a pronounced peak and an exponential tail

As understood in the context of the original SMP [30], the stable states can be arranged hierarchically in the order of decreasing microbe-optimality quantified by the average rank of nutrients consumed by microbes in a particular state. Since rank 1 corresponds to the most preferred nutrient, while rank N corresponds to the least preferred one, lower values for this optimality measure correspond to more microbe-preferred states. The labels of the states S1S5 were arranged in the order of decreasing microbe-optimality, i.e., increasing the average rank of consumed nutrients (Fig. 3b). Thus the state S1 is the most optimal for microbes (corresponding to the stable state generated by the’microbe-proposing’ Gale–Shapley algorithm in the SMP), while the state S5 is the least optimal one. The average rank of consumed nutrients in S1 is equal to 1.7 which means that even in this state, not every microbe gets its most preferred nutrient. This should be compared to its value ~2.9 in the state S5, where a typical microbe gets its third choice among nutrients.

As described in the Methods section, the transitions between stable states of the SMP can be realized by transiently breaking a “marriage”, i.e., disrupting a microbe-nutrient pair. Figure 3b shows that the removal of nutrients from a diet (starvation) generally drives the community further away from the microbe-optimal state (S1). Indeed, in this case (akin to the probiotic case shown in Fig. 2a) microbes need to compete more for the remaining nutrients. Removing a specific subset of microbes (e.g., by antibiotics) has the opposite result: the surviving microbes have fewer competitive interactions for nutrients and hence each one of them would get a better (or same) ranked nutrient according to its preference list. Thus, somewhat counterintuitively, transient introduction of antibiotics might shift a community towards a more microbe-optimal state with larger overall biomass, which can be experimentally verified.

As known from the SMP results, the transitions between stable states could be triggered only by the removal of a very specific subset of nutrients or microbes. These states can thus be arranged in a “community restructuring network” shown in Fig. 3c, d. The transition along a given edge of this network leading further away from the microbe-optimal state could be triggered by a transient removal of a specific single nutrient (Fig. 3c). The transition in the opposite direction (towards a microbe-optimal state) is triggered by the transient removal of a specific single microbial species (Fig. 3d). Removal of a nutrient leaves the microbe that was utilizing it temporarily without its source of energy. This microbe will then engage in competition with other microbes for the remaining nutrients. This results in a cascade of shifts where microbes begin to utilize less-preferred nutrients, as prescribed by the Gale–Shapley algorithm. If the removed nutrient is reintroduced soon after its removal, the community will return back to its original state, contributing to the community’s resilience. In the opposite case, if the nutrient’s absence lasts very long, one of the microbial species left without a nutrient will go extinct. However, there is a specific intermediate regime where the nutrient is reintroduced at just the right time for its microbial consumer in the new stable state to have recently switched towards it. In this case, such a transient nutrient removal results in a community restructuring from a stable state to another one but less microbe-optimal. A similar restructuring is possible when a microbial species is transiently removed from the community (e.g., by a narrow-spectrum antibiotic) so the nutrient it utilized before the removal is now open for competition from other microbes. If this microbe is reintroduced later at just the right time, the community can restructure towards another stable state which is more microbe-optimal.

These examples (as well as their counterparts in which microbes or nutrients were added to the community as discussed in the previous section and illustrated in Fig. 2) demonstrate that these stable states are relatively resilient with respect to many transient perturbations. Such resilience is exhibited at two different levels. First, not all perturbations result in community restructuring. Those perturbations that do arrange the stable states in a hierarchical “community restructuring network” are shown in Fig. 3c. For anytwo adjacent stable states in this network, there is just one specific nutrient and one specific microbe that can be removed to trigger a transition between them. Transient removal of other nutrients or microbes is shown as self-loops in Fig. 3c, d), since these events return the community back to the original stable state. Second, even when this carefully selected nutrient or microbe is removed, it must be reintroduced within a specific time interval (not too soon and not too late) to result in a successful restructuring.

The average number of stable states for different combinations of numbers of microbes, M, and nutrients, N, are shown as a grid in Fig. 3e. The distribution of the number of stable states for different (random) realizations of microbe preference lists and competitive abilities for M=N= 50 is shown in the orange histogram in the inset to Fig. 3e. Further, supplementary figure S3 shows: (1) how the number of stable states decreases when the correlation among preference lists increases (Figs. S3(C)–(E)); and (2) how the average number of stable states increases with increasing M or N (figure S3(A)).

Complementary prioritization of nutrients as a mechanism for robust many-species coexistence

The human gut microbiome provides a fertile testing ground for our model. Indeed, as discussed in the introduction, many gut microbes are known to utilize nutrients sequentially. Moreover, recent reports indicate that multiple Bacteroides species have been regularly observed at high abundances simultaneously, in spite of a strong overlap in their metabolic capabilities [27]. This overlap is visualized in Fig. 4a, where we show a network connecting each of seven abundant species in the human gut (Bacteriodes fragilis, B. ovatus, B.vulgatus, B.caccae, B. cellulosilyticus, B. thetaiotaomicron, and a recently reclassified member of the Bacteroidetes phylum Parabacteroides distasonis) with a subset of nine polysaccharides (starch, mucin, galactan, pectin, arabinogalactan, hemicellulose, cellulose, hyaluronan, and chondroitin sulfate) they are capable of utilizing as energy sources (data from ref. [45], see the Methods section for details). For the sake of brevity, in what follows we refer to this set as Bacteroides species. What strategies by these microbes would allow their “robust” co-occurrence in the human gut, i.e., long-term, stable coexistence at high abundances?

Fig. 4
figure 4

Complementary polysaccharide prioritization allows robust coexistence in gut Bacteroides species. a The polysaccharide utilization network of Bacteroides species in the human gut (data taken from ref. [45]). The character labels represent nine different polysaccharides: S starch, M mucin, G galactan, P pectin, A arabinogalactan, HC hemicellulose, C cellulose, H hyaluronan, CS chondroitin sulfate (CS)—known to be frequently present in human diets (legend in the box on the left), whereas the colored circles represent seven different Bacteroides species routinely found in human gut microbiome: Bacteriodes fragilis, B. ovatus, B.vulgatus, B.caccae, B. cellulosilyticus, B. thetaiotaomicron, Parabacteroides distasonis. Undirected links between microbes and polysaccharides indicate a species’ ability to metabolize that polysaccharide. b Examples of microbial nutrient preferences (the most preferred nutrient of each of the microbes) are sorted into three categories: complementary (top) where microbes’ top preferred nutrients (#1) are all distinct from each other; random (middle) preferences where all ranked lists are randomly generated; and maximal conflict (bottom) which represents the maximum intersection between the sets of top (#1) and second (#2) preferred nutrients of different microbes. c For 1000 randomly sampled microbial preferences from each category, we simulated the stable marriage model to compute the expected per species microbial abundances (Methods section: Studying complementarity through different ranked interaction tables) for each case as box plots. The box plots quantify the distribution of average microbial abundance assumed to be inversely proportional to the rank of utilized nutrient. The average abundance is the largest in the case of complementary nutrient choices. All differences between distributions of abundances in each category are highly statistically significant according to the Kolmogorov–Smirnov test with a P-value threshold of 0.01

The SMP provides a natural framework in which to look for such strategies. Indeed, by supplementing the utilization network shown in Fig. 4a with a specific set of ranked nutrient preferences and competitive abilities of all participating microbial species, our model can predict which species will survive, how many stable states the corresponding community can be in, and what kind of abundance profiles they will achieve in these states. The latter could be approximated by the inverse of the rank of the consumed nutrient for every surviving microbe in a particular stable state. Indeed, microbes utilizing their preferred (low rank) nutrient are expected to reach high abundances. It stands to reason that in order to simultaneously achieve high abundances, these species have to successfully partition the set of nutrients among themselves. In the presence of a strong metabolic overlap this requires microbes to have evolved a mutually complementary set of nutrient preferences.

We quantify the complementarity of microbes’ top preferences by calculating the number of competing pairs of microbes that have the same most preferred nutrient. This number can vary between 0 (for perfect complementarity; Fig. 4b (top case)), to around 6 (for random preferences; Fig. 4b (middle case)) and ultimately up to 11 (for maximal conflict in these lists; Fig. 4b (bottom case)). The maximal conflict case assumes the strongest possible similarity of the entire preference lists of different microbes (see Methods for details).

We tested 1000 preference lists from each of these three categories (complementary, random, and maximal conflict) and calculated the average microbial abundances in each case (see box plots in Fig. 4c). As expected, the average abundance is the highest in the case of complementarity, lower for random preferences, and lower still for maximal conflict. Moreover, communities with complementary preferences show a higher number of stable states (see figure S2(B) for Bacteroides and figure S3(C)–(E) for a more general result for the communities in our model).

Perfect complementary between the top preferences of seven microbes would require careful orchestration over evolutionary times. However, these choices are encoded in regulation of specific polysaccharides utilization loci (PULs) controlled by microbial transcription regulatory networks and have been shown to be quite flexible [27]. Thus the complementarity of top nutrients choices required for robust coexistence of Bacteroides species in the human gut is entirely plausible and, indeed, has been in part reported in ref. [22].

Discussion

In the results presented above, we describe a conceptual model of microbial competition for sequentially utilized nutrients. This model can exhibit rich behaviors such as dynamic restructuring and multiple stable states connected by a hierarchical transition network. All of this complexity is encoded in just two ranked tables: one with microbial nutrient preferences and the other with their competitive abilities for different nutrients. The competitive interactions summarized in these tables are just starting to be explored experimentally. In fact, the first experimental results relevant to communities within the human gut have already been reported [22, 26]. Specifically, these results demonstrate the preferences and competitive abilities of two Bacteroides species for nine particular polysaccharides.

In the absence of experimentally determined preferences, the naive expectation would be to use randomized nutrient preferences and competitive abilities. However, as shown in Fig. 4, the results for random preference tables qualitatively disagree with experimental observations of robust coexistence of multiple species (e.g., Bacteroides in human gut) competing for the same set of nutrients. Our model shows that complementarity in nutrient preferences of different microbes facilitates such coexistence. This is consistent with experimental studies reporting that frequently co-occurring microbial species tend to have complementary nutrient preferences [22, 26, 46].

Complementary nutrient preferences may also explain the prevalence of habitat filtering in many naturally occurring microbial communities [15, 47,48,49], i.e., the observation that many metabolically overlapping species stably coexist with each other. This apparently paradoxical observation is unsurprising in the light of our results assuming that nutrient preferences of these species co-evolved to be (at least partially) complementary to each other.

One factor complicating the (co-)evolution of nutrient complementarity is that certain nutrients tend to be universally prized by all microbes. This is true for simple, easy-to-digest metabolites with high-energy content (e.g., simple sugars) where evidence suggests the existence of a common preference order [50]. However, the order of microbial preferences for more complex, harder-to-digest nutrients such as polysaccharides is known to be much more flexible [22, 26].

Correlations or complementarity in the preference lists of different microbial species (correlations of Type A) discussed above are just one out of three types of correlations possible in our model. The remaining two correlations are: Type B—Correlations in competitive abilities of different microbes; and Type C—Correlations between each microbe’s nutrient preferences and competitive abilities for the same nutrient. Strong positive correlations of type B imply the existence of “super bugs” good at utilizing every resource. Conversely, negative type B correlations may arise due to tradeoffs in each microbe’s competitive abilities for different nutrients [17]. For type C only the positive correlations are biologically plausible. Indeed, one might expect microbes to have higher-than-average competitive abilities for those nutrients that they prefer to consume first.

Positive correlations of all three types reduce the number of stable states, ultimately resulting in a unique stable state for fully correlated lists (see figure S3, panels (C) to (E) for correlations of types A, B and C respectively). Supplementary Fig. S3 explores the model with correlated lists by plotting the number of stable states as a function of correlation strength.

An evolutionary variant of the stable marriage model allows one to answer questions related to metabolic specialization of microbes. These questions include: How many nutrients a given microbe should have the capacity of using? That is to say, how many distinct nutrient utilizing metabolic pathways should be encoded in its genome? How do different microbes make a choice between being broad generalists and narrow specialists? In our analysis we see examples of both among Bacteroides species (Fig. 4a). The common wisdom is that in stable environments, characterized by a reliable influx of the same set of nutrients, microbes tend to become narrow specialists. However, this strategy would not fare well for microbes trying to survive in strongly fluctuating environments, where each microbe needs to be able to switch between multiple nutrients until it finds one currently present in the environment. An intriguing possibility is that the evolutionary trajectory of each species may be shaped by its partners in the SMP. That is to say, given its microbial partners, there is no need for a microbe to retain metabolic pathways utilizing nutrients which it never gets to use in any of the “stable marriages”. Over evolutionary time, such unused pathways would be dropped from its genome. At the same time, microbes would tend to improve their competitive abilities for the remaining nutrients, which in turn could possibly reinforce the initial set of stable states in the ecosystem. Hence the stable states in the marriage model may leave their footprint on the genomic content of co-evolved microbial species. More technically, in this case the set of nutrients each microbe could utilize would coincide with its “reduced Gale-Shapley preference list” (see ref. [30] for definitions).

Our model assumes one-at-a-time sequential consumption of all nutrients by all microbes. However, real-life microbes are known to combine sequential consumption and co-utilization of different nutrients depending on the topology of their catabolic pathways [51]. We can potentially incorporate co-utilization of nutrients to our model as a “many-to-many” matching rules [30] combined with ties in the ranked lists [35]. The number and nature of stable states in such models remain to be explored in a future study.

Furthermore, a key driver of diversity in real-life microbial communities often lies in the metabolic byproducts generated by resident species. Indeed, in the presence of metabolic byproducts the number of microbial species in the steady state is no longer limited from above by the number of externally provided nutrients. Recent models [15, 52] and experiments [15, 53] demonstrate that a diverse microbial ecosystem may be supported even by a single externally provided nutrient. The Bacteroides species used in our study are also known to grow on each other’s metabolic byproducts [46]. That may be the reason why B. thetaiotaomicron survives while losing the competition to B. ovatus on all eight polysaccharides studied in ref. [22] (see Fig. 4 from that reference).

The basic stable marriage model allows for a natural multi-layered generalization involving cross-feeding between microbial species. One starts with a single layer composed of abundant primary nutrients, which for human gut include polysaccharides shown in Fig. 4a. The microbes (such as Bacteroides species in Fig. 4a) compete, or, alternatively, complementarily utilize these nutrients and generate the second layer of nutrients, composed of their metabolic byproducts (or products of extracellular metabolic degradation). These byproducts in turn allow for a new set of microbes to grow and generate yet another layer of byproducts. Furthermore, microbes from the upper layers would normally not compete for nutrients in the layers below them. Indeed, the concentration of nutrients is expected to rapidly decrease with a trophic layer [52]. Hence, to maximize their growth rate, microbes would prefer nutrients from higher trophic layers.

Microbes using nutrients one-at-a-time give rise to tree-like food webs similar to those studied in ref. [52]. In our case there will be multiple trees, each growing from a single-primary nutrient. These trees would generally change as the community switches from one stable state to another. All the results of ref. [52] including the functional forms of the distributions of species’ abundances and prevalences are directly transferable to the multi-layered variant of the stable marriage model.

Another generalization of our model is when nutrients come in two or more distinct types, each essential for microbial growth (e.g., carbon and nitrogen sources). An extension of the model in this case would require a microbe to choose one source of each type. This would correspond to a marriage with more than two sexes. As far as we know, these modifications of the stable marriage model have not been developed yet, though this possibility has been explored in works of science fiction [54, 55].

A natural way to think about the competition in the stable marriage context is in terms of species and nutrients subject to a constant dilution in a chemostat. Changing the dilution rate would drive the ecosystem through different qualitative regimes of nutrient utilization. Another possible realization is in a periodically diluted batch culture where the system is diluted and the nutrients are added at discrete time points in a cyclic fashion. When thinking about such batch-fed bioreactors, one needs to consider the possibility of transient co-utilization of the same nutrient by several microbes. How can our model adapt to this possibility? One of the variants of the SMP known as the hospitals/residents problem [29, 30, 56] provides a possible starting point for such adaptation. In this problem a hospital (a nutrient in our case) can accommodate multiple residents (microbes). A variant of the Gale–Shapley algorithm [57 58] allows one to find all stable states of the community. Most other mathematical results of a “pure” marriage problem are also directly transferable here with only minor modifications.

Another appealing feature of our model is that it naturally incorporates higher-order interactions between microbial species [59]. These interactions have recently been brought to attention after a large number of studies showed that pairwise interactions are not sufficient to explain community dynamics [15, 60,61,62]. Further, they have been implicated as an important factor contributing to the composition, stability, and diversity of ecosystems [63,64,65,66]. In our model, community dynamics depend on ranked preferences and competitive abilities of all species in a resource explicit manner, and cannot be simply reduced to a set of pairwise competitive outcomes. That is to say, the outcome of the competition between species can be rather different depending on the presence or absence of other species. This is reflected in different species abundance profiles in Fig. 3a (see for instance, states S2 and S3).

To summarize, in this study we present a model inspired by the SMP that shows and gives insights regarding several dynamic microbial community phenomena. These phenomena include the observation of several stable states, dynamics of transitions between these states, as well as how they restructure. The stable states in our model satisfy all three necessary criteria for alternative stable states set forth in ref. [44]. Our model assumes that several microbes utilize nutrients sequentially (diauxie or polyauxie). With this assumption, all the stable states of a community are fully determined by two ranked tables: one summarizing all microbes’ preferred order of utilization of nutrients, and the other their competitive ability to uptake these nutrients relative to others microbes. Such rank tables can be inferred from polyauxic shift experiments in which individual microbes are grown on a rich medium with many nutrients. Further experiments in this direction will help generate predictions against which to test our model.

Methods

Enumerating all stable states

For any general case of preference lists in the SMP, there exist multiple “stable states”. There are several algorithms to enumerate all these states, though we used in our study one that is intuitive and connects well with microbial communities: the so-called “breakmarriage” algorithm [30, 67]. For our problem this algorithm involves starting from one of the stable states (e.g., microbe-optimal one) and then successively breaking each of the microbe-nutrient pairs by removing either a microbe or a nutrient. A transient removal of a specific nutrient has the possibility of triggering a transition of the community to another stable state in which all microbes are worse off (or equal) in terms of the preference rank of the nutrient they consume. These transitions are shown as downward pointing arrows in Fig. 3c. Conversely, a transient removal of a specific microbe could trigger a transition to a stable state in which all microbes are better off (or equal) in terms of the preference rank of the nutrient they consume (upward pointing arrows in Fig. 3d). Below, we list the specific details of the “breakmarriage” algorithm.

One starts with the microbe-optimal stable state obtained through the Gale–Shapley algorithm [29] in which every microbe plays the role of the active party and thus gets the best nutrient in any stable state. In the example illustrated in Fig. 3b, this corresponds to the state S1. One chooses an implicit ordering of microbes (say for convenience, in increasing order from M1 to MM for M microbes) in which one attempts to break microbe-nutrient pairs.

Upon breaking a pair (in our example, N5 and the teal microbe M5), the microbe in that pair (M5) is left without a nutrient, and therefore shifts down to (i.e., “proposes marriage to” in the SMP jargon) the next nutrient in its preference list (N3). If M5 is more competitive than the current consumer of this nutrient (the dark blue microbe, M6) with respect to the nutrient N3, it competitively displaces this current consumer (M6). (If not, the microbe (M5) continues to shift down its preference hierarchy until it finds a nutrient it can utilize.) Every time a microbe is left without a nutrient, it continues to down-shift its nutrient preference list and attempts to competitively displace other microbes using these nutrients (in our example, M6 now moves to attempt to use N5). If along this sequence, the original nutrient whose pair was broken (N5) is “proposed” to by another microbe (here, by M6), and if M6 can competitively displace its original partner (M5 in our case), a “rotation” is said to have been successfully completed and the new state is guaranteed to be stable (here, that state is S2 shown in Fig. 3b). If any of these steps fails, the attempted rotation is unsuccessful and one reverts back to the previous stable state and then attempts to break the next microbe–nutrient pair according to our implicitly chosen order.

For any of the new stable states (say S2 described above) found through this procedure, one repeats this procedure using this state as the initial stable state to find even more stable states. When all microbe-nutrient pairs in all such obtained stable states have been attempted to be broken, the algorithm is terminated. This procedure is guaranteed to enumerate all possible states for a chosen set of ranked interaction tables.

Studying complementarity through different ranked interaction tables

We sampled a large number of possible interaction tables, i.e., preferences towards nutrients and competitive abilities for all gut microbes of the genus Bacteroides regularly found at high abundances in the human gut (data taken from ref. [45]).

In principle, there are close to 10131 such possibilities, and it is thus not possible to sample all such tables. Instead, we compartmentalize such interactions in three broad categories: complementary, random, and maximal conflict.

In complementary interaction tables (see Fig. 4c (top case)), we construct random interaction tables with the following constraint: microbial preferences for the top (most preferred) nutrient must be made maximally distinct, i.e., with no overlap if possible. To construct interaction tables in this category, we begin by picking a microbe at random and assigning it a nutrient it can utilize at random. We then remove this nutrient as a possible top choice for all other microbes. We then randomly pick another microbe (without replacement) from the full set and assign it another random nutrient. We continue this until all microbes have been assigned a distinct most preferred nutrient. In case a chosen microbe has no choice left, we discard that particular interaction scenario and start a new one.

Random interaction tables provide a null interaction scenario for our model (see Fig. 4c (middle case)) and are thus used to set the naive expectation for competition and conflict within these gut microbes. In this scenario microbial preferences towards nutrients are selected by a random permutation independently chosen for each of the microbes.

In interaction tables with maximal conflict (see Fig. 4c (bottom case)), we construct random interaction tables with the following constraint: we attempt to maximize the number of conflicting pairs (NCP) for the set of microbes (see Results: Complementary prioritization as a mechanism for robust many-species coexistence). For this, we pick a microbe at random and then randomly pick a nutrient it can utilize as its most preferred (top choice). For all other microbes in our set that can utilize this nutrient, we set it as their most preferred nutrient as well. We continue until all microbes have been assigned a most preferred nutrient and then randomize the rest of the interaction tables.

In all three cases described above the competitive abilities of microbes for each of the nutrients are set by a random permutation.

Each specific pair of interaction rank tables (one for microbial preferences and another, for their competitive abilities) represents a possible competitive scenario in the human gut. We construct 1000 tables for each case. We then use the Gale–Shapley algorithm [29] to find the microbe-optimal stable state of the possible Bacteroides community and the breakmarriage algorithm (see Methods: Enumerating all stable states) to find the overall number of stable states. In the microbe-optimal state, we compute the relative rank of each microbe’s utilized nutrient in their preference lists, i.e., the rank of the utilized nutrient relative to how many nutrients that microbial species is known to utilize. The inverse of this relative rank is used (in a.u.: arbitrary units) as a predictive measure of its species abundance in the resultant community. We repeat this procedure for all microbes in the community and then normalize the abundances of all microbes to add up to one so that the relative abundance for each species is between 0 and 1.