Hi achocolu,
I know a few things about caravans. I hope this helps.
I think (not too sure) that a caravan prefers to go to a storage yard that has a lot of space for a good that they will sell. A caravan prefers to go to a storage yard that has a lot of a good that they will buy. A caravan prefers to go to a storage yard that is nearby.
If you want caravans to go through a city rapidly, all trade by those caravans should be done in the same area. (It might be possible to optimize trade if caravans always went first to one area (closer to the entrance) to sell imports and then to another area (closer to the exit) to buy exports, but I've never tried that.)
As you noted, there can be problems if caravans will buy or sell a good that is widely used in the city. There are various solutions.
One solution is to design the city so that certain goods are kept in a central location. For example, my Waset buys beer from caravans (that also buy copper) and sells pottery to caravans (that also sell gems). Pottery, beer, copper, and gems are each kept in a single storage yard, and those storage yards are fairly close together. All of the houses use pottery and beer, so some bazaar buyers have to go farther than I usually make them go, but it isn't too far.
Another solution is to try to have caravans prefer certain storage yards. For example, my Thinis sells pottery and beer to caravans (that also sell wood). Both pottery and beer are stored in multiple places around the city, but the storage yard special orders are set so that the storage yards that are closest to the entry point almost always have the most pottery and beer (with the single storage yard that accepts wood nearby).
It may be easiest to not export a good, especially later in a mission. For example, my Itjtawy has beer and linen stored in multiple places around the city. Beer and linen were sold during development, which sometimes required trade micromanagement, but those exports eventually stopped. Now the city makes far more money from taxes than it ever did from exports.
Sometimes all potential solutions appear to have drawbacks. In my opinion, that is partly why this game is so replayable (as you mentioned).