Sweat the aromatics: Heat the olive oil in a small heavy-bottomed saucepan over medium heat. Add the diced onion, chopped garlic and 1/2 tsp kosher salt; cook 4-5 minutes, stirring often, until soft and translucent.
Caramelise the base: Stir in the brown sugar and smoked paprika. Lower the heat to medium-low and cook 10-12 minutes, stirring often, until the onions are deeply golden, sticky and sweet-smelling and the paprika has toasted in the fat. Do not rush this step — burnt sugar goes bitter.
Deglaze with the acid: Pour in the cider vinegar — it will hiss and steam. Scrape up every browned bit from the bottom of the pan and cook 1-2 minutes until the sharp vinegar smell cooks off.
Build the sauce: Stir in the Worcestershire sauce, ketchup and the espresso, if using. Lower the heat and simmer gently 8-10 minutes, stirring occasionally, until thick, dark and glossy — it should coat the back of a spoon and hold a trail when you drag the spoon through it.
Blend for a silky finish (optional): For a restaurant-smooth sauce, buzz briefly with an immersion blender. Leave it chunky if you like the caramelised-onion texture.
Taste and jar: Season with salt and plenty of black pepper. Cool completely, then pour into a clean glass jar with a lid. Keeps in the fridge up to 2 weeks.