I've never had any serious problems with the Seljuk barbs... a few archers (w/at least one city defense promotion) and walls in all of your central Anatolian cities are enough to hold them off. Keep a few horsemen in the area to chase down the ones that withdraw. Don't bother with spearmen - if you have a barracks and archery range in your military production city then an archer will always be better; plus you can upgrade them to marksmen later.
The Mongols are another story entirely. You pretty much always have to prioritize Guilds and Castle Building, throw up walls/castles and fortify at least 3 promoted marksmen everywhere if you want to keep all of your cities. Your terrain improvements are all doomed, though.
This is true of basically every civ that spawns before and in the path of the Mongols, although if you're a Persia civ (Khwarezmids, Seljuks, etc.) you'll probably need a lot more marksmen because they really get hit hard. It makes the early game (especially the research path) for these civs rather predictable. The Georgians are a bit of an exception; their Mongol invasions aren't as severe, and Monaspa lancers are great for mowing over even undamaged horse archers before they get out of the hilly Caucasus.