Bring a large pot of salted water to a boil and cook the spaghetti until al dente. Reserve ½ cup of the pasta water before draining.
In a bowl, whisk together the eggs, grated Parmesan cheese, and black pepper until well combined.
Cook the pancetta or bacon in a large skillet over medium heat until crispy. If using garlic, sauté it for 30 seconds until fragrant.
Add the drained spaghetti to the skillet and toss with the pancetta.
Remove the skillet from the heat and immediately pour in the egg and cheese mixture, tossing continuously so the residual heat creates a smooth, creamy sauce without scrambling the eggs.
Add a little reserved pasta water if needed to loosen the sauce and coat the pasta evenly.
Serve immediately with extra Parmesan cheese and freshly ground black pepper.