I'm not a historian, but my understanding is that Vietnam was a failure for the US because it wasn't executed properly. Eventually, US lost heart and fled the country. The goal itself (stopping comunism from spreading to another country), was in US' interest, at least as long as US wanted to be maintain its status as a global hegemon.
The US effectively lost the war before it even started. They decided to support the French during their colonial war due to the so-called 'domino theory,' which ignored the fact that the Vietnamese hated or feared China more than anyone else. After the French were gone, China would have been the biggest geopolitical threat to Vietnam.
If the right choices had been made in the 1940s and early 1950s, it wouldn't have been that hard to turn Vietnam into an East Asian equivalent of Yugoslavia, if not an actual US ally
My understanding from historians is that, whether or not the goal was right, it may have been an impossible situation.
Wars are politics and end only with a stable political settlement; without that, they can go on indefinitely - such as in Afghanistan recently.
Like Afghanistan, there was nobody in Vietnam that could run the country, politically, except the North Vietnamese. All the US could do was build someone else's capability, which wasn't working (in Vietname or Afghanistan) or fight indefinitely.