Once you get railroads it gets pretty easy to defend. Definitely a pretty large army near your borders. Also it helps to do some heavy espionage investments against your bordering nations just to see what armies are in them. Just recently playing the 18civs scenario using Germany, I saw a 120ish stack cavalry from China coming through Russia and had enough time to move and crank out military to my Russian borders to crush the invasion. Also if you keep enough artillery units you usually don't need too big an army. Basically just judge by the score of your largest rival how much army they can crank out and try to keep just over half that. Keep track of who's fighting who, if a large empire is at peacetime and is cautious or worse with you then always expect an attack coming.