But how does the quantity matching happen? For example, if I want to buy 1000 shares at $100, but there is only one seller to sell 10 shares at $100, what happens then?
This depends on the type of order you've placed. If you placed a fill-or-kill order, your order to buy or sell a certain number of shares
is routed to the trading floor for immediate execution. If the order cannot be immediately filled, it is cancelled (killed) automatically. Note that the order must be filled in its entirety. Partial fills are not allowed.
In your example, your buy order wouldn't be filled because it couldn't be matched to a sell order of the same volume.
This is similar to an all-or-none order, which is an order that contains
A condition instructing the broker to fill the order completely or not at all. If there is insufficient supply to meet the quantity requested by the order then it is canceled at the close of the market.
In this case, if your order wasn't matched to an order of the same volume by the time the market closes, it's cancelled.
If you simply placed a market/limit order, and (in the case of the limit order), part of your order was matched to another order with the right price, that part of your order will be filled, while the rest will remained unfilled.