If I google “mealybugs,” the first pages of results deal almost entirely with ways of spotting and destroying them. There’s good reason for that: these small, sap-sucking bugs drain fluids from plants, spread diseases, foster the growth of molds, and cost millions in damage to crop growers every year. They destroy the things we eat, and so we destroy them.

But mealybugs are more than just symbols of both famine and pestilence. Over the last 15 years, a small team of scientists has shown that they are also symbols of interconnectedness. They are among the most spectacular examples of symbiosis—the phenomenon where different species live together in intimate association. And with every new discovery, their biology becomes even more elaborate and unbelievable.

The prelude to this story begins in the early 20th century, when an exceptionally productive zoologist named Paul Buchner started dissecting his way through the insect world. He showed that countless species are filled with microbes, many of which live inside their very cells. The mealybugs were no exception—they also contained inner bacteria, which seemed to be thickly embedded within “roundish or longish mucilaginous globules.” That is: big balls of mucus.

Buchner didn’t press the matter further. But when other scientists later analyzed these globules, they started getting very odd results. If the mealybugs swallowed antibiotics, the globules would rupture along with the bacteria inside them. Peculiar. The mucus also seemed to contain many of the elements of an actual cell. Also peculiar. And genetic studies showed that they contained DNA from two separate lineages of bacteria. That, at least, was explicable: Buchner’s globules probably contained two types of symbiotic bacteria rather than one.

In 2001, Carol von Dohlen tested this idea by studying the citrus mealybug—a tiny insect that looked like a lozenge dipped in icing sugar. Von Dohlen fashioned two fluorescent molecules—one red and one blue—that would each stick to DNA from one of the two bacteria. If the two microbes did indeed share the same living quarters, their respective glows should have blended into a sea of purple.

That is not what happened. Instead, von Dohlen saw red dots against a blue background. The red probe had stuck to the bacteria in the globules. But the blue probe was sticking to the globules themselves. These mucus-filled spheres weren’t enclosing two kinds of bacteria. They were bacteria.

Von Dohlen had discovered that the citrus mealybug is a living Russian doll—or perhaps a microbial turducken. The bacteria living in its cells have more bacteria living inside them. It contains multitudes, and its multitudes contain more multitudes. The bigger microbe was eventually named Tremblaya, and its inner companion was called Moranella. And then things got even weirder.

In 2011, von Dohlen teamed up with geneticist John McCutcheon to sequence the genomes of the two microbes. Both were very small, as is often the case with bacteria that find their way into insect cells. In the cozy confines of their hosts, these microbes can afford to lose genes that they would normally need for an independent existence. Tremblaya has even lost a group of supposedly indispensable genes that were there in the last common ancestor of all living things, and are found in everything from bacteria to bats. There should be twenty of them, and Tremblaya has none. It survives because the insect around it and the Moranella within it compensate for its genetic shortfall.

This convoluted set-up developed gradually. Tremblaya was first of the two partners to colonize mealybugs: it’s there in all the species from one particular lineage, and there are some mealybugs that carry it and it alone. Snug in a bug, it began jettisoning genes. In the citrus mealybug, Moranella joined the partnership. The duo became a trio, and Tremblaya continued its slide into genetic pauperdom. As long as any gene exists in one of the partners, the others can afford to lose it.

That’s abundantly clear when you look at genes for making nutrients. For example, it takes nine genes to make an essential amino acid called phenylalanine. But none of the three partners makes all nine. Tremblaya can build 1, 2, 5, 6, 7 and 8; Moranella can make 3, 4, and 5; and the mealybug alone makes the 9th. As I wrote in my new book, this reminds me of the Graeae of Greek mythology: the three sisters who share one eye and one tooth between them. They are still distinct entities, but they’re each like thirds of a single whole. They cooperate to make nutrients that they all rely upon, and none can survive without the other.

Now things get really strange. Other species of mealybugs are also Russian dolls, with the same bug-in-a-bug-in-a-bug set-up. One of them—the long-tailed mealybug—even seems to have two kinds of inner bacteria living inside its outer one.

No matter the mealybug species, the outer bacterium is always Tremblaya. But the inner bacterium varies considerably—it’s Moranella in the citrus mealybug, but different microbes in the other insects. The most obvious explanation for this pattern is that some ancestral mealybug became infected with its two nested microbes. As the insects diverged into different species, so did the microbes within them. For whatever reason, the outer one stayed the same, while the inner one changed into new forms—Moranella being just one of them. “It’s so weird and so uncommon to get these bacteria inside of each other that I thought it had to happen once,” says McCutcheon.

If that were the case, you’d expect the family tree of the inner microbes to match that of the mealybugs themselves. But it doesn’t. Not even close. Once again, with mealybugs, the obvious explanation is completely wrong.

By sequencing the genomes of five mealybugs and all their associated bacteria, Filip Husnik, one of McCutcheon’s graduate students, has shown that these insects seem to regularly replace their inner bacterium. Tremblaya is constant, but the microbe within gets periodically swapped out for a fresh partner. That’s why some of these inner microbes have genomes that are 10 times bigger than others—they are recent acquisitions that haven’t had time to lose disposable genes.

So, even though the mealybug and its bacteria cannot survive without each other, their three-way alliance turns out to be surprisingly flexible. New partners come and go. Various genes are lost and retained.

This constant symbiotic turmoil leaves its mark on the genomes of the mealybugs themselves. Husnik showed that each of these insects carries bacterial genes in its DNA, and these genes almost never come from their current partners. Instead, they belonged to bacteria that once colonized these insects but have since been ousted. Before they vanished, they transferred genes to their hosts, and the mealybugs use these genes to make nutrients. So, each of these insects is a mash-up of many species of microbes, several of which aren’t even there anymore.

In their new paper, Husnik and McCutcheon show all of these genetic patchworks in one enormously complicated diagram. When I ask McCutcheon to explain it to me, he says: “F*********ck.” Then, after a pause: “If you look at just the citrus mealybug, you think: Oh, it’s that way. But this dynamism gives me a sense that we should be careful drawing conclusions from one example.”

“The study is an exceptional accomplishment,” says von Dohlen. “I think the next major phase of research in symbiosis will be studies like this,” which look at many related species to see how the relationships between animals and microbes evolve over time. That’s the best shot of answering the many lingering questions about these symbioses.

How, for example, why do some mealybugs do fine with just Tremblaya, while others added a second microbe to the mix? How did the bacterium-in-a-bacterium set-up evolve in the first place? How do the inner bacteria get swapped out? And why is it that they are only ever replaced by species from one particular lineage, known as Sodalis. “It’s my favorite genus of bacteria at the moment—a special group that seems to exist somewhere in the environment and is really good at getting into insect cells,” says McCutcheon. “Sodalis is really special, and I don’t know why.”