Bring a large pot of salted water to a boil. Cook the spaghetti until al dente. Reserve 1 cup of pasta water, then drain.
In a large skillet, heat the olive oil over medium heat. Add the guanciale and cook until golden and crisp, about 5 minutes. Stir in the garlic and cook for 30 seconds, then remove the skillet from heat.
In a bowl, whisk together the egg yolks, grated Pecorino Romano, and pesto until smooth and well combined.
Add the hot pasta to the skillet with the guanciale. Off the heat, pour in the egg-pesto mixture, tossing quickly with tongs or a pasta fork. Add splashes of reserved pasta water as needed until the sauce is creamy and coats the pasta.
Season with salt and plenty of cracked black pepper. Top with more Pecorino Romano and fresh basil, if using. Serve immediately.
Notes
Toss off the heat: The residual heat from the pasta is all you need to cook the yolks. Too much heat = scrambled eggs.Save your pasta water: This starchy liquid is key to making the sauce creamy and smooth without needing cream.Grate the cheese finely: It melts better and integrates seamlessly into the sauce.Room temp eggs only: Cold yolks can seize when they hit the hot pasta. Let them sit out while you prep.