Walls work. The one at Constantinople kept out invaders from every corner for 1000 years. And the only times the city got sacked was because of the incompetence and corruption of it's political class. 1204, the rogue Crusaders were literally let in and allowed to run amuck. 1453, the leadership grew arrogant and refused to update their weaponry and amass cannons even as other European diplomats pleaded with them to, citing that the Turks have made artillery the entire component of their fighting force. They turned down the services of master cannon makers in Europe who were eager to build guns for them at steeply reduced costs to protect Christendom, opting to rely on only their Hellenic classical pride in the face of a ruthless and fanatic conquering force.