1. Bring a large pot of salted water to a boil. Add the spaghetti and cook according to the package directions. Drain, reserving 1 cup of the pasta cooking water. Return pasta to the pot.
While the pasta is cooking, heat the oil in a large skillet over medium heat. Add the bacon and cook, stirring occasionally so it cooks evenly, about 5 minutes. Add the onions and garlic and cook, stirring occasionally, until the onions are soft, about 3 minutes.
Whisk together the eggs and cheese in a small bowl. Add it to the pasta and immediately (so it doesn't curdle) stir and toss together. Add the bacon, onions, and 1/2 cup of the reserved pasta water (see Cook's Note).
4. Toss to coat well and serve immediately (see Cook's Note).
Cook's Note: The pasta will absorb some of the liquid as it sits, so if not serving right away, toss with the remaining 1/2 cup warm pasta water just before serving.