This question is more about the algorithm behind how exchange Handling transaction rather than ethereum itself.
So I have use exchange to trade ethereum, every exchange issue a unique ethereum address to it user. Unlike Bitcoin, Ethereum doesn't have multiple input and multiple output. So I am wondering how exchange handle the ethereum transaction itself. And What is the optimum algorithm to handle those transaction.
So I notice, when I deposit my ethereum, there are some exchange the do send the ethereum that I deposit to their main wallet which then send out for user who request withdrawal. The problem is that the transaction fees is quite high. Maybe about 90 Gwei or $2.00 for a single transaction. So for example, if a userA deposit 0.01 ether which is about $14 to their address. At the same time userB request withdrawal of 1 ether and pay 0.01 ether withdrawal fees, however, my main wallet does not have 1 ether, so I need to transfer from all the wallet like userA and other user which scattered between different number of ether, which means the cost that userB paid cannot cover the transaction fees from other user to my main wallet because there would be 99 transaction needed 1 ether if all of my user ether wallet balance only consist of 0.01ether! In another scenario if the user only need to withdraw 0.009 ether, I could directly transfer from userA's wallet to that user without transfering to my main wallet.
So I am wondering, do you guys have an idea what the formula or algorithm which make this possible to avoid lost to the exchange itself? Thanks.