When Jesús Rivas removed a female anaconda from a snake orgy in order to examine her, he got a surprise.

The anaconda's swollen body suggested she was full of food, so Rivas waited for her to throw up: snakes often vomit after a meal if they have over-eaten or are stressed, to make themselves lighter so they can flee. But instead of a typical prey, like a capybara, a reptilian tail started emerging from her mouth.

"It was an anaconda," says Rivas, a herpetologist from New Mexico Highlands University in Las Vegas. "And the hemepenis was there, so it was a male."

The female anaconda had eaten one of her most recent sexual partners, a phenomenon known as sexual cannibalism. Her startling action is part of a growing body of evidence that we have misunderstood how snakes have sex.

In anacondas, sexual cannibalism only goes one way: the female consumes the male.

Previously, scientists had assumed that female snakes are submissive during courtship and mating, but it is now clear that they have a prominent role. "There was the interpretation that females had no say in the mating process," says Rivas. He thinks that assumption stems from bias by early researchers, who were predominantly male.

In fact female snakes are physically imposing, so it is not surprising that they can overpower – and even swallow – their mates. In many animals, males are larger than females, but for most snakes the opposite is true.

In anacondas, females are on average 4.7 times larger than males. That is the biggest size difference between sexes in any land-living vertebrate. "I was surprised," says Rivas. "The difference is drastic."

The reason males are so often larger than females is that it helps them secure a mate.

Among lizards, birds and mammals, bigger males are more successful at defending a territory and driving off any competing males. But most male snakes do not exhibit such stereotypically male behaviour. They are not territorial, and during courtship they may simply push away their competition, instead manoeuvring their tails to sneakily reach for a female's genital tract. This could explain why male snakes do not benefit from being larger.

Instead, evolution may have driven female snakes to grow larger. Size is linked to increased fertility and bigger offspring, which are more likely to survive. A 2016 study also found that maternal body size can influence the young's immune systems.

Males seem to be drawn to these reproductive benefits: they prefer to court larger females.

But it is not obvious how the males make this choice. Snakes do not have very good eyesight, so how a male snake could spot a particularly big female from a distance is unclear.

A possible clue comes from the fact that courtship is initiated by females, not males. After a female emerges from hibernation and sheds her skin, she releases pheromones that draw males towards her.

"It's thought that the pheromones are transmitted when the skin tears," says Rivas. "Males go crazy."

It turns out that these pheromones can carry information about a female's appearance.

Michael LeMaster from Western Oregon University in Monmouth found that the scent emitted by female red-sided garter snakes can convey their physical size. During the breeding season, longer females had higher proportions of certain chemicals in their skin.

"We were pleasantly surprised to find that there was size-dependent variation in the female sexual attractiveness pheromone," says LeMaster. Although males do court small females, they spend less time doing so, and often switch their attention to larger females if one passes by.

However, the pheromones cannot be the whole explanation because, with very few exceptions, they do not diffuse through the air, so suitors need to get close before they detect them.

Another aspect of snake sex that we have got wrong is the pattern of mating.

Polygyny, in which one male mates with several females, was long thought to be the norm in snakes. But it is not quite as simple as that.

It is certainly common for several male snakes to be attracted to the same female. For example, in a 2016 study Mark O'Shea from the University of Wolverhampton in the UK and his colleagues reported an instance of multi-male courtship in the paradise flying snake.

In the Malaysian region of Borneo, a female paradise flying snake was photographed in a braid-like entanglement with four males. The snakes moved as a unit following the female's lead, moving along a path and into bushes, over the course of 30 minutes. The team suspects that the males competed for the prime copulation position during the journey.

Keel-bellied whipsnakes, a closely-related species, have also been observed in a similar courtship braid. These snakes are active during the day, so the formation may help them do two things at once: woo a female and keep slithering through the trees to avoid predators.

On the ground, snake "orgies" tend to be much larger.

A female green anaconda will sit still in mud or shallow water, while males make the effort of moving around to find her. Often, a dozen prospective partners present themselves, wrapping themselves around the female in a ritual that can last for up to a month.

Rivas vividly recalls watching a male green anaconda persistently pursue a large female and later have sex with her, disregarding other mating opportunities nearby. "It's the closest to true love you'll find in a snake," he says.

Garter snake courtship can be even more extreme. In the Interlake region of Manitoba, Canada, a single female may be pursued by up to 100 males, who slither on top of each other and form a "mating ball". Several mating groups often gather at once in crevices above ground, littering the landscape with thousands of snakes.

However, the garter snakes only do this in certain places. "In the continental US, there are no mating aggregations," says Rivas. It is not clear why, but environmental conditions such as climate could be a factor: the behaviour of other snake species can vary dramatically based on geography. Rivas and his team are currently studying the mating practices of their local garter snake population in New Mexico.

The trouble with all these snake orgies is that it is not clear which of the males, if any, actually succeeds in producing offspring. But one thing is clear: since snake orgies are writhing with males, females must choose.

"A female ultimately 'decides' when to [open] her cloaca to allow for mating to occur," says LeMaster, based on his studies of red-sided garter snakes. Females also use genital contractions to control the duration of copulation and can interrupt sex if a mate proves unsatisfactory.

It is still unclear what cues the females use to choose one suitor over another. "The strongest or most persistent male is probably the one that would eventually mate with the female, thereby producing stronger offspring," suggests O'Shea. But there may well be more of an element of female choice. Rivas thinks the females could use their sense of touch to distinguish between males. Observing a mating group from the inside, perhaps with a camera, could reveal the process involved.

In any case, females do not necessarily pick a single suitor. Instead, they often have sex with several males. What's more, contrary to early research, males typically stick with a single partner while females sleep around.

"Males invest a lot of energy trying to find females, which is consistent with polyandry," says Rivas. He thinks polyandry – in which each female mates with multiple males – is likely to be the ancestral mating system in snakes.

It is not clear why snakes would have evolved this particular mating system. One idea is that promiscuity allows females to stock up on seminal fluids, which provide her with nutrition. However, Rivas thinks that mating with many males is more likely to be a way of producing the healthiest offspring, by letting sperm competition weed out incompatible or unhealthy genes. Females can store sperm in their reproductive tract for months or even years, and it seems to remain competitive even when faced with new, fresh sperm.

So how do males get ahead?

Female red-sided garter snakes that have just copulated emit a special pheromone, which allows males to avoid wasting time pursuing them. But some males take a more active role in securing mates.

For example, male red-sided garter snakes produce a gelatinous substance that blocks the female's genital tract after mating. This "mating plug" is thought to be a tactic to prevent the female from mating again. When male red-sided garter snakes copulate with large females, they tend to mate for longer – but instead of depositing more sperm, they often produce a larger mating plug to make life difficult for other suitors.

Mating plugs are not 100% effective. For one thing, they often fall out. But they may have another role besides enforcing chastity. The mating plugs of red-sided garter snakes have been found to be packed with sperm, which could be gradually released as they dissolve. In other words, these mating plugs may actually be a sneaky way for males to spread their seed.

A male might also gain an advantage by being the last to mate with a female. The sperm from the most recent sexual encounter may remain on top and enter the female first. That could help explain why anacondas court each other for so long. "It would make sense for males to hang out and try to be the last ones to mate," says Rivas.

However, to come back to where we started, male anacondas may not want to stick around for too long after sex: doing so puts them at risk of being eaten.

Female anacondas do not always consume their mates, and it is not clear how they choose whether to do so. "It would be interesting to find out why the ones that get eaten are more susceptible," says Rivas. Sexual cannibalism probably provides female anacondas with a lot of nutrients, which would be useful because they fast for seven months while pregnant.

When it comes to the reproductive behaviour of snakes though, there are still many mysteries to be solved. Part of the issue is that snakes are so secretive, which means only a few species have been observed in the wild.

But from what we can tell, the mating habits of snakes are rather similar to those of spiders. In both groups, the females are larger than the males, there is a lot of complex competition among males to fertilise the females, while the females find ways to control who mates with them – and unwary males sometimes risk being eaten by their mates.

Why two such distantly related groups, which last shared a common ancestor hundreds of millions of years ago when animal life was still confined to the sea, have evolved such similar mating styles is anyone's guess.