If you are talking about cultural flips, just make sure you have more culture than the opposing nations. So if your city does not, at the very least, control the immediate 8 tiles around the city, you have a problem. Anytime another Civ's boarders are pushing your boarders away, that is where you can look for immediate problems. To prevent the flip you have some options.
First, flips occur in part based upon the number of foreign citizens are in the city - those are citizens not of your culture. A city that is in a riot because of unhappiness is particulary vulnerable to flips. Either starve down the native population or make sure they are happy. At higher levels you may find that starving the city is the only way to keep it under control, but it won't help your world reputation any. To make people happy, build marketplaces (in non-corrupted cities) - this increases revenue and happiness.
Second, make sure you've got more culture then the neighboring civ. One way is to remove the neighboring civ.

If you are trying to be peaceful, then build cultural buildings. Many people prefer libraries and other educational buildings because it helps with research as well. Temples and religious buildings will do the trick and increase happiness (you'll find players are divided on the usefulness of religious buildings). Wonders also give culture but they are costly to build and I would be weary of putting one in a city that is already under cultural attack. The Forbidden Palace gives culture but can flip. Only your capital city is immune.
Third, garrison the city. The more troops you have in the city, the less the chance of a flip. But if it does flip, you lose ALL of the garrison troops. I think most experience players just park their army outside the city and if the city flips, they retake the city the next round. This had the added benefit of 'killing' one of the population which is basically the same as starving them down.
Finally, once espionage is on the tech table, the AI loves to use it to cause your border cities to flip. If you are in Democracy, you are immune to this. Otherwise it can be very annoying, particulary because the AI can do it without starting a war and you need to declare on them to get it back.
You'll find that at higher levels, many players will sack the city for the slave workers and just replace it with one of their own nationality. It is less work and far safer (though not foolproof).