In the USA is it compulsory to indicate a political affiliation when registering to vote and if so isn't it an invasion of privacy?
There is no federal register of voters in the US, to my knowledge. Voting laws are regulated by individual states, and vary from state to state.
Where I live, the registration process does ask if you want to register as a Republican or Democrat (or one of a few lesser known parties) but we have the option to leave that blank.
I have never been affiliated with any party, including the two major ones. Those like me used to be called Independent Voters, until the creation of an actual Independent Party, some years ago. Now I'm considered to be an Unaffiliated Voter.
The only time that makes a difference is in the primary election (which is six months before the general election), where you get a ballot with Republican candidates, OR Democratic candidates, OR no candidates. Anyone not registered with one of the major parties is given a ballot for only the issues, levies and non-partisan positions like local school boards or county commissioners.
Hope this answers your question.