Combine milk, eggs, sugar and gentle heat and one of our most treasured comfort food appears. But how is this creamy concoction conjured? Veronique Greenwood peers into the pot.

This year was the year of pies. In a particularly long and snowy winter, I began to work my way through the Four and Twenty Blackbirds Pie Book, starting with a salt pork-apple pie. Now I've made 17 of the recipes, some of them multiple times, for a total pie count of 37 this year. Many recipes were leaps of faith. Really? I pour pork fat over the apples? Mix ground juniper berries with pears? Add roasted beets? – but none quite so much as my very first custard pie.

It was a Meyer lemon custard with a layer of chocolate ganache painstakingly spread in the bottom of the pie shell. I popped it into the oven, and waited. And waited. After 50 minutes, when it should have possessed a self-confident jiggle, my custard simply sloshed.

The chemistry of custards is a delicate business, though the ingredients are simple: eggs, milk, sugar. The eggs, especially the yolks, are the chemical stars – it's their actions that matter most, generating the thick gel that's the key for a custard pie, says Guy Crosby, food scientist and science editor at America's Test Kitchen. The rest of the gang are there to help ease the eggs in the right direction. And in On Food and Cooking, Harold McGee emphasises that even the milk isn't strictly speaking required – just any substance with dissolved minerals. “Mix an egg with a cup of plain water,” he writes, “and you get curdled egg floating in water; include a pinch of salt and you get a coherent gel.”

So what is going on? (Or, in my custard, failing to go on?) As the liquid heats up, the yolk proteins, previously tightly packed in small granules, start to unfurl. Left to themselves, they'll make a few bonds with each other and create a tough, grainy substance at around 150 F (65C) – essentially, a hardboiled yolk. But the water in the milk and the sugar slow that process down, keeping them from binding so quickly. “The sugar is coating and physically blocking the proteins from getting together” until the temperature rises further, Crosby explains.

Whatever you do, don't just crank the heat up! – Guy Crosby

Meanwhile, the dissolved minerals are clustering around the proteins. In the ordinary course of things, a few bonds are all the yolk proteins will make – the absolute social minimum, like a party guest who speaks only when spoken to – because their negative charges repel each other. But with the minerals, which carry positive charges, playing the buffer, they start to interact more seriously, forming more and more bonds and growing more and more entwined, while the moderating influence of the water and sugar keeps things from going too fast.

All the while, the temperature rises. “You've got to do it very carefully and gently, which is why custards are often baked in a water bath,” Crosby says. The temperature for getting just the right texture is 180-185F (82-85C), and if all goes well – everything in its own time, and never too high a heat – a very fine mesh of egg proteins forms, resilient yet yielding to the fork.

But what if all doesn't go well – if you have a custard, like mine, that just isn't setting up? Crosby advises patience, and a longer cooking time. “Whatever you do, don't just crank the heat up! That's not the secret,” he says. “You just have to be patient. Eventually the temperature will rise. It's a matter of how much your egg mixture is heating up.” A ceramic pie plate will heat up slower than a metal one, and eggs straight from the fridge will start out chillier than room temperature eggs and take longer to reach 180F (82C). 

Microwave method?

And it's true, it doesn't pay to overheat custard. The average custard consumer has probably never thought about it, but custard exists on a continuum with scrambled eggs. Exactly the same reactions are going on, except that by stirring the eggs regularly you're breaking up the gel that forms the final product for a custard, and you aren't being so careful about the heat. But when you overcook a custard, suddenly the connection is very, very clear. A nasty eggy taste takes up residence and won't go away. That's likely the result of heat breaking down the protein components cysteine and methionine to release sulphur, says Crosby.

Could you – in a pinch – jump-start a custard in a microwave? That's not a good idea either, it turns out. The great failing of microwaves is that they heat unevenly, even when they have a turntable. You'd risk not just a liquid custard but one with overdone eggy patches interspersed with completely raw puddles.

In the end, time and patience were the saving of the Meyer lemon custard. It came out after an extra 40 minutes of cooking time – thanks to my oven? The starting temperature of the eggs? Who knows. But it was as golden as the sun, and, most importantly, just firm enough.

Follow us on Facebook, TwitterGoogle+LinkedIn and Instagram.