I recently wrote about how the ability of Japan and Britain to defend their farmlands from foreign invaders, via their island positions and strong navies, were probably not unrelated to their having among the highest farm productivities between medieval and early modern times, despite unfavorable soils and climates.
A similar phenomena occurred for commerce in commodities (including agricultural commodities after being harvested). However, here the optimal scales of defense are much smaller since stores of commodities, along with the persons who produce, deal in, and consume those commodities, require far less space than farmland. Thus during many eras cities were independently defensible areas. In late medieval Europe cities became so independently defensible and had such different laws (specialized for commerce in commodities instead of agriculture) that they often became politically independent. Indeed, four of the most successful medieval empires, Venice, Genoa, the Lombard League, and the Hanseatic League, were either centered on such cities or were an alliance of such cities.
Several medieval areas especially benefitted from small defensible areas. See, for example, this nice satellite image of Venice. (There have been some small changes since the Middle Ages -- some of what is now ocean was once swamp land). From their small island base, Venice was able to withstand the various Dark Age invasions and become a Mediterranean superpower. Low Country cities such as Bruges, Ghent, and Amsterdam were surrounded and criss-crossed by canals such as this one in Bruges.
Canals and oceanside locations also extended the reach of shipment for commodities. Adam Smith estimated that water transport was about out twenty times cheaper by water than by the same distance on land.